ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / aura-team-server / src / routes / archives.ts 126 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import type { FastifyInstance } from 'fastify' ;
import { createReadStream, createWriteStream, mkdirSync, rmSync } from 'node:fs' ;
import { pipeline } from 'node:stream/promises' ;
import { join } from 'node:path' ;
import { mapAccessError, requireRole, userId } from '../access.js' ;
import { config } from '../config.js' ;
import { audit, database } from '../database.js'
id
broadcast
app FastifyInstance
app request
user request
user request params teamId error error
database request params teamId
app request reply
user request
user request params teamId error error
row database request params archiveId request params teamId id path created_by
row reply
row path force
database row id
user request params teamId row id
request params teamId
ok
app request reply
user request
user request params teamId error error
part request limits fileSize config archiveMaxBytes files
part part filename reply
part filename reply
safeName part filename
archiveId
projectId request query projectId
projectId
existing database projectId request params teamId id
existing reply
projectName request query projectName
projectName reply
projectId
database projectId request params teamId projectName user
directory config dataDir
directory recursive
path directory
part file path flags
part file truncated Object statusCode
bytes part file bytesRead
expiresAt Date config archiveTtlDays
database
database archiveId request params teamId projectId path bytes expiresAt user
user request params teamId archiveId bytes projectId
request params teamId
reply id archiveId projectId bytes expiresAt
error
path force
error
app request reply
user request
user request params teamId error error
row database request params archiveId request params teamId path bytes
row reply
storedName row path
originalName storedName storedName storedName storedName
reply
originalName
row path
name
name
name
ascii name
ascii
name
name
rows database id path
remove database
database rows row row path force remove row id
rows length
;
import
{
}
from
'../security.js'
;
import
{
}
from
'../realtime.js'
;
export
async
function
archiveRoutes
(
:
)
:
Promise
<
void
>
{
.
get < { Params: { teamId: string } } >
(
'/v1/teams/:teamId/archives'
,
async
=>
{
const
=
await
userId
(
)
;
try
{
requireRole
(
,
.
.
,
'viewer'
)
;
}
catch
(
)
{
mapAccessError
(
)
;
}
return
(
.
prepare
(
`
SELECT a.id, a.project_id AS projectId, p.name AS projectName, a.bytes, a.created_at AS createdAt, a.expires_at AS expiresAt,
u.display_name AS createdBy
FROM archives a
LEFT JOIN projects p ON p.id = a.project_id
LEFT JOIN users u ON u.id = a.created_by
WHERE a.team_id = ? AND a.expires_at > ?
ORDER BY a.created_at DESC
`
)
.
all
(
.
.
,
new
Date
(
)
.
toISOString
(
)
)
as
unknown
[
]
)
;
}
)
;
.
delete < { Params: { teamId: string ; archiveId: string } } >
(
'/v1/teams/:teamId/archives/:archiveId'
,
async
(
,
)
=>
{
const
=
await
userId
(
)
;
try
{
requireRole
(
,
.
.
,
'maintainer'
)
;
}
catch
(
)
{
mapAccessError
(
)
;
}
const
=
.
prepare
(
'SELECT id, path, created_by FROM archives WHERE id=? AND team_id=?'
)
.
get
(
.
.
,
.
.
)
as
{
:
string
;
:
string
;
:
string
}
|
undefined
;
if
(
!
)
{
return
.
notFound
(
)
;
}
rmSync
(
.
,
{
:
true
}
)
;
.
prepare
(
'DELETE FROM archives WHERE id=?'
)
.
run
(
.
)
;
audit
(
,
'archive.delete'
,
.
.
,
'archive'
,
.
)
;
broadcast
(
.
.
,
'project.changed'
)
;
return
{
:
true
}
;
}
)
;
.
post < { Params: { teamId: string } ; Querystring: { projectName? : string ; projectId? : string } } >
(
'/v1/teams/:teamId/archives'
,
async
(
,
)
=>
{
const
=
await
userId
(
)
;
try
{
requireRole
(
,
.
.
,
'dev'
)
;
}
catch
(
)
{
mapAccessError
(
)
;
}
const
=
await
.
file
(
{
:
{
:
.
,
:
1
}
}
)
;
if
(
!
||
!
.
)
{
return
.
badRequest
(
'A file with a name is required'
)
;
}
if
(
!
isArchiveName
(
.
)
)
{
return
.
badRequest
(
'Only .zip and .rar archives are accepted'
)
;
}
const
=
.
.
replace
(
/ [ ^ \w .\- ()] / g
,
'_'
)
.
slice
(
0
,
120
)
||
'archive'
;
const
=
id
(
)
;
let
=
.
.
?.
trim
(
)
??
''
;
if
(
)
{
const
=
.
prepare
(
'SELECT id FROM projects WHERE id=? AND team_id=?'
)
.
get
(
,
.
.
)
as
{
:
string
}
|
undefined
;
if
(
!
)
{
return
.
badRequest
(
'Project not found'
)
;
}
}
else
{
const
=
.
.
?.
trim
(
)
;
if
(
!
)
{
return
.
badRequest
(
'Project name is required'
)
;
}
=
id
(
)
;
.
prepare
(
'INSERT INTO projects(id,team_id,name,owner_id,default_branch,created_at) VALUES(?,?,?,?,?,?)'
)
.
run
(
,
.
.
,
,
,
'main'
,
new
Date
(
)
.
toISOString
(
)
)
;
}
const
=
join
(
.
,
'archives'
)
;
mkdirSync
(
,
{
:
true
}
)
;
const
=
join
(
,
` ${ archiveId} __ ${ safeName} `
)
;
try
{
await
pipeline
(
.
,
createWriteStream
(
,
{
:
'wx'
}
)
)
;
if
(
.
.
)
{
throw
.
assign
(
new
Error
(
'Archive exceeds the configured size limit'
)
,
{
:
413
}
)
;
}
const
=
.
.
;
const
=
new
Date
(
.
now
(
)
+
.
*
24
*
60
*
60_000
)
.
toISOString
(
)
;
.
transaction
(
(
)
=>
{
.
prepare
(
'INSERT INTO archives(id,team_id,project_id,path,bytes,expires_at,created_by,created_at) VALUES(?,?,?,?,?,?,?,?)'
)
.
run
(
,
.
.
,
,
,
,
,
,
new
Date
(
)
.
toISOString
(
)
)
;
audit
(
,
'archive.upload'
,
.
.
,
'archive'
,
,
{
,
}
)
;
}
)
(
)
;
broadcast
(
.
.
,
'project.changed'
)
;
return
.
code
(
201
)
.
send
(
{
:
,
,
,
}
)
;
}
catch
(
)
{
rmSync
(
,
{
:
true
}
)
;
throw
;
}
}
)
;
.
get < { Params: { teamId: string ; archiveId: string } } >
(
'/v1/teams/:teamId/archives/:archiveId'
,
async
(
,
)
=>
{
const
=
await
userId
(
)
;
try
{
requireRole
(
,
.
.
,
'viewer'
)
;
}
catch
(
)
{
mapAccessError
(
)
;
}
const
=
.
prepare
(
'SELECT path,bytes FROM archives WHERE id=? AND team_id=? AND expires_at>?'
)
.
get
(
.
.
,
.
.
,
new
Date
(
)
.
toISOString
(
)
)
as
{
:
string
;
:
number
}
|
undefined
;
if
(
!
)
{
return
.
notFound
(
)
;
}
const
=
.
.
split
(
/ [ \\ /] /
)
.
pop
(
)
??
'archive'
;
const
=
.
includes
(
'__'
)
?
.
slice
(
.
indexOf
(
'__'
)
+
2
)
:
;
return
.
header
(
'content-disposition'
,
` attachment; filename=" ${ asciiFallbackName ( originalName) } "; filename*=UTF-8'' ${ encodeURIComponent ( originalName) } `
)
.
type
(
archiveContentType
(
)
)
.
send
(
createReadStream
(
.
)
)
;
}
)
;
}
export
function
isArchiveName
(
:
string
)
:
boolean
{
return
/ \. ( zip| rar) $ / i
.
test
(
String
(
??
''
)
.
trim
(
)
)
;
}
export
function
asciiFallbackName
(
:
string
)
:
string
{
const
=
String
(
??
''
)
.
replace
(
/ [ ^ \x20 - \x7e ] / g
,
'_'
)
.
replace
(
/ [ "\\ ] / g
,
'_'
)
.
trim
(
)
;
return
||
'archive'
;
}
export
function
archiveContentType
(
:
string
)
:
string
{
return
/ \. rar$ / i
.
test
(
String
(
??
''
)
)
?
'application/vnd.rar'
:
'application/zip'
;
}
export
function
cleanupArchives
(
)
:
number
{
const
=
.
prepare
(
'SELECT id,path FROM archives WHERE expires_at<=?'
)
.
all
(
new
Date
(
)
.
toISOString
(
)
)
as
{
:
string
;
:
string
}
[
]
;
const
=
.
prepare
(
'DELETE FROM archives WHERE id=?'
)
;
.
transaction
(
(
)
=>
.
forEach
(
=>
{
rmSync
(
.
,
{
:
true
}
)
;
.
run
(
.
)
;
}
)
)
(
)
;
return
.
;
}