Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Nestjs
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
3rdeye
Koishi Nestjs
Commits
b0e3c29b
Commit
b0e3c29b
authored
Oct 31, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix command in service
parent
e37410c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
+25
-2
README.md
README.md
+4
-0
src/koishi.service.ts
src/koishi.service.ts
+21
-2
No files found.
README.md
View file @
b0e3c29b
...
...
@@ -549,6 +549,10 @@ export class AppModule {}
## 更新历史
### 1.5
*
增加了指令拦截器。
### 1.4.2
*
`KoishiWsAdapter`
: 支持正则表达式路径。
...
...
src/koishi.service.ts
View file @
b0e3c29b
import
{
App
,
Command
,
Context
,
Router
}
from
'
koishi
'
;
import
{
App
,
Argv
,
Command
,
Context
,
Router
}
from
'
koishi
'
;
import
{
Inject
,
Injectable
,
...
...
@@ -24,6 +24,7 @@ import { Filter, ReplacedContext } from './utility/replaced-context';
export
class
KoishiService
extends
App
implements
OnModuleInit
,
OnApplicationBootstrap
,
OnModuleDestroy
{
private
globalInterceptors
:
KoishiCommandInterceptorRegistration
[];
constructor
(
@
Inject
(
KOISHI_MODULE_OPTIONS
)
private
readonly
koishiModuleOptions
:
KoishiModuleOptions
,
...
...
@@ -35,6 +36,7 @@ export class KoishiService
...
koishiModuleOptions
,
port
:
0
,
});
this
.
globalInterceptors
=
this
.
globalInterceptors
;
this
.
router
=
new
Router
();
this
.
_nestKoaTmpInstance
.
use
(
KoaBodyParser
());
this
.
_nestKoaTmpInstance
.
use
(
this
.
router
.
routes
());
...
...
@@ -88,7 +90,7 @@ export class KoishiService
interceptors
:
KoishiCommandInterceptorRegistration
[]
=
[],
):
Context
{
return
new
ReplacedContext
(
filter
,
this
,
null
,
[
...
(
this
.
koishiModuleOptions
.
globalInterceptors
||
[])
,
...
this
.
globalInterceptors
,
...
interceptors
,
]);
}
...
...
@@ -119,4 +121,21 @@ export class KoishiService
const
filter
=
typeof
arg
===
'
function
'
?
arg
:
arg
.
filter
;
return
this
.
cloneContext
((
s
)
=>
this
.
filter
(
s
)
&&
!
filter
(
s
));
}
command
<
D
extends
string
>
(
def
:
D
,
config
?:
Command
.
Config
,
):
Command
<
never
,
never
,
Argv
.
ArgumentType
<
D
>>
;
command
<
D
extends
string
>
(
def
:
D
,
desc
:
string
,
config
?:
Command
.
Config
,
):
Command
<
never
,
never
,
Argv
.
ArgumentType
<
D
>>
;
command
(
def
:
string
,
...
args
:
[
Command
.
Config
?]
|
[
string
,
Command
.
Config
?])
{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const
cmd
=
super
.
command
(
def
,
...
args
);
this
.
addInterceptors
(
cmd
,
this
.
globalInterceptors
);
return
cmd
;
}
}
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