Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
Ygopro Arena Revive
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
Ygopro Arena Revive
Commits
0df1c6b5
Commit
0df1c6b5
authored
Oct 21, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add /api/novelai-auth
parent
df1ebd2a
Pipeline
#17332
passed with stages
in 3 minutes and 45 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1854 additions
and
1202 deletions
+1854
-1202
package-lock.json
package-lock.json
+1724
-1192
package.json
package.json
+1
-1
src/account/account.service.spec.ts
src/account/account.service.spec.ts
+18
-0
src/account/account.service.ts
src/account/account.service.ts
+60
-0
src/app.controller.ts
src/app.controller.ts
+18
-8
src/app.module.ts
src/app.module.ts
+2
-0
src/app.service.ts
src/app.service.ts
+24
-1
src/config.ts
src/config.ts
+7
-0
No files found.
package-lock.json
View file @
0df1c6b5
This source diff could not be displayed because it is too large. You can
view the blob
instead.
package.json
View file @
0df1c6b5
...
...
@@ -46,7 +46,7 @@
"
rxjs
"
:
"
^6.6.3
"
,
"
sqlite3
"
:
"
^5.0.0
"
,
"
swagger-ui-express
"
:
"
^4.1.6
"
,
"
typeorm
"
:
"
^0.2.37
"
,
"
typeorm
"
:
"
0.2.45
"
,
"
underscore
"
:
"
^1.12.0
"
},
"devDependencies"
:
{
...
...
src/account/account.service.spec.ts
0 → 100644
View file @
0df1c6b5
import
{
Test
,
TestingModule
}
from
'
@nestjs/testing
'
;
import
{
AccountService
}
from
'
./account.service
'
;
describe
(
'
AccountService
'
,
()
=>
{
let
service
:
AccountService
;
beforeEach
(
async
()
=>
{
const
module
:
TestingModule
=
await
Test
.
createTestingModule
({
providers
:
[
AccountService
],
}).
compile
();
service
=
module
.
get
<
AccountService
>
(
AccountService
);
});
it
(
'
should be defined
'
,
()
=>
{
expect
(
service
).
toBeDefined
();
});
});
src/account/account.service.ts
0 → 100644
View file @
0df1c6b5
import
{
HttpException
,
HttpService
,
Inject
,
Injectable
,
InternalServerErrorException
,
}
from
'
@nestjs/common
'
;
import
{
config
}
from
'
src/config
'
;
export
interface
MycardUser
{
id
:
number
;
username
:
string
;
name
:
string
;
email
:
string
;
password_hash
:
string
;
salt
:
string
;
active
:
boolean
;
admin
:
boolean
;
avatar
:
string
;
locale
:
string
;
registration_ip_address
:
string
;
ip_address
:
string
;
created_at
:
string
;
updated_at
:
string
;
}
@
Injectable
()
export
class
AccountService
{
private
url
=
config
.
accountsUrl
+
'
/authUser
'
;
constructor
(
private
http
:
HttpService
)
{}
async
getUserFromToken
(
token
:
string
):
Promise
<
MycardUser
>
{
try
{
const
result
=
await
this
.
http
.
get
<
MycardUser
&
{
error
?:
string
}
>
(
this
.
url
,
{
responseType
:
'
json
'
,
headers
:
{
Authorization
:
`Bearer
${
token
}
`
,
},
})
.
toPromise
();
if
(
result
.
status
>=
400
)
{
throw
new
HttpException
(
result
.
data
?.
error
,
result
.
status
);
}
return
result
.
data
;
}
catch
(
e
)
{
throw
new
InternalServerErrorException
(
e
);
}
}
async
checkToken
(
token
:
string
)
{
if
(
typeof
token
!==
'
string
'
)
{
throw
new
HttpException
(
'
Invalid token
'
,
400
);
}
if
(
token
.
startsWith
(
'
Bearer
'
))
{
token
=
token
.
slice
(
7
);
}
return
this
.
getUserFromToken
(
token
);
}
}
src/app.controller.ts
View file @
0df1c6b5
...
...
@@ -4,31 +4,33 @@ import {
Controller
,
ForbiddenException
,
Get
,
Headers
,
HttpCode
,
HttpException
,
InternalServerErrorException
,
NotFoundException
,
Param
,
ParseIntPipe
,
Post
,
Query
,
Req
,
Res
,
UploadedFile
,
UploadedFiles
,
UseInterceptors
,
}
from
'
@nestjs/common
'
;
import
express
from
'
express
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
UserInfo
}
from
'
./entities/mycard/UserInfo
'
;
import
{
config
}
from
'
./config
'
;
import
{
AnyFilesInterceptor
,
FileInterceptor
}
from
'
@nestjs/platform-express
'
;
import
{
FileInterceptor
}
from
'
@nestjs/platform-express
'
;
import
{
HttpResponseService
}
from
'
./http-response/http-response.service
'
;
import
{
CodeResponseDto
}
from
'
./dto/CodeResponse.dto
'
;
import
multer
from
'
multer
'
;
import
cryptoRandomString
from
'
crypto-random-string
'
;
import
{
join
}
from
'
path
'
;
import
{
ApiBody
,
ApiConsumes
,
ApiTags
}
from
'
@nestjs/swagger
'
;
import
{
ApiBody
,
ApiConsumes
,
ApiHeader
,
ApiOkResponse
,
ApiOperation
,
ApiTags
,
}
from
'
@nestjs/swagger
'
;
import
{
FileUploadDto
}
from
'
./dto/FileUploadDto
'
;
import
{
HomePageMatchCountDto
}
from
'
./dto/HomePageMatchCount.dto
'
;
...
...
@@ -271,4 +273,12 @@ export class AppController {
async
getLastMonthBattleCount
():
Promise
<
HomePageMatchCountDto
>
{
return
this
.
appService
.
getLastMonthBattleCount
();
}
@
Get
(
'
novelai-auth
'
)
@
ApiOperation
({
summary
:
'
novelai 用认证
'
})
@
ApiHeader
({
name
:
'
Authorization
'
})
@
ApiOkResponse
({
type
:
CodeResponseDto
})
async
novelaiAuth
(@
Headers
(
'
Authorization
'
)
token
:
string
)
{
return
this
.
appService
.
novelaiAuth
(
token
);
}
}
src/app.module.ts
View file @
0df1c6b5
...
...
@@ -52,6 +52,7 @@ import { CardInfoService } from './card-info/card-info.service';
import
{
ServeStaticModule
}
from
'
@nestjs/serve-static
'
;
import
{
join
}
from
'
path
'
;
import
{
AthleticCheckerService
}
from
'
./athletic-checker/athletic-checker.service
'
;
import
{
AccountService
}
from
'
./account/account.service
'
;
const
ygoproEntities
=
[
YGOProDatabaseDatas
,
YGOProDatabaseTexts
];
const
mycardEntities
=
[
...
...
@@ -138,6 +139,7 @@ const mycardEntities = [
EloService
,
CardInfoService
,
AthleticCheckerService
,
AccountService
,
],
})
export
class
AppModule
{}
src/app.service.ts
View file @
0df1c6b5
import
{
Injectable
,
NotFoundException
}
from
'
@nestjs/common
'
;
import
{
HttpException
,
Injectable
,
NotFoundException
}
from
'
@nestjs/common
'
;
import
{
InjectConnection
,
InjectEntityManager
}
from
'
@nestjs/typeorm
'
;
import
{
Brackets
,
...
...
@@ -38,6 +38,8 @@ import { EloService } from './elo/elo.service';
import
{
CardInfoService
}
from
'
./card-info/card-info.service
'
;
import
{
AthleticCheckerService
}
from
'
./athletic-checker/athletic-checker.service
'
;
import
{
HomePageMatchCountDto
}
from
'
./dto/HomePageMatchCount.dto
'
;
import
{
AccountService
}
from
'
./account/account.service
'
;
import
{
CodeResponseDto
}
from
'
./dto/CodeResponse.dto
'
;
const
attrOffset
=
1010
;
const
raceOffset
=
1020
;
...
...
@@ -122,6 +124,7 @@ export class AppService {
private
eloService
:
EloService
,
private
cardInfoService
:
CardInfoService
,
private
athleticCheckerService
:
AthleticCheckerService
,
private
accountService
:
AccountService
,
)
{
this
.
log
.
setContext
(
'
ygopro-arena-revive
'
);
this
.
chineseDirtyFilter
=
new
Filter
({
...
...
@@ -1777,4 +1780,24 @@ export class AppService {
});
return
new
HomePageMatchCountDto
(
count
);
}
async
novelaiAuth
(
token
:
string
)
{
const
user
=
await
this
.
accountService
.
checkToken
(
token
);
if
(
user
.
admin
)
{
return
new
CodeResponseDto
(
200
);
}
return
this
.
mcdb
.
transaction
(
async
(
edb
)
=>
{
const
userInfo
=
await
edb
.
getRepository
(
UserInfo
).
findOne
({
select
:
[
'
username
'
,
'
exp
'
],
where
:
{
username
:
user
.
username
},
});
if
(
!
userInfo
||
userInfo
.
exp
<
config
.
novelaiCost
)
{
throw
new
HttpException
(
new
CodeResponseDto
(
402
),
402
);
}
await
edb
.
getRepository
(
UserInfo
)
.
decrement
({
username
:
user
.
username
},
'
exp
'
,
config
.
novelaiCost
);
return
new
CodeResponseDto
(
200
);
});
}
}
src/config.ts
View file @
0df1c6b5
...
...
@@ -8,6 +8,8 @@ export interface Config {
deckIdentifierPath
:
string
;
analyzerHost
:
string
;
enableSchedule
:
boolean
;
accountsUrl
:
string
;
novelaiCost
:
number
;
}
export
const
athleticCheckConfig
=
{
...
...
@@ -31,4 +33,9 @@ export const config: Config = {
deckIdentifierPath
:
process
.
env
.
DECK_IDENTIFIER_PATH
,
analyzerHost
:
process
.
env
.
ANALYZER_HOST
,
enableSchedule
:
!
process
.
env
.
NO_SCHEDULE
,
accountsUrl
:
process
.
env
.
ACCOUNTS_URL
||
'
https://sapi.moecube.com:444/accounts
'
,
novelaiCost
:
process
.
env
.
NOVELAI_COST
?
parseInt
(
process
.
env
.
NOVELAI_COST
)
:
3
,
};
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