Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
console
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
console
Commits
4aae8cd0
Commit
4aae8cd0
authored
Aug 22, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sha256 and migrate
parent
5cef4cc5
Pipeline
#4864
passed with stages
in 4 minutes
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
5 deletions
+44
-5
console-api/src/admin/admin.controller.ts
console-api/src/admin/admin.controller.ts
+10
-3
console-api/src/app.service.ts
console-api/src/app.service.ts
+31
-0
console-api/src/entities/Archive.entity.ts
console-api/src/entities/Archive.entity.ts
+1
-1
console-api/src/packager/packager.service.ts
console-api/src/packager/packager.service.ts
+1
-1
console-api/views/metalinks.mustache
console-api/views/metalinks.mustache
+1
-0
No files found.
console-api/src/admin/admin.controller.ts
View file @
4aae8cd0
...
...
@@ -15,8 +15,8 @@ import { AppPrefixDto } from '../dto/AppPrefix.dto';
export
class
AdminController
{
constructor
(
private
readonly
appService
:
AppService
)
{}
@
Post
(
'
migrate
'
)
@
ApiOperation
({
summary
:
'
迁移
'
,
description
:
'
上传一个 apps.json 文件
'
})
@
Post
(
'
migrate
/apps.json
'
)
@
ApiOperation
({
summary
:
'
迁移
apps
'
,
description
:
'
上传一个 apps.json 文件
'
})
@
UseInterceptors
(
FileInterceptor
(
'
file
'
))
@
ApiConsumes
(
'
multipart/form-data
'
)
@
ApiBody
({
...
...
@@ -24,7 +24,7 @@ export class AdminController {
type
:
FileUploadDto
,
})
@
ApiCreatedResponse
({
type
:
BlankReturnMessageDto
})
async
migrate
(@
UploadedFile
(
'
file
'
)
file
:
Express
.
Multer
.
File
):
Promise
<
BlankReturnMessageDto
>
{
async
migrate
Apps
(@
UploadedFile
(
'
file
'
)
file
:
Express
.
Multer
.
File
):
Promise
<
BlankReturnMessageDto
>
{
if
(
!
file
)
{
throw
new
BlankReturnMessageDto
(
400
,
'
no file
'
).
toException
();
}
...
...
@@ -32,6 +32,13 @@ export class AdminController {
return
this
.
appService
.
migrateFromAppsJson
(
apps
);
}
@
Post
(
'
migrate/hash
'
)
@
ApiOperation
({
summary
:
'
迁移 hash
'
})
@
ApiCreatedResponse
({
type
:
BlankReturnMessageDto
})
async
migrateHash
(@
UploadedFile
(
'
file
'
)
file
:
Express
.
Multer
.
File
):
Promise
<
BlankReturnMessageDto
>
{
return
this
.
appService
.
migrateHashes
();
}
@
Put
(
'
app/:id
'
)
@
ApiOperation
({
summary
:
'
创建 app
'
})
@
ApiOkResponse
({
type
:
BlankReturnMessageDto
})
...
...
console-api/src/app.service.ts
View file @
4aae8cd0
...
...
@@ -13,6 +13,8 @@ import { Build } from './entities/Build.entity';
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
Archive
,
ArchiveType
}
from
'
./entities/Archive.entity
'
;
import
{
PackageS3Service
}
from
'
./package-s3/package-s3.service
'
;
import
axios
from
'
axios
'
;
import
{
createHash
}
from
'
crypto
'
;
@
Injectable
()
export
class
AppService
extends
ConsoleLogger
{
...
...
@@ -309,4 +311,33 @@ export class AppService extends ConsoleLogger {
}
return
null
;
}
async
getHashForMigrate
(
fullPath
:
string
):
Promise
<
string
>
{
const
url
=
`
${
this
.
packageS3
.
cdnUrl
}
/
${
fullPath
}
`
;
this
.
log
(
`Migrating hash:
${
url
}
`
);
const
{
data
}
=
await
axios
.
get
<
internal
.
Readable
>
(
url
,
{
responseType
:
'
stream
'
});
//data.pipe(hashObject);
const
hash
=
await
new
Promise
<
string
>
((
resolve
,
reject
)
=>
{
const
hashObject
=
createHash
(
'
sha256
'
);
data
.
on
(
'
data
'
,
(
data
)
=>
hashObject
.
update
(
data
));
data
.
on
(
'
error
'
,
reject
);
data
.
on
(
'
end
'
,
()
=>
resolve
(
hashObject
.
digest
(
'
hex
'
)));
});
this
.
log
(
`Migrated hash:
${
url
}
=>
${
hash
}
`
);
return
hash
;
}
async
migrateHashes
()
{
const
archivesToDo
=
await
this
.
db
.
getRepository
(
Archive
).
find
({
where
:
{
hash
:
IsNull
()
},
select
:
[
'
id
'
,
'
hash
'
,
'
path
'
]
});
const
tmpMap
=
new
Map
<
string
,
string
>
();
for
(
const
archive
of
archivesToDo
)
{
if
(
tmpMap
.
has
(
archive
.
path
))
{
archive
.
hash
=
tmpMap
.
get
(
archive
.
path
);
}
else
{
archive
.
hash
=
await
this
.
getHashForMigrate
(
archive
.
archiveFullPath
);
tmpMap
.
set
(
archive
.
path
,
archive
.
hash
);
}
}
await
this
.
db
.
getRepository
(
Archive
).
save
(
archivesToDo
);
return
new
BlankReturnMessageDto
(
200
,
'
success
'
);
}
}
console-api/src/entities/Archive.entity.ts
View file @
4aae8cd0
...
...
@@ -21,7 +21,7 @@ export class Archive extends TimeBase {
@
Column
(
'
varchar
'
,
{
length
:
128
})
path
:
string
;
@
Column
(
'
varchar
'
,
{
length
:
128
,
nullable
:
true
})
@
Column
(
'
varchar
'
,
{
length
:
64
,
nullable
:
true
})
hash
:
string
;
@
Column
(
'
int
'
,
{
unsigned
:
true
})
...
...
console-api/src/packager/packager.service.ts
View file @
4aae8cd0
...
...
@@ -201,7 +201,7 @@ export class PackagerService extends ConsoleLogger {
reject
(
error
);
});
});
const
hashObject
=
createHash
(
'
sha
512
'
);
const
hashObject
=
createHash
(
'
sha
256
'
);
child
.
stdout
.
on
(
'
data
'
,
(
chunk
)
=>
{
hashObject
.
update
(
chunk
);
});
...
...
console-api/views/metalinks.mustache
View file @
4aae8cd0
...
...
@@ -3,6 +3,7 @@
{{#
archives
}}
<file
name=
"
{{
path
}}
.tar.zst"
>
<size>
{{
size
}}
</size>
<hash
type=
"sha-256"
>
{{
hash
}}
</hash>
<url
priority=
"1"
>
{{&
cdnUrl
}}
/
{{
path
}}
.tar.zst
</url>
</file>
{{/
archives
}}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment