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
e26cbc81
You need to sign in or sign up before continuing.
Commit
e26cbc81
authored
Oct 26, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support running on other IP
parent
6b2f67a6
Pipeline
#17475
passed with stages
in 2 minutes and 47 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
11 deletions
+26
-11
src/abstract/controller.ts
src/abstract/controller.ts
+3
-2
src/abstract/service.ts
src/abstract/service.ts
+1
-1
src/dto/Mirror.dto.ts
src/dto/Mirror.dto.ts
+10
-3
src/one-two-three/one-two-three.service.ts
src/one-two-three/one-two-three.service.ts
+12
-5
No files found.
src/abstract/controller.ts
View file @
e26cbc81
import
{
Body
,
Get
,
Patch
,
Post
,
ValidationPipe
}
from
'
@nestjs/common
'
;
import
{
Body
,
Get
,
Ip
,
Patch
,
Post
,
ValidationPipe
}
from
'
@nestjs/common
'
;
import
{
import
{
ApiBody
,
ApiBody
,
ApiCreatedResponse
,
ApiCreatedResponse
,
...
@@ -48,11 +48,12 @@ export class MiddlewareController {
...
@@ -48,11 +48,12 @@ export class MiddlewareController {
@
ApiOkResponse
({
type
:
StringReturnMessageDto
})
@
ApiOkResponse
({
type
:
StringReturnMessageDto
})
async
download
(
async
download
(
@
Body
(
new
ValidationPipe
({
transform
:
true
}))
mirrorDto
:
MirrorDto
,
@
Body
(
new
ValidationPipe
({
transform
:
true
}))
mirrorDto
:
MirrorDto
,
@
Ip
()
ip
:
string
,
)
{
)
{
return
new
ReturnMessageDto
(
return
new
ReturnMessageDto
(
200
,
200
,
'
success
'
,
'
success
'
,
await
this
.
middlewareService
.
download
(
mirrorDto
),
await
this
.
middlewareService
.
download
(
mirrorDto
,
ip
),
);
);
}
}
}
}
src/abstract/service.ts
View file @
e26cbc81
...
@@ -16,7 +16,7 @@ export class MiddlewareService extends ConsoleLogger {
...
@@ -16,7 +16,7 @@ export class MiddlewareService extends ConsoleLogger {
async
upload
(
urlDto
:
PostUrlDto
):
Promise
<
string
>
{
async
upload
(
urlDto
:
PostUrlDto
):
Promise
<
string
>
{
throw
new
BlankReturnMessageDto
(
404
,
'
Not Implemented
'
).
toException
();
throw
new
BlankReturnMessageDto
(
404
,
'
Not Implemented
'
).
toException
();
}
}
async
download
(
mirror
:
MirrorDto
):
Promise
<
string
>
{
async
download
(
mirror
:
MirrorDto
,
ip
:
string
):
Promise
<
string
>
{
return
mirror
.
url
;
return
mirror
.
url
;
}
}
}
}
src/dto/Mirror.dto.ts
View file @
e26cbc81
import
{
IsString
}
from
'
class-validator
'
;
import
{
Is
Optional
,
Is
String
}
from
'
class-validator
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
export
class
MirrorDto
{
export
class
MirrorDto
{
@
IsString
()
@
IsString
()
@
IsOptional
()
@
ApiProperty
({
description
:
'
文件标识路径。
'
})
@
ApiProperty
({
description
:
'
文件标识路径。
'
})
path
:
string
;
path
?
:
string
;
@
IsString
()
@
IsString
()
@
ApiProperty
({
description
:
'
文件地址,middleware 曾经返回的。
'
})
@
ApiProperty
({
description
:
'
文件地址,middleware 曾经返回的。
'
})
url
:
string
;
url
:
string
;
@
IsString
()
@
IsString
()
@
IsOptional
()
@
ApiProperty
({
description
:
'
middleware 标识符
'
})
@
ApiProperty
({
description
:
'
middleware 标识符
'
})
middleware
:
string
;
middleware
?:
string
;
@
IsString
()
@
IsOptional
()
@
ApiProperty
({
description
:
'
下载的客户端 IP
'
})
clientIp
?:
string
;
}
}
src/one-two-three/one-two-three.service.ts
View file @
e26cbc81
...
@@ -219,7 +219,7 @@ export class OneTwoThreeService extends MiddlewareService {
...
@@ -219,7 +219,7 @@ export class OneTwoThreeService extends MiddlewareService {
}
}
}
}
async
getDownloadUrl
(
fileInfo
:
FileInfo
)
{
async
getDownloadUrl
(
fileInfo
:
FileInfo
,
ip
:
string
)
{
const
downloadReq
=
await
lastValueFrom
(
const
downloadReq
=
await
lastValueFrom
(
this
.
http
.
post
<
OTTResponse
<
UploadReq
>>
(
this
.
http
.
post
<
OTTResponse
<
UploadReq
>>
(
'
https://www.123pan.com/api/file/download_info
'
,
'
https://www.123pan.com/api/file/download_info
'
,
...
@@ -228,6 +228,7 @@ export class OneTwoThreeService extends MiddlewareService {
...
@@ -228,6 +228,7 @@ export class OneTwoThreeService extends MiddlewareService {
responseType
:
'
json
'
,
responseType
:
'
json
'
,
headers
:
{
headers
:
{
Authorization
:
`Bearer
${
await
this
.
login
()}
`
,
Authorization
:
`Bearer
${
await
this
.
login
()}
`
,
'
X-Forwarded-For
'
:
ip
,
},
},
},
},
),
),
...
@@ -238,16 +239,19 @@ export class OneTwoThreeService extends MiddlewareService {
...
@@ -238,16 +239,19 @@ export class OneTwoThreeService extends MiddlewareService {
return
downloadReq
.
data
.
data
.
DownloadUrl
;
return
downloadReq
.
data
.
data
.
DownloadUrl
;
}
}
async
parse302
(
url
:
string
)
{
async
parse302
(
url
:
string
,
ip
:
string
)
{
if
(
url
.
includes
(
'
?params=
'
))
{
if
(
url
.
includes
(
'
?params=
'
))
{
const
params
=
url
.
split
(
'
?params=
'
)[
1
];
const
params
=
url
.
split
(
'
?params=
'
)[
1
];
const
decoded
=
Buffer
.
from
(
params
,
'
base64
'
).
toString
(
'
utf-8
'
);
const
decoded
=
Buffer
.
from
(
params
,
'
base64
'
).
toString
(
'
utf-8
'
);
return
this
.
parse302
(
decoded
);
return
this
.
parse302
(
decoded
,
ip
);
}
}
const
tmpLinkReq
=
await
lastValueFrom
(
const
tmpLinkReq
=
await
lastValueFrom
(
this
.
http
.
head
(
url
,
{
this
.
http
.
head
(
url
,
{
maxRedirects
:
0
,
maxRedirects
:
0
,
validateStatus
:
(
c
)
=>
c
===
302
||
c
===
301
||
c
===
200
,
validateStatus
:
(
c
)
=>
c
===
302
||
c
===
301
||
c
===
200
,
headers
:
{
'
X-Forwarded-For
'
:
ip
,
},
}),
}),
);
);
if
(
tmpLinkReq
.
status
!==
200
)
{
if
(
tmpLinkReq
.
status
!==
200
)
{
...
@@ -256,10 +260,13 @@ export class OneTwoThreeService extends MiddlewareService {
...
@@ -256,10 +260,13 @@ export class OneTwoThreeService extends MiddlewareService {
return
url
;
return
url
;
}
}
async
download
(
info
)
{
async
download
(
info
,
ip
:
string
)
{
try
{
try
{
const
fileInfo
=
JSON
.
parse
(
info
.
url
)
as
FileInfo
;
const
fileInfo
=
JSON
.
parse
(
info
.
url
)
as
FileInfo
;
return
await
this
.
parse302
(
await
this
.
getDownloadUrl
(
fileInfo
));
return
await
this
.
parse302
(
await
this
.
getDownloadUrl
(
fileInfo
,
info
.
ip
||
ip
),
info
.
ip
||
ip
,
);
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
error
(
`Download failed:
${
e
.
message
}
`
);
this
.
error
(
`Download failed:
${
e
.
message
}
`
);
throw
new
BlankReturnMessageDto
(
500
,
e
.
message
).
toException
();
throw
new
BlankReturnMessageDto
(
500
,
e
.
message
).
toException
();
...
...
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