Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-pics
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-plugin-pics
Commits
bcea2e6b
Commit
bcea2e6b
authored
Apr 21, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more
parent
3bd1026f
Pipeline
#11805
failed with stage
in 19 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
6 deletions
+11
-6
CONTRIBUTING.md
CONTRIBUTING.md
+6
-1
src/index.ts
src/index.ts
+5
-5
No files found.
CONTRIBUTING.md
View file @
bcea2e6b
...
...
@@ -200,11 +200,16 @@ export class PicSourceConfig {
和图源类似,图像中间件是
`koishi-plugin-pics`
的另一类附属插件,可以对图源获取的随机 URL 在发送给用户之前进行一定的变换。
### 图像中间件系统
图像中间件系统使用洋葱模型的方式进行处理。每一层处理的过程中,可以使用
`next(url?: string)`
函数进行后续的操作,并得到后续结果的返回值,再进行进一步的处理。
`next`
函数中的
`url`
参数可以对进行后续操作的初始 URL 值进行控制。若不填写,则与本中间件的传入 URL 值相同。
### 开发图像中间件插件
图像中间件插件需要使用
[
koishi-thirdeye
](
https://koishi.js.org/about/decorator
)
进行开发。请在开发之前阅读相关相关文档。推荐在
`package.json`
的
`keywords`
内写上
`required:pics`
以保证正确被 Koishi 插件市场搜索。
#### 插件基类
图源中间件插件需要继承
`PicMiddlewareBase<Config>`
类,覆盖
`use`
方法,并使用
`@DefinePlugin({ schema: Config })`
进行注解。
...
...
src/index.ts
View file @
bcea2e6b
...
...
@@ -245,20 +245,20 @@ export default class PicsContainer
return
this
.
bufferToUrl
(
buffer
);
}
async
resolveUrl
(
url
:
string
,
middlwares
=
this
.
picMiddlewares
)
{
if
(
!
middlwares
.
length
)
{
async
resolveUrl
(
url
:
string
,
middl
e
wares
=
this
.
picMiddlewares
)
{
if
(
!
middl
e
wares
.
length
)
{
return
url
;
}
const
next
:
PicNext
=
async
(
nextUrl
)
=>
{
nextUrl
||=
url
;
const
nextResult
=
await
this
.
resolveUrl
(
nextUrl
,
middlwares
.
slice
(
1
));
const
nextResult
=
await
this
.
resolveUrl
(
nextUrl
,
middl
e
wares
.
slice
(
1
));
return
nextResult
||
nextUrl
;
};
try
{
let
result
=
await
middlwares
[
0
].
use
(
url
,
next
);
let
result
=
await
middl
e
wares
[
0
].
use
(
url
,
next
);
if
(
!
result
)
{
this
.
logger
.
warn
(
`Got empty result from middleware
${
middlwares
[
0
].
name
||
'
???
'
}
`
,
`Got empty result from middleware
${
middl
e
wares
[
0
].
name
||
'
???
'
}
`
,
);
result
=
url
;
}
...
...
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