Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-tips-biu-generator
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
ygopro-tips-biu-generator
Commits
599f70ca
Commit
599f70ca
authored
May 27, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remake for latest biu
parent
fdfe4b01
Pipeline
#3387
passed with stages
in 18 minutes
Changes
5
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
595 additions
and
44 deletions
+595
-44
package-lock.json
package-lock.json
+516
-40
package.json
package.json
+13
-4
src/app.controller.ts
src/app.controller.ts
+2
-0
src/app.service.ts
src/app.service.ts
+52
-0
src/main.ts
src/main.ts
+12
-0
No files found.
package-lock.json
View file @
599f70ca
This diff is collapsed.
Click to expand it.
package.json
View file @
599f70ca
...
@@ -24,21 +24,30 @@
...
@@ -24,21 +24,30 @@
"
@nestjs/common
"
:
"
^7.5.1
"
,
"
@nestjs/common
"
:
"
^7.5.1
"
,
"
@nestjs/core
"
:
"
^7.5.1
"
,
"
@nestjs/core
"
:
"
^7.5.1
"
,
"
@nestjs/platform-express
"
:
"
^7.5.1
"
,
"
@nestjs/platform-express
"
:
"
^7.5.1
"
,
"
@types/lodash
"
:
"
^4.14.168
"
,
"
@nestjs/swagger
"
:
"
^4.8.0
"
,
"
@nestjs/typeorm
"
:
"
^7.1.5
"
,
"
@types/cookie
"
:
"
^0.4.0
"
,
"
axios
"
:
"
^0.21.1
"
,
"
axios
"
:
"
^0.21.1
"
,
"
lodash
"
:
"
^4.17.20
"
,
"
class-transformer
"
:
"
^0.4.0
"
,
"
class-validator
"
:
"
^0.13.1
"
,
"
cookie
"
:
"
^0.4.1
"
,
"
lodash
"
:
"
^4.17.21
"
,
"
moment
"
:
"
^2.29.1
"
,
"
moment
"
:
"
^2.29.1
"
,
"
mysql
"
:
"
^2.18.1
"
,
"
p-queue
"
:
"
^6.6.2
"
,
"
p-queue
"
:
"
^6.6.2
"
,
"
reflect-metadata
"
:
"
^0.1.13
"
,
"
reflect-metadata
"
:
"
^0.1.13
"
,
"
rimraf
"
:
"
^3.0.2
"
,
"
rimraf
"
:
"
^3.0.2
"
,
"
rxjs
"
:
"
^6.6.3
"
"
rxjs
"
:
"
^6.6.3
"
,
"
swagger-ui-express
"
:
"
^4.1.6
"
,
"
typeorm
"
:
"
^0.2.32
"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"
@nestjs/cli
"
:
"
^7.5.1
"
,
"
@nestjs/cli
"
:
"
^7.5.1
"
,
"
@nestjs/schematics
"
:
"
^7.1.3
"
,
"
@nestjs/schematics
"
:
"
^7.1.3
"
,
"
@nestjs/testing
"
:
"
^7.5.1
"
,
"
@nestjs/testing
"
:
"
^7.5.1
"
,
"
@types/express
"
:
"
^4.17.
8
"
,
"
@types/express
"
:
"
^4.17.
12
"
,
"
@types/jest
"
:
"
^26.0.15
"
,
"
@types/jest
"
:
"
^26.0.15
"
,
"
@types/lodash
"
:
"
^4.14.170
"
,
"
@types/node
"
:
"
^14.14.6
"
,
"
@types/node
"
:
"
^14.14.6
"
,
"
@types/supertest
"
:
"
^2.0.10
"
,
"
@types/supertest
"
:
"
^2.0.10
"
,
"
@typescript-eslint/eslint-plugin
"
:
"
^4.6.1
"
,
"
@typescript-eslint/eslint-plugin
"
:
"
^4.6.1
"
,
...
...
src/app.controller.ts
View file @
599f70ca
import
{
Controller
,
Get
}
from
'
@nestjs/common
'
;
import
{
Controller
,
Get
}
from
'
@nestjs/common
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
ApiTags
}
from
'
@nestjs/swagger
'
;
@
Controller
()
@
Controller
()
export
class
AppController
{
export
class
AppController
{
constructor
(
private
readonly
appService
:
AppService
)
{}
constructor
(
private
readonly
appService
:
AppService
)
{}
@
Get
(
'
tips.json
'
)
@
Get
(
'
tips.json
'
)
@
ApiTags
(
'
tips
'
)
async
getTips
():
Promise
<
string
[]
>
{
async
getTips
():
Promise
<
string
[]
>
{
return
await
this
.
appService
.
getTips
();
return
await
this
.
appService
.
getTips
();
}
}
...
...
src/app.service.ts
View file @
599f70ca
...
@@ -4,18 +4,32 @@ import moment from 'moment';
...
@@ -4,18 +4,32 @@ import moment from 'moment';
import
PQueue
from
'
p-queue
'
;
import
PQueue
from
'
p-queue
'
;
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
import
_
from
'
lodash
'
;
import
_
from
'
lodash
'
;
import
qs
from
'
qs
'
;
import
cookie
from
'
cookie
'
;
const
blacklistedWords
=
[
'
曲
'
,
'
词
'
,
'
曲
'
,
'
詞
'
,
'
[Vv]ocal
'
,
'
:
'
,
'
:
'
];
const
blacklistedWords
=
[
'
曲
'
,
'
词
'
,
'
曲
'
,
'
詞
'
,
'
[Vv]ocal
'
,
'
:
'
,
'
:
'
];
const
blacklistedRegex
=
blacklistedWords
.
map
((
word
)
=>
new
RegExp
(
word
));
const
blacklistedRegex
=
blacklistedWords
.
map
((
word
)
=>
new
RegExp
(
word
));
interface
LoginInfo
{
email
:
string
;
password
:
string
;
}
@
Injectable
()
@
Injectable
()
export
class
AppService
{
export
class
AppService
{
cache
:
string
[];
cache
:
string
[];
lastFetchTime
:
moment
.
Moment
;
lastFetchTime
:
moment
.
Moment
;
queue
:
PQueue
;
queue
:
PQueue
;
loginInfo
:
LoginInfo
;
constructor
(
private
log
:
AppLogger
)
{
constructor
(
private
log
:
AppLogger
)
{
this
.
log
.
setContext
(
'
ygopro-tips-biu-generator
'
);
this
.
log
.
setContext
(
'
ygopro-tips-biu-generator
'
);
this
.
queue
=
new
PQueue
({
concurrency
:
1
});
this
.
queue
=
new
PQueue
({
concurrency
:
1
});
if
(
process
.
env
.
BIU_EMAIL
&&
process
.
env
.
BIU_PASSWORD
)
{
this
.
loginInfo
=
{
email
:
process
.
env
.
BIU_EMAIL
,
password
:
process
.
env
.
BIU_PASSWORD
,
};
}
}
}
async
getTips
():
Promise
<
string
[]
>
{
async
getTips
():
Promise
<
string
[]
>
{
...
@@ -68,11 +82,49 @@ export class AppService {
...
@@ -68,11 +82,49 @@ export class AppService {
}
}
}
}
async
getLoginCookie
()
{
if
(
!
this
.
loginInfo
)
{
return
undefined
;
}
try
{
this
.
log
.
log
(
`Logging in.`
);
const
ret
=
await
axios
.
post
(
'
https://web.biu.moe/User/doLogin
'
,
qs
.
stringify
(
this
.
loginInfo
),
{
responseType
:
'
json
'
,
timeout
:
30000
,
},
);
if
(
!
ret
.
data
.
status
)
{
this
.
log
.
error
(
`Login failed:
${
ret
.
data
.
message
}
`
);
return
undefined
;
}
const
setCookieContent
=
ret
.
headers
[
'
set-cookie
'
]
as
string
[];
if
(
!
setCookieContent
)
{
return
undefined
;
}
const
contentHits
=
setCookieContent
.
find
((
c
)
=>
c
.
includes
(
'
biuInfo
'
));
if
(
!
contentHits
)
{
return
undefined
;
}
const
token
=
cookie
.
parse
(
contentHits
).
biuInfo
as
string
;
this
.
log
.
log
(
`Login success:
${
token
}
`
);
return
cookie
.
serialize
(
'
biuInfo
'
,
token
);
}
catch
(
e
)
{
this
.
log
.
error
(
`Login error:
${
e
.
toString
()}
`
);
return
undefined
;
}
}
async
fetchTipsTask
():
Promise
<
string
[]
>
{
async
fetchTipsTask
():
Promise
<
string
[]
>
{
try
{
try
{
this
.
log
.
log
(
`Fetching song list.`
);
this
.
log
.
log
(
`Fetching song list.`
);
const
{
data
}
=
await
axios
.
get
(
'
https://web.biu.moe/Index/home
'
,
{
const
{
data
}
=
await
axios
.
get
(
'
https://web.biu.moe/Index/home
'
,
{
responseType
:
'
document
'
,
responseType
:
'
document
'
,
headers
:
{
Cookie
:
(
await
this
.
getLoginCookie
())
||
''
,
},
timeout
:
30000
,
timeout
:
30000
,
});
});
const
urls
=
(
data
as
string
).
match
(
/href="
\/
s
(\d
+
)
"/g
);
const
urls
=
(
data
as
string
).
match
(
/href="
\/
s
(\d
+
)
"/g
);
...
...
src/main.ts
View file @
599f70ca
import
{
NestFactory
}
from
'
@nestjs/core
'
;
import
{
NestFactory
}
from
'
@nestjs/core
'
;
import
{
SwaggerModule
,
DocumentBuilder
}
from
'
@nestjs/swagger
'
;
import
{
AppModule
}
from
'
./app.module
'
;
import
{
AppModule
}
from
'
./app.module
'
;
async
function
bootstrap
()
{
async
function
bootstrap
()
{
const
app
=
await
NestFactory
.
create
(
AppModule
);
const
app
=
await
NestFactory
.
create
(
AppModule
);
app
.
enableCors
();
app
.
enableCors
();
const
documentConfig
=
new
DocumentBuilder
()
.
setTitle
(
'
ygopro-tips-biu-generator
'
)
.
setDescription
(
'
YGOPro Tips 生成工具
'
)
.
setVersion
(
'
1.0
'
)
.
addTag
(
'
tips
'
)
.
build
();
const
document
=
SwaggerModule
.
createDocument
(
app
,
documentConfig
);
SwaggerModule
.
setup
(
'
docs
'
,
app
,
document
);
await
app
.
listen
(
3000
);
await
app
.
listen
(
3000
);
}
}
bootstrap
();
bootstrap
();
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