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
5cef4cc5
Commit
5cef4cc5
authored
Aug 22, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hash thing
parent
cf2e61b1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
6 deletions
+37
-6
console-api/src/app.service.ts
console-api/src/app.service.ts
+11
-1
console-api/src/entities/Archive.entity.ts
console-api/src/entities/Archive.entity.ts
+3
-0
console-api/src/packager/packager.service.ts
console-api/src/packager/packager.service.ts
+23
-5
No files found.
console-api/src/app.service.ts
View file @
5cef4cc5
import
{
Connection
,
In
,
IsNull
,
Not
,
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
InjectConnection
}
from
'
@nestjs/typeorm
'
;
import
{
ConsoleLogger
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
ConsoleLogger
,
forwardRef
,
Inject
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
AppsJson
}
from
'
./utility/apps-json-type
'
;
import
{
App
}
from
'
./entities/App.entity
'
;
import
{
BlankReturnMessageDto
,
ReturnMessageDto
}
from
'
./dto/ReturnMessage.dto
'
;
...
...
@@ -19,6 +19,8 @@ export class AppService extends ConsoleLogger {
private
readonly
packageVersionTraceCount
:
number
;
private
readonly
packageVersionPreserveCount
:
number
;
constructor
(
@
Inject
(
forwardRef
(()
=>
AppService
))
appService
:
AppService
,
@
InjectConnection
(
'
app
'
)
private
db
:
Connection
,
private
packager
:
PackagerService
,
...
...
@@ -299,4 +301,12 @@ export class AppService extends ConsoleLogger {
async
deleteApp
(
id
:
string
)
{
return
this
.
updateResult
(()
=>
this
.
db
.
getRepository
(
App
).
update
({
id
},
{
isDeleted
:
true
}));
}
async
lookForExistingArchiveHash
(
path
:
string
)
{
const
archive
=
await
this
.
db
.
getRepository
(
Archive
).
findOne
({
where
:
{
path
,
hash
:
Not
(
IsNull
())
},
select
:
[
'
hash
'
]
});
if
(
archive
)
{
return
archive
.
hash
;
}
return
null
;
}
}
console-api/src/entities/Archive.entity.ts
View file @
5cef4cc5
...
...
@@ -21,6 +21,9 @@ export class Archive extends TimeBase {
@
Column
(
'
varchar
'
,
{
length
:
128
})
path
:
string
;
@
Column
(
'
varchar
'
,
{
length
:
128
,
nullable
:
true
})
hash
:
string
;
@
Column
(
'
int
'
,
{
unsigned
:
true
})
size
:
number
;
...
...
console-api/src/packager/packager.service.ts
View file @
5cef4cc5
...
...
@@ -11,10 +11,11 @@ import { PackageResult } from '../dto/PackageResult.dto';
import
{
PackageS3Service
}
from
'
../package-s3/package-s3.service
'
;
import
readdirp
from
'
readdirp
'
;
import
{
ConsoleLogger
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
createHash
}
from
'
crypto
'
;
import
{
ConsoleLogger
,
forwardRef
,
Inject
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
Archive
,
ArchiveType
}
from
'
../entities/Archive.entity
'
;
import
{
Build
}
from
'
../entities/Build.entity
'
;
import
{
AppService
}
from
'
../app.service
'
;
import
{
createHash
}
from
'
crypto
'
;
export
interface
FileWithHash
{
file
:
readdirp
.
EntryInfo
;
...
...
@@ -63,7 +64,11 @@ export class PackagerService extends ConsoleLogger {
bucket_enter
=
1
*
1024
**
2
;
packagerWorkingDirectory
:
string
;
constructor
(
private
s3
:
PackageS3Service
,
config
:
ConfigService
)
{
constructor
(
@
Inject
(
forwardRef
(()
=>
AppService
))
private
readonly
appService
:
AppService
,
private
s3
:
PackageS3Service
,
config
:
ConfigService
)
{
super
(
'
packager
'
);
this
.
bucket_max
=
(
parseInt
(
config
.
get
(
'
PACKAGE_BUCKET_MAX
'
))
||
10
)
*
1024
**
2
;
this
.
bucket_enter
=
(
parseInt
(
config
.
get
(
'
PACKAGE_BUCKET_ENTER
'
))
||
1
)
*
1024
**
2
;
...
...
@@ -173,11 +178,14 @@ export class PackagerService extends ConsoleLogger {
const
existing
=
await
this
.
s3
.
fileExists
(
archiveName
);
if
(
existing
)
{
archive
.
size
=
existing
.
Size
;
return
archive
;
const
hash
=
await
this
.
appService
.
lookForExistingArchiveHash
(
archiveTask
.
path
);
if
(
hash
)
{
archive
.
hash
=
hash
;
return
archive
;
}
}
const
files
=
archiveTask
.
filePaths
;
this
.
log
(
`Packaging archive
${
archiveName
}
with
${
files
.
length
}
files.`
);
const
stream
=
new
Stream
.
Writable
();
const
child
=
child_process
.
spawn
(
'
tar
'
,
[
'
--zstd
'
,
'
-cf
'
,
'
-
'
].
concat
(
files
),
{
cwd
:
root
,
});
...
...
@@ -193,10 +201,20 @@ export class PackagerService extends ConsoleLogger {
reject
(
error
);
});
});
const
hashObject
=
createHash
(
'
sha512
'
);
child
.
stdout
.
on
(
'
data
'
,
(
chunk
)
=>
{
hashObject
.
update
(
chunk
);
});
if
(
existing
)
{
await
childPromise
;
archive
.
hash
=
hashObject
.
digest
(
'
hex
'
);
return
archive
;
}
const
uploadPromise
=
this
.
s3
.
uploadStream
(
archiveName
,
child
.
stdout
,
{
ContentType
:
'
application/tar+zstd
'
,
});
const
[,
{
object
}]
=
await
Promise
.
all
([
childPromise
,
uploadPromise
]);
archive
.
hash
=
hashObject
.
digest
(
'
hex
'
);
archive
.
size
=
object
.
Size
;
return
archive
;
}
...
...
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