Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Console Mirror Middleware
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
nanahira
Console Mirror Middleware
Commits
dade795c
Commit
dade795c
authored
Sep 08, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add middleware info
parent
6b24584a
Pipeline
#5419
passed with stages
in 2 minutes and 57 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
2 deletions
+44
-2
src/app.controller.ts
src/app.controller.ts
+17
-2
src/app.service.ts
src/app.service.ts
+13
-0
src/dto/MiddlewareInfo.dto.ts
src/dto/MiddlewareInfo.dto.ts
+8
-0
src/dto/ReturnMessage.dto.ts
src/dto/ReturnMessage.dto.ts
+6
-0
No files found.
src/app.controller.ts
View file @
dade795c
import
{
Body
,
Controller
,
Get
,
Post
,
ValidationPipe
}
from
'
@nestjs/common
'
;
import
{
Body
,
Controller
,
Get
,
Post
,
ValidationPipe
}
from
'
@nestjs/common
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
ApiBody
,
ApiCreatedResponse
,
ApiOperation
}
from
'
@nestjs/swagger
'
;
import
{
ApiBody
,
ApiCreatedResponse
,
ApiOkResponse
,
ApiOperation
,
}
from
'
@nestjs/swagger
'
;
import
{
PostUrlDto
}
from
'
./dto/PostUrl.dto
'
;
import
{
PostUrlDto
}
from
'
./dto/PostUrl.dto
'
;
import
{
StringReturnMessageDto
}
from
'
./dto/ReturnMessage.dto
'
;
import
{
MiddlewareInfoReturnMessageDto
,
StringReturnMessageDto
,
}
from
'
./dto/ReturnMessage.dto
'
;
@
Controller
()
@
Controller
()
export
class
AppController
{
export
class
AppController
{
constructor
(
private
readonly
appService
:
AppService
)
{}
constructor
(
private
readonly
appService
:
AppService
)
{}
@
Get
(
'
jsd
'
)
@
ApiOperation
({
summary
:
'
JSDelivr
'
,
description
:
'
需要配置 JSD_URL
'
})
@
ApiOkResponse
({
type
:
MiddlewareInfoReturnMessageDto
})
jsdInfo
()
{
return
this
.
appService
.
jsdInfo
();
}
@
Post
(
'
jsd
'
)
@
Post
(
'
jsd
'
)
@
ApiOperation
({
summary
:
'
JSDelivr
'
,
description
:
'
需要配置 JSD_URL
'
})
@
ApiOperation
({
summary
:
'
JSDelivr
'
,
description
:
'
需要配置 JSD_URL
'
})
@
ApiBody
({
type
:
PostUrlDto
})
@
ApiBody
({
type
:
PostUrlDto
})
...
...
src/app.service.ts
View file @
dade795c
...
@@ -11,13 +11,16 @@ import {
...
@@ -11,13 +11,16 @@ import {
import
FormData
from
'
form-data
'
;
import
FormData
from
'
form-data
'
;
import
{
PostUrlDto
}
from
'
./dto/PostUrl.dto
'
;
import
{
PostUrlDto
}
from
'
./dto/PostUrl.dto
'
;
import
hasha
from
'
hasha
'
;
import
hasha
from
'
hasha
'
;
import
{
MiddlewareInfoDto
}
from
'
./dto/MiddlewareInfo.dto
'
;
@
Injectable
()
@
Injectable
()
export
class
AppService
extends
ConsoleLogger
{
export
class
AppService
extends
ConsoleLogger
{
private
jsdUrl
:
string
;
private
jsdUrl
:
string
;
private
jsdIdentifier
:
string
;
constructor
(
config
:
ConfigService
,
private
http
:
HttpService
)
{
constructor
(
config
:
ConfigService
,
private
http
:
HttpService
)
{
super
(
'
app
'
);
super
(
'
app
'
);
this
.
jsdUrl
=
config
.
get
(
'
JSD_URL
'
);
this
.
jsdUrl
=
config
.
get
(
'
JSD_URL
'
);
this
.
jsdIdentifier
=
config
.
get
(
'
JSD_IDENTIFIER
'
)
||
`jsd-
${
this
.
jsdUrl
}
`
;
}
}
private
async
getStreamFromUrl
(
url
:
string
)
{
private
async
getStreamFromUrl
(
url
:
string
)
{
...
@@ -34,6 +37,16 @@ export class AppService extends ConsoleLogger {
...
@@ -34,6 +37,16 @@ export class AppService extends ConsoleLogger {
}
}
}
}
jsdInfo
()
{
if
(
!
this
.
jsdUrl
)
{
throw
new
BlankReturnMessageDto
(
404
,
'
JSDelivr is not configured.
'
);
}
const
info
=
new
MiddlewareInfoDto
();
info
.
identifier
=
this
.
jsdIdentifier
;
info
.
maxSize
=
50
*
1024
*
1024
;
return
new
ReturnMessageDto
(
200
,
'
success
'
,
info
);
}
async
jsd
(
urlDto
:
PostUrlDto
)
{
async
jsd
(
urlDto
:
PostUrlDto
)
{
if
(
!
this
.
jsdUrl
)
{
if
(
!
this
.
jsdUrl
)
{
throw
new
BlankReturnMessageDto
(
404
,
'
JSDelivr is not configured.
'
);
throw
new
BlankReturnMessageDto
(
404
,
'
JSDelivr is not configured.
'
);
...
...
src/dto/MiddlewareInfo.dto.ts
0 → 100644
View file @
dade795c
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
export
class
MiddlewareInfoDto
{
@
ApiProperty
({
description
:
'
标识符
'
})
identifier
:
string
;
@
ApiProperty
({
description
:
'
最大文件大小
'
})
maxSize
?:
number
;
}
src/dto/ReturnMessage.dto.ts
View file @
dade795c
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
HttpException
}
from
'
@nestjs/common
'
;
import
{
HttpException
}
from
'
@nestjs/common
'
;
import
{
MiddlewareInfoDto
}
from
'
./MiddlewareInfo.dto
'
;
export
interface
BlankReturnMessage
{
export
interface
BlankReturnMessage
{
statusCode
:
number
;
statusCode
:
number
;
...
@@ -44,3 +45,8 @@ export class StringReturnMessageDto extends BlankReturnMessageDto {
...
@@ -44,3 +45,8 @@ export class StringReturnMessageDto extends BlankReturnMessageDto {
@
ApiProperty
({
description
:
'
返回内容
'
})
@
ApiProperty
({
description
:
'
返回内容
'
})
data
:
string
;
data
:
string
;
}
}
export
class
MiddlewareInfoReturnMessageDto
extends
BlankReturnMessageDto
{
@
ApiProperty
({
description
:
'
返回内容
'
})
data
:
MiddlewareInfoDto
;
}
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