Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Momento
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
Momento
Commits
b9159b32
Commit
b9159b32
authored
Dec 25, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jwt
parent
d9c2f05e
Pipeline
#8117
passed with stages
in 4 minutes and 4 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
94 additions
and
6 deletions
+94
-6
config.example.yaml
config.example.yaml
+3
-1
src/app.module.ts
src/app.module.ts
+3
-2
src/auth/auth.controller.spec.ts
src/auth/auth.controller.spec.ts
+18
-0
src/auth/auth.controller.ts
src/auth/auth.controller.ts
+48
-0
src/auth/dto/SendCode.dto.ts
src/auth/dto/SendCode.dto.ts
+10
-0
src/dto/ReturnMessage.dto.ts
src/dto/ReturnMessage.dto.ts
+6
-2
src/message/message.service.ts
src/message/message.service.ts
+1
-1
src/utility/config.ts
src/utility/config.ts
+5
-0
No files found.
config.example.yaml
View file @
b9159b32
...
@@ -17,4 +17,6 @@ jwt:
...
@@ -17,4 +17,6 @@ jwt:
secretOrPrivateKey
:
'
secret'
secretOrPrivateKey
:
'
secret'
signOptions
:
signOptions
:
expiresIn
:
'
1d'
expiresIn
:
'
1d'
centerAccount
:
'
1111111111'
centerAccount
:
'
1111111111'
\ No newline at end of file
es
:
secret
:
'
http://localhost:9200'
\ No newline at end of file
src/app.module.ts
View file @
b9159b32
...
@@ -21,8 +21,9 @@ import { AuthController } from './auth/auth.controller';
...
@@ -21,8 +21,9 @@ import { AuthController } from './auth/auth.controller';
load
:
[
loadConfig
],
load
:
[
loadConfig
],
isGlobal
:
true
,
isGlobal
:
true
,
}),
}),
ElasticsearchModule
.
register
({
ElasticsearchModule
.
registerAsync
({
node
:
'
http://poi.lan:9200
'
,
inject
:
[
ConfigService
],
useFactory
:
(
configService
:
ConfigService
)
=>
configService
.
get
(
'
es
'
),
}),
}),
KoishiModule
.
registerAsync
({
KoishiModule
.
registerAsync
({
inject
:
[
ConfigService
],
inject
:
[
ConfigService
],
...
...
src/auth/auth.controller.spec.ts
0 → 100644
View file @
b9159b32
import
{
Test
,
TestingModule
}
from
'
@nestjs/testing
'
;
import
{
AuthController
}
from
'
./auth.controller
'
;
describe
(
'
AuthController
'
,
()
=>
{
let
controller
:
AuthController
;
beforeEach
(
async
()
=>
{
const
module
:
TestingModule
=
await
Test
.
createTestingModule
({
controllers
:
[
AuthController
],
}).
compile
();
controller
=
module
.
get
<
AuthController
>
(
AuthController
);
});
it
(
'
should be defined
'
,
()
=>
{
expect
(
controller
).
toBeDefined
();
});
});
src/auth/auth.controller.ts
0 → 100644
View file @
b9159b32
import
{
Body
,
Controller
,
Headers
,
Post
,
ValidationPipe
,
}
from
'
@nestjs/common
'
;
import
{
ApiBody
,
ApiCreatedResponse
,
ApiHeader
,
ApiOperation
,
ApiTags
,
}
from
'
@nestjs/swagger
'
;
import
{
AuthService
}
from
'
./auth.service
'
;
import
{
SendCodeDto
}
from
'
./dto/SendCode.dto
'
;
import
{
BlankReturnMessageDto
,
ReturnMessageDto
,
StringReturnMessageDto
,
}
from
'
../dto/ReturnMessage.dto
'
;
@
Controller
(
'
api/auth
'
)
@
ApiTags
(
'
Auth
'
)
export
class
AuthController
{
constructor
(
private
readonly
authService
:
AuthService
)
{}
@
Post
(
'
sendcode
'
)
@
ApiOperation
({
summary
:
'
发送 token
'
})
@
ApiBody
({
type
:
SendCodeDto
})
@
ApiCreatedResponse
({
type
:
BlankReturnMessageDto
})
async
sendCode
(
@
Body
(
new
ValidationPipe
({
transform
:
true
}))
sendCodeDto
:
SendCodeDto
,
):
Promise
<
BlankReturnMessageDto
>
{
await
this
.
authService
.
sendCode
(
sendCodeDto
.
userId
);
return
new
BlankReturnMessageDto
(
201
,
'
success
'
);
}
@
Post
(
'
verifycode
'
)
@
ApiOperation
({
summary
:
'
验证 token
'
})
@
ApiHeader
({
name
:
'
Authorization
'
,
required
:
true
})
@
ApiCreatedResponse
({
type
:
StringReturnMessageDto
})
async
verifyCode
(@
Headers
(
'
Authorization
'
)
token
:
string
)
{
const
realToken
=
token
?.
startsWith
(
'
Bearer
'
)
?
token
.
substring
(
7
)
:
token
;
const
userId
=
await
this
.
authService
.
verify
(
realToken
);
return
new
ReturnMessageDto
(
201
,
'
success
'
,
userId
);
}
}
src/auth/dto/SendCode.dto.ts
0 → 100644
View file @
b9159b32
import
{
IsNumberString
,
MaxLength
,
MinLength
}
from
'
class-validator
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
export
class
SendCodeDto
{
@
IsNumberString
()
@
MinLength
(
5
)
@
MaxLength
(
11
)
@
ApiProperty
({
description
:
'
QQ号码
'
,
example
:
'
123456789
'
})
userId
:
string
;
}
src/dto/ReturnMessage.dto.ts
View file @
b9159b32
...
@@ -31,8 +31,7 @@ export class BlankReturnMessageDto implements BlankReturnMessage {
...
@@ -31,8 +31,7 @@ export class BlankReturnMessageDto implements BlankReturnMessage {
export
class
ReturnMessageDto
<
T
>
export
class
ReturnMessageDto
<
T
>
extends
BlankReturnMessageDto
extends
BlankReturnMessageDto
implements
ReturnMessage
<
T
>
implements
ReturnMessage
<
T
>
{
{
@
ApiProperty
({
description
:
'
返回内容
'
})
@
ApiProperty
({
description
:
'
返回内容
'
})
data
?:
T
;
data
?:
T
;
constructor
(
statusCode
:
number
,
message
?:
string
,
data
?:
T
)
{
constructor
(
statusCode
:
number
,
message
?:
string
,
data
?:
T
)
{
...
@@ -40,3 +39,8 @@ export class ReturnMessageDto<T>
...
@@ -40,3 +39,8 @@ export class ReturnMessageDto<T>
this
.
data
=
data
;
this
.
data
=
data
;
}
}
}
}
export
class
StringReturnMessageDto
extends
BlankReturnMessageDto
{
@
ApiProperty
({
description
:
'
返回内容
'
})
data
:
string
;
}
src/message/message.service.ts
View file @
b9159b32
...
@@ -55,7 +55,7 @@ export class MessageService
...
@@ -55,7 +55,7 @@ export class MessageService
);
);
await
this
.
elasticsearchService
.
index
({
await
this
.
elasticsearchService
.
index
({
index
:
session
.
selfId
,
index
:
`user_message_
${
session
.
selfId
}
`
,
body
:
{
body
:
{
selfId
:
session
.
selfId
,
selfId
:
session
.
selfId
,
type
:
session
.
subtype
as
string
,
type
:
session
.
subtype
as
string
,
...
...
src/utility/config.ts
View file @
b9159b32
...
@@ -5,6 +5,7 @@ import S3Assets from '@koishijs/plugin-assets-s3';
...
@@ -5,6 +5,7 @@ import S3Assets from '@koishijs/plugin-assets-s3';
import
{
AdapterConfig
}
from
'
../onebot-improved/utils
'
;
import
{
AdapterConfig
}
from
'
../onebot-improved/utils
'
;
import
{
BotConfig
}
from
'
../onebot-improved
'
;
import
{
BotConfig
}
from
'
../onebot-improved
'
;
import
{
JwtModuleOptions
}
from
'
@nestjs/jwt
'
;
import
{
JwtModuleOptions
}
from
'
@nestjs/jwt
'
;
import
{
ClientOptions
}
from
'
@elastic/elasticsearch
'
;
export
interface
Config
{
export
interface
Config
{
host
:
string
;
host
:
string
;
...
@@ -13,6 +14,7 @@ export interface Config {
...
@@ -13,6 +14,7 @@ export interface Config {
s3
?:
S3Assets
.
Config
;
s3
?:
S3Assets
.
Config
;
jwt
:
JwtModuleOptions
;
jwt
:
JwtModuleOptions
;
centerAccount
:
string
;
centerAccount
:
string
;
es
:
ClientOptions
;
}
}
const
defaultConfig
:
Config
=
{
const
defaultConfig
:
Config
=
{
...
@@ -26,6 +28,9 @@ const defaultConfig: Config = {
...
@@ -26,6 +28,9 @@ const defaultConfig: Config = {
},
},
},
},
centerAccount
:
'
1111111111
'
,
centerAccount
:
'
1111111111
'
,
es
:
{
node
:
'
http://localhost:9200
'
,
},
};
};
export
async
function
loadConfig
():
Promise
<
Config
>
{
export
async
function
loadConfig
():
Promise
<
Config
>
{
...
...
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