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
f2ab8518
Commit
f2ab8518
authored
Aug 17, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
assets
parent
1ca4c2bc
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
2153 additions
and
66 deletions
+2153
-66
console-api/package-lock.json
console-api/package-lock.json
+2040
-0
console-api/package.json
console-api/package.json
+2
-0
console-api/src/admin/admin.controller.ts
console-api/src/admin/admin.controller.ts
+0
-2
console-api/src/app.controller.ts
console-api/src/app.controller.ts
+36
-2
console-api/src/app.module.ts
console-api/src/app.module.ts
+27
-3
console-api/src/app.service.ts
console-api/src/app.service.ts
+23
-10
console-api/src/config.ts
console-api/src/config.ts
+0
-22
console-api/src/dto/ReturnMessage.dto.ts
console-api/src/dto/ReturnMessage.dto.ts
+22
-0
console-api/src/entities/App.entity.ts
console-api/src/entities/App.entity.ts
+0
-10
console-api/src/entities/AppBase.entity.ts
console-api/src/entities/AppBase.entity.ts
+2
-15
console-api/src/main.ts
console-api/src/main.ts
+1
-1
console-api/src/my-card-admin.guard.ts
console-api/src/my-card-admin.guard.ts
+0
-1
No files found.
console-api/package-lock.json
View file @
f2ab8518
This diff is collapsed.
Click to expand it.
console-api/package.json
View file @
f2ab8518
...
...
@@ -21,7 +21,9 @@
"test:e2e"
:
"jest --config ./test/jest-e2e.json"
},
"dependencies"
:
{
"@aws-sdk/client-s3"
:
"^3.26.0"
,
"@nestjs/common"
:
"^8.0.0"
,
"@nestjs/config"
:
"^1.0.1"
,
"@nestjs/core"
:
"^8.0.0"
,
"@nestjs/platform-express"
:
"^8.0.0"
,
"@nestjs/swagger"
:
"^5.0.9"
,
...
...
console-api/src/admin/admin.controller.ts
View file @
f2ab8518
...
...
@@ -2,9 +2,7 @@ import {
Body
,
Controller
,
Delete
,
Get
,
Param
,
ParseIntPipe
,
Post
,
Put
,
UploadedFile
,
...
...
console-api/src/app.controller.ts
View file @
f2ab8518
...
...
@@ -2,14 +2,17 @@ import {
Body
,
Controller
,
Get
,
ParseIntPipe
,
Post
,
Query
,
UploadedFile
,
UseGuards
,
UseInterceptors
,
ValidationPipe
,
}
from
'
@nestjs/common
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
ApiBody
,
ApiConsumes
,
ApiCreatedResponse
,
ApiOkResponse
,
ApiOperation
,
...
...
@@ -18,14 +21,23 @@ import {
import
{
BlankReturnMessageDto
,
GetAppReturnMessageDto
,
ReturnMessageDto
,
StringReturnMessageDto
,
}
from
'
./dto/ReturnMessage.dto
'
;
import
{
FetchMyCardUser
,
MyCardUser
}
from
'
./utility/mycard-auth
'
;
import
{
AppsJson
}
from
'
./utility/apps-json-type
'
;
import
{
MyCardAppMaintainerGuard
}
from
'
./my-card-app-maintainer.guard
'
;
import
{
S3Service
}
from
'
./s3/s3.service
'
;
import
{
FileInterceptor
}
from
'
@nestjs/platform-express
'
;
import
{
FileUploadDto
}
from
'
./dto/FileUpload.dto
'
;
import
AppClass
=
AppsJson
.
AppClass
;
@
Controller
(
'
api
'
)
export
class
AppController
{
constructor
(
private
readonly
appService
:
AppService
)
{}
constructor
(
private
readonly
appService
:
AppService
,
private
readonly
s3
:
S3Service
,
)
{}
@
Get
(
'
apps.json
'
)
getAppsJson
()
{
...
...
@@ -55,4 +67,26 @@ export class AppController {
)
{
return
this
.
appService
.
updateApp
(
user
,
app
.
id
,
app
);
}
@
Post
(
'
assets
'
)
@
ApiOperation
({
summary
:
'
上传附件
'
,
description
:
'
必须登录用户且必须是管理员或者拥有1个 app 才能上传
'
,
})
@
UseInterceptors
(
FileInterceptor
(
'
file
'
))
@
ApiConsumes
(
'
multipart/form-data
'
)
@
ApiBody
({
description
:
'
apps.json 文件
'
,
type
:
FileUploadDto
,
})
@
ApiCreatedResponse
({
type
:
StringReturnMessageDto
})
@
UseGuards
(
MyCardAppMaintainerGuard
)
async
uploadAssets
(@
UploadedFile
()
file
:
Express
.
Multer
.
File
)
{
const
res
=
await
this
.
s3
.
uploadAssets
(
file
);
if
(
res
)
{
return
new
ReturnMessageDto
(
201
,
'
success
'
,
res
);
}
else
{
throw
new
BlankReturnMessageDto
(
500
,
'
upload fail
'
).
toException
();
}
}
}
console-api/src/app.module.ts
View file @
f2ab8518
...
...
@@ -2,12 +2,36 @@ import { Module } from '@nestjs/common';
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
TypeOrmModule
}
from
'
@nestjs/typeorm
'
;
import
{
typeormConfig
}
from
'
./config
'
;
import
{
AdminController
}
from
'
./admin/admin.controller
'
;
import
{
ConfigModule
,
ConfigService
}
from
'
@nestjs/config
'
;
import
{
App
}
from
'
./entities/App.entity
'
;
import
{
AppHistory
}
from
'
./entities/AppHistory.entity
'
;
import
{
S3Service
}
from
'
./s3/s3.service
'
;
const
configModule
=
ConfigModule
.
forRoot
();
@
Module
({
imports
:
[
TypeOrmModule
.
forRoot
(
typeormConfig
())],
imports
:
[
configModule
,
TypeOrmModule
.
forRootAsync
({
name
:
'
app
'
,
imports
:
[
configModule
],
inject
:
[
ConfigService
],
useFactory
:
async
(
config
:
ConfigService
)
=>
{
return
{
type
:
'
postgres
'
,
entities
:
[
App
,
AppHistory
],
// entities here
synchronize
:
!
config
.
get
(
'
DB_NO_INIT
'
),
host
:
config
.
get
(
'
DB_HOST
'
),
port
:
parseInt
(
config
.
get
(
'
DB_PORT
'
))
||
5432
,
username
:
config
.
get
(
'
DB_USER
'
),
password
:
config
.
get
(
'
DB_PASS
'
),
database
:
config
.
get
(
'
DB_NAME
'
),
};
},
}),
],
controllers
:
[
AppController
,
AdminController
],
providers
:
[
AppService
],
providers
:
[
AppService
,
S3Service
],
})
export
class
AppModule
{}
console-api/src/app.service.ts
View file @
f2ab8518
import
{
Any
,
Connection
,
FindConditions
,
I
n
,
IsNull
,
Not
}
from
'
typeorm
'
;
import
{
Connectio
n
,
IsNull
,
Not
}
from
'
typeorm
'
;
import
{
InjectConnection
}
from
'
@nestjs/typeorm
'
;
import
{
Injectable
,
ConsoleLogger
,
HttpException
}
from
'
@nestjs/common
'
;
import
{
ConsoleLogger
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
AppsJson
}
from
'
./utility/apps-json-type
'
;
import
{
App
}
from
'
./entities/App.entity
'
;
import
{
...
...
@@ -22,7 +22,7 @@ export class AppService extends ConsoleLogger {
return
(
await
this
.
db
.
getRepository
(
App
)
.
find
({
where
:
{
app
Content
:
Not
(
IsNull
()),
isDeleted
:
false
}
})
.
find
({
where
:
{
app
Data
:
Not
(
IsNull
()),
isDeleted
:
false
}
})
).
map
((
a
)
=>
a
.
appData
);
}
...
...
@@ -84,6 +84,21 @@ export class AppService extends ConsoleLogger {
return
new
ReturnMessageDto
(
200
,
'
success
'
,
await
query
.
getMany
());
}
async
isUserCanMaintainApp
(
user
:
MyCardUser
,
id
?:
string
)
{
if
(
user
.
admin
)
{
return
true
;
}
const
query
=
this
.
db
.
getRepository
(
App
)
.
createQueryBuilder
(
'
app
'
)
.
where
(
'
app.isDeleted = false
'
)
.
andWhere
(
'
:uid = ANY(app.author)
'
,
{
uid
:
user
.
id
});
if
(
id
)
{
query
.
andWhere
(
'
app.id = :id
'
,
{
id
});
}
return
(
await
query
.
getCount
())
>
0
;
}
async
createApp
(
id
:
string
)
{
let
app
=
await
this
.
db
.
getRepository
(
App
)
...
...
@@ -115,13 +130,11 @@ export class AppService extends ConsoleLogger {
throw
new
BlankReturnMessageDto
(
401
,
'
Needs login
'
).
toException
();
}
appData
.
id
=
id
;
const
app
=
await
this
.
db
.
getRepository
(
App
)
.
findOne
({
where
:
{
id
:
appData
.
id
},
relations
:
[
'
history
'
],
select
:
[
'
id
'
,
'
author
'
,
'
appContent
'
],
});
const
app
=
await
this
.
db
.
getRepository
(
App
).
findOne
({
where
:
{
id
:
appData
.
id
},
relations
:
[
'
history
'
],
select
:
[
'
id
'
,
'
author
'
,
'
appData
'
],
});
if
(
!
app
)
{
throw
new
BlankReturnMessageDto
(
404
,
'
App not found
'
).
toException
();
}
...
...
console-api/src/config.ts
deleted
100644 → 0
View file @
1ca4c2bc
import
{
TypeOrmModuleOptions
}
from
'
@nestjs/typeorm
'
;
import
{
App
}
from
'
./entities/App.entity
'
;
import
{
AppHistory
}
from
'
./entities/AppHistory.entity
'
;
export
function
dbConfig
()
{
return
{
host
:
process
.
env
.
DB_HOST
,
port
:
process
.
env
.
DB_PORT
?
parseInt
(
process
.
env
.
DB_PORT
)
:
5432
,
username
:
process
.
env
.
DB_USER
,
password
:
process
.
env
.
DB_PASS
,
database
:
process
.
env
.
DB_NAME
,
};
}
export
function
typeormConfig
():
TypeOrmModuleOptions
{
return
{
name
:
'
app
'
,
type
:
'
postgres
'
,
entities
:
[
App
,
AppHistory
],
// entities here
synchronize
:
true
,
...
dbConfig
(),
};
}
console-api/src/dto/ReturnMessage.dto.ts
View file @
f2ab8518
...
...
@@ -33,3 +33,25 @@ export class GetAppReturnMessageDto extends BlankReturnMessageDto {
@
ApiProperty
({
description
:
'
返回 app
'
})
data
?:
AppsJson
.
AppClass
;
}
export
class
UploadAssignInfo
{
@
ApiProperty
({
description
:
'
下载地址
'
})
downloadUrl
:
string
;
@
ApiProperty
({
description
:
'
s3 上传地址,如果是空则不需要上传
'
})
uploadUrl
?:
string
;
constructor
(
downloadUrl
:
string
,
uploadurl
?:
string
)
{
this
.
downloadUrl
=
downloadUrl
;
this
.
uploadUrl
=
uploadurl
;
}
}
export
class
StringReturnMessageDto
extends
BlankReturnMessageDto
{
@
ApiProperty
({
description
:
'
返回字符串
'
})
data
?:
string
;
}
export
class
UploadAssignInfoReturnMessageDto
extends
BlankReturnMessageDto
{
@
ApiProperty
({
description
:
'
返回内容
'
})
data
?:
UploadAssignInfo
;
}
console-api/src/entities/App.entity.ts
View file @
f2ab8518
...
...
@@ -36,14 +36,4 @@ export class App extends AppBase {
h
.
appData
=
appData
;
this
.
history
.
push
(
h
);
}
get
appData
():
AppsJson
.
App
{
const
appData
=
super
.
appData
;
appData
.
id
=
this
.
id
;
return
appData
;
}
set
appData
(
a
)
{
this
.
appContent
=
JSON
.
stringify
(
a
);
}
}
console-api/src/entities/AppBase.entity.ts
View file @
f2ab8518
import
{
TimeBase
}
from
'
./TimeBase.entity
'
;
import
{
Column
}
from
'
typeorm
'
;
import
{
AppsJson
}
from
'
../utility/apps-json-type
'
;
import
{
MyCardUser
}
from
'
../utility/mycard-auth
'
;
export
class
AppBase
extends
TimeBase
{
@
Column
(
'
text
'
,
{
nullable
:
true
})
appContent
:
string
;
get
appData
():
AppsJson
.
App
{
if
(
!
this
.
appContent
)
{
return
null
;
}
const
a
=
JSON
.
parse
(
this
.
appContent
);
return
a
;
}
set
appData
(
a
)
{
this
.
appContent
=
JSON
.
stringify
(
a
);
}
@
Column
(
'
jsonb
'
,
{
nullable
:
true
})
appData
:
AppsJson
.
App
;
}
console-api/src/main.ts
View file @
f2ab8518
import
{
NestFactory
}
from
'
@nestjs/core
'
;
import
{
SwaggerModule
,
DocumentBuilder
}
from
'
@nestjs/swagger
'
;
import
{
DocumentBuilder
,
SwaggerModule
}
from
'
@nestjs/swagger
'
;
import
{
NestExpressApplication
}
from
'
@nestjs/platform-express
'
;
import
{
AppModule
}
from
'
./app.module
'
;
...
...
console-api/src/my-card-admin.guard.ts
View file @
f2ab8518
import
{
CanActivate
,
ExecutionContext
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
Observable
}
from
'
rxjs
'
;
import
{
getUserFromContext
}
from
'
./utility/mycard-auth
'
;
import
{
BlankReturnMessageDto
}
from
'
./dto/ReturnMessage.dto
'
;
...
...
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