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
1b6e065e
Commit
1b6e065e
authored
Aug 23, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use file relation
parent
a3afc3fd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
7 deletions
+59
-7
console-api/src/admin/admin.controller.ts
console-api/src/admin/admin.controller.ts
+8
-1
console-api/src/app.module.ts
console-api/src/app.module.ts
+3
-2
console-api/src/app.service.ts
console-api/src/app.service.ts
+22
-1
console-api/src/entities/Archive.entity.ts
console-api/src/entities/Archive.entity.ts
+6
-2
console-api/src/entities/ArchiveFile.entity.ts
console-api/src/entities/ArchiveFile.entity.ts
+17
-0
console-api/src/packager/packager.service.ts
console-api/src/packager/packager.service.ts
+3
-1
No files found.
console-api/src/admin/admin.controller.ts
View file @
1b6e065e
...
@@ -35,10 +35,17 @@ export class AdminController {
...
@@ -35,10 +35,17 @@ export class AdminController {
@
Post
(
'
migrate/hash
'
)
@
Post
(
'
migrate/hash
'
)
@
ApiOperation
({
summary
:
'
迁移 hash
'
})
@
ApiOperation
({
summary
:
'
迁移 hash
'
})
@
ApiCreatedResponse
({
type
:
BlankReturnMessageDto
})
@
ApiCreatedResponse
({
type
:
BlankReturnMessageDto
})
async
migrateHash
(
@
UploadedFile
(
'
file
'
)
file
:
Express
.
Multer
.
File
):
Promise
<
BlankReturnMessageDto
>
{
async
migrateHash
():
Promise
<
BlankReturnMessageDto
>
{
return
this
.
appService
.
migrateHashes
();
return
this
.
appService
.
migrateHashes
();
}
}
@
Post
(
'
migrate/filesField
'
)
@
ApiOperation
({
summary
:
'
迁移 file 字段
'
})
@
ApiCreatedResponse
({
type
:
BlankReturnMessageDto
})
async
migrateFilesField
():
Promise
<
BlankReturnMessageDto
>
{
return
this
.
appService
.
migrateFilesField
();
}
@
Put
(
'
app/:id
'
)
@
Put
(
'
app/:id
'
)
@
ApiOperation
({
summary
:
'
创建 app
'
})
@
ApiOperation
({
summary
:
'
创建 app
'
})
@
ApiOkResponse
({
type
:
BlankReturnMessageDto
})
@
ApiOkResponse
({
type
:
BlankReturnMessageDto
})
...
...
console-api/src/app.module.ts
View file @
1b6e065e
...
@@ -16,6 +16,7 @@ import { UpdateController } from './update/update.controller';
...
@@ -16,6 +16,7 @@ import { UpdateController } from './update/update.controller';
import
{
UpdateService
}
from
'
./update/update.service
'
;
import
{
UpdateService
}
from
'
./update/update.service
'
;
import
{
ServeStaticModule
}
from
'
@nestjs/serve-static
'
;
import
{
ServeStaticModule
}
from
'
@nestjs/serve-static
'
;
import
path
from
'
path
'
;
import
path
from
'
path
'
;
import
{
ArchiveFile
}
from
'
./entities/ArchiveFile.entity
'
;
const
configModule
=
ConfigModule
.
forRoot
();
const
configModule
=
ConfigModule
.
forRoot
();
...
@@ -32,14 +33,14 @@ const configModule = ConfigModule.forRoot();
...
@@ -32,14 +33,14 @@ const configModule = ConfigModule.forRoot();
useFactory
:
async
(
config
:
ConfigService
)
=>
{
useFactory
:
async
(
config
:
ConfigService
)
=>
{
return
{
return
{
type
:
'
postgres
'
,
type
:
'
postgres
'
,
entities
:
[
App
,
AppHistory
,
Archive
,
Build
,
Depot
],
// entities here
entities
:
[
App
,
AppHistory
,
Archive
,
Build
,
Depot
,
ArchiveFile
],
// entities here
synchronize
:
!
config
.
get
(
'
DB_NO_INIT
'
),
synchronize
:
!
config
.
get
(
'
DB_NO_INIT
'
),
host
:
config
.
get
(
'
DB_HOST
'
),
host
:
config
.
get
(
'
DB_HOST
'
),
port
:
parseInt
(
config
.
get
(
'
DB_PORT
'
))
||
5432
,
port
:
parseInt
(
config
.
get
(
'
DB_PORT
'
))
||
5432
,
username
:
config
.
get
(
'
DB_USER
'
),
username
:
config
.
get
(
'
DB_USER
'
),
password
:
config
.
get
(
'
DB_PASS
'
),
password
:
config
.
get
(
'
DB_PASS
'
),
database
:
config
.
get
(
'
DB_NAME
'
),
database
:
config
.
get
(
'
DB_NAME
'
),
logging
:
true
,
//
logging: true,
};
};
},
},
}),
}),
...
...
console-api/src/app.service.ts
View file @
1b6e065e
...
@@ -15,6 +15,8 @@ import { Archive, ArchiveType } from './entities/Archive.entity';
...
@@ -15,6 +15,8 @@ import { Archive, ArchiveType } from './entities/Archive.entity';
import
{
PackageS3Service
}
from
'
./package-s3/package-s3.service
'
;
import
{
PackageS3Service
}
from
'
./package-s3/package-s3.service
'
;
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
import
{
createHash
}
from
'
crypto
'
;
import
{
createHash
}
from
'
crypto
'
;
import
{
ArchiveFile
}
from
'
./entities/ArchiveFile.entity
'
;
import
_
from
'
lodash
'
;
@
Injectable
()
@
Injectable
()
export
class
AppService
extends
ConsoleLogger
{
export
class
AppService
extends
ConsoleLogger
{
...
@@ -294,7 +296,9 @@ export class AppService extends ConsoleLogger {
...
@@ -294,7 +296,9 @@ export class AppService extends ConsoleLogger {
}
}
await
this
.
purgeRelatedArchives
(
build
);
await
this
.
purgeRelatedArchives
(
build
);
await
this
.
db
.
transaction
(
async
(
edb
)
=>
{
await
this
.
db
.
transaction
(
async
(
edb
)
=>
{
await
edb
.
getRepository
(
Archive
).
delete
({
build
});
//const archives = await edb.getRepository(Archive).find({ where: { build } });
//await edb.getRepository(ArchiveFile).delete({ archive: In(archives) });
//await edb.getRepository(Archive).delete({ build });
await
edb
.
getRepository
(
Build
).
delete
(
build
);
await
edb
.
getRepository
(
Build
).
delete
(
build
);
});
});
return
new
BlankReturnMessageDto
(
200
,
'
success
'
);
return
new
BlankReturnMessageDto
(
200
,
'
success
'
);
...
@@ -340,4 +344,21 @@ export class AppService extends ConsoleLogger {
...
@@ -340,4 +344,21 @@ export class AppService extends ConsoleLogger {
await
this
.
db
.
getRepository
(
Archive
).
save
(
archivesToDo
);
await
this
.
db
.
getRepository
(
Archive
).
save
(
archivesToDo
);
return
new
BlankReturnMessageDto
(
200
,
'
success
'
);
return
new
BlankReturnMessageDto
(
200
,
'
success
'
);
}
}
async
migrateFilesField
()
{
const
archives
=
await
this
.
db
.
getRepository
(
Archive
).
find
({
select
:
[
'
id
'
,
'
files
'
]
});
await
this
.
db
.
transaction
(
async
(
edb
)
=>
{
for
(
const
a
of
archives
)
{
this
.
log
(
`Processing archive
${
a
.
id
}
with
${
a
.
files
.
length
}
files.`
);
const
files
=
a
.
files
.
map
((
f
)
=>
{
const
fileEnt
=
ArchiveFile
.
fromPath
(
f
);
fileEnt
.
archive
=
a
;
return
fileEnt
;
});
await
edb
.
getRepository
(
ArchiveFile
).
save
(
files
);
}
});
this
.
log
(
`Done.`
);
return
new
BlankReturnMessageDto
(
200
,
'
success
'
);
}
}
}
console-api/src/entities/Archive.entity.ts
View file @
1b6e065e
import
{
Column
,
Entity
,
ManyToOne
,
PrimaryGeneratedColumn
}
from
'
typeorm
'
;
import
{
Column
,
Entity
,
ManyToOne
,
OneToMany
,
PrimaryGeneratedColumn
}
from
'
typeorm
'
;
import
{
Build
}
from
'
./Build.entity
'
;
import
{
Build
}
from
'
./Build.entity
'
;
import
{
Index
}
from
'
typeorm
'
;
import
{
Index
}
from
'
typeorm
'
;
import
{
TimeBase
}
from
'
./TimeBase.entity
'
;
import
{
TimeBase
}
from
'
./TimeBase.entity
'
;
import
{
ArchiveFile
}
from
'
./ArchiveFile.entity
'
;
export
enum
ArchiveType
{
export
enum
ArchiveType
{
Full
=
'
full
'
,
Full
=
'
full
'
,
...
@@ -17,6 +18,9 @@ export class Archive extends TimeBase {
...
@@ -17,6 +18,9 @@ export class Archive extends TimeBase {
@
Column
(
'
varchar
'
,
{
length
:
256
,
array
:
true
})
@
Column
(
'
varchar
'
,
{
length
:
256
,
array
:
true
})
files
:
string
[];
files
:
string
[];
@
OneToMany
(()
=>
ArchiveFile
,
(
file
)
=>
file
.
archive
,
{
cascade
:
true
})
containingFiles
:
ArchiveFile
[];
@
Index
()
@
Index
()
@
Column
(
'
varchar
'
,
{
length
:
128
})
@
Column
(
'
varchar
'
,
{
length
:
128
})
path
:
string
;
path
:
string
;
...
@@ -27,7 +31,7 @@ export class Archive extends TimeBase {
...
@@ -27,7 +31,7 @@ export class Archive extends TimeBase {
@
Column
(
'
int
'
,
{
unsigned
:
true
})
@
Column
(
'
int
'
,
{
unsigned
:
true
})
size
:
number
;
size
:
number
;
@
ManyToOne
((
type
)
=>
Build
,
(
build
)
=>
build
.
archives
)
@
ManyToOne
((
type
)
=>
Build
,
(
build
)
=>
build
.
archives
,
{
onDelete
:
'
CASCADE
'
}
)
build
:
Build
;
build
:
Build
;
@
Index
()
@
Index
()
...
...
console-api/src/entities/ArchiveFile.entity.ts
0 → 100644
View file @
1b6e065e
import
{
Entity
,
ManyToOne
,
PrimaryColumn
}
from
'
typeorm
'
;
import
{
Archive
}
from
'
./Archive.entity
'
;
@
Entity
()
export
class
ArchiveFile
{
@
ManyToOne
(()
=>
Archive
,
(
a
)
=>
a
.
containingFiles
,
{
primary
:
true
,
onDelete
:
'
CASCADE
'
})
archive
:
Archive
;
@
PrimaryColumn
(
'
varchar
'
,
{
length
:
256
})
path
:
string
;
static
fromPath
(
path
:
string
)
{
const
archiveFile
=
new
ArchiveFile
();
archiveFile
.
path
=
path
;
return
archiveFile
;
}
}
console-api/src/packager/packager.service.ts
View file @
1b6e065e
...
@@ -16,6 +16,7 @@ import { Archive, ArchiveType } from '../entities/Archive.entity';
...
@@ -16,6 +16,7 @@ import { Archive, ArchiveType } from '../entities/Archive.entity';
import
{
Build
}
from
'
../entities/Build.entity
'
;
import
{
Build
}
from
'
../entities/Build.entity
'
;
import
{
AppService
}
from
'
../app.service
'
;
import
{
AppService
}
from
'
../app.service
'
;
import
{
createHash
}
from
'
crypto
'
;
import
{
createHash
}
from
'
crypto
'
;
import
{
ArchiveFile
}
from
'
../entities/ArchiveFile.entity
'
;
export
interface
FileWithHash
{
export
interface
FileWithHash
{
file
:
readdirp
.
EntryInfo
;
file
:
readdirp
.
EntryInfo
;
...
@@ -46,7 +47,8 @@ export class ArchiveTask {
...
@@ -46,7 +47,8 @@ export class ArchiveTask {
const
archive
=
new
Archive
();
const
archive
=
new
Archive
();
archive
.
path
=
this
.
path
;
archive
.
path
=
this
.
path
;
archive
.
role
=
this
.
role
;
archive
.
role
=
this
.
role
;
archive
.
files
=
this
.
exactFilePaths
;
archive
.
files
=
[];
archive
.
containingFiles
=
this
.
exactFilePaths
.
map
((
filePath
)
=>
ArchiveFile
.
fromPath
(
filePath
));
return
archive
;
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