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
55474879
Commit
55474879
authored
Apr 20, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some fixes
parent
67646c15
Pipeline
#11793
canceled with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
17 deletions
+27
-17
src/config.ts
src/config.ts
+12
-10
src/index.ts
src/index.ts
+15
-4
src/middlewares/download.ts
src/middlewares/download.ts
+0
-3
No files found.
src/config.ts
View file @
55474879
// import 'source-map-support/register';
import
{
DefineSchema
,
RegisterSchema
,
SchemaClass
}
from
'
koishi-thirdeye
'
;
import
{
SchemaProperty
,
RegisterSchema
,
SchemaClass
}
from
'
koishi-thirdeye
'
;
import
{
Quester
}
from
'
koishi
'
;
import
{
PicMiddleware
}
from
'
./index
'
;
@
RegisterSchema
()
export
class
PicsPluginConfig
{
constructor
(
config
:
Partial
<
PicsPluginConfig
>
)
{}
@
DefineSchema
({
description
:
'
指令名
'
,
default
:
'
pic
'
,
hidden
:
true
})
@
SchemaProperty
({
description
:
'
指令名
'
,
default
:
'
pic
'
,
hidden
:
true
})
commandName
:
string
;
@
DefineSchema
({
@
SchemaProperty
({
description
:
'
Assets 服务可用时,使用 Assets 缓存图片。
'
,
default
:
true
,
})
useAssets
:
boolean
;
@
DefineSchema
({
description
:
'
使用 Base64 发送图片结果。
'
,
default
:
false
})
@
SchemaProperty
({
description
:
'
使用 Base64 发送图片结果。
'
,
default
:
false
})
useBase64
:
boolean
;
@
DefineSchema
({
type
:
Quester
.
createSchema
(),
default
:
{}
})
@
SchemaProperty
({
type
:
Quester
.
createSchema
(),
default
:
{}
})
httpConfig
:
Quester
.
Config
;
}
...
...
@@ -37,15 +37,15 @@ export interface PicSourceInfo {
export
class
PicSourceConfig
implements
PicSourceInfo
{
constructor
(
config
:
Partial
<
PicSourceInfo
>
)
{}
@
DefineSchema
({
type
:
'
string
'
,
default
:
[],
description
:
'
图源标签
'
})
@
SchemaProperty
({
type
:
'
string
'
,
default
:
[],
description
:
'
图源标签
'
})
tags
:
string
[];
@
DefineSchema
({
default
:
1
,
description
:
'
图源权重
'
})
@
SchemaProperty
({
default
:
1
,
description
:
'
图源权重
'
})
weight
:
number
;
@
DefineSchema
({
default
:
1
,
description
:
'
图源名称
'
,
required
:
true
})
@
SchemaProperty
({
default
:
1
,
description
:
'
图源名称
'
,
required
:
true
})
name
:
string
;
@
DefineSchema
({
description
:
'
图源描述
'
})
@
SchemaProperty
({
description
:
'
图源描述
'
})
description
?:
string
;
@
DefineSchema
({
description
:
'
是否为默认图源
'
})
@
SchemaProperty
({
description
:
'
是否为默认图源
'
})
isDefault
?:
boolean
;
// 给目标对象注入上述对象。
...
...
@@ -67,7 +67,9 @@ export interface PicMiddlewareInfo {
export
class
PicMiddlewareConfig
{
constructor
(
config
:
PicMiddlewareInfo
)
{}
@
SchemaProperty
({
description
:
'
中间件名称。
'
})
name
:
string
;
@
SchemaProperty
({
description
:
'
是否在首位插入中间件。
'
,
default
:
false
})
prepend
:
boolean
;
applyTo
(
target
:
PicMiddleware
)
{
...
...
src/index.ts
View file @
55474879
...
...
@@ -223,15 +223,26 @@ export default class PicsContainer
);
}
async
download
(
url
:
string
,
extraConfig
:
AxiosRequestConfig
=
{})
{
async
urlToBuffer
(
url
:
string
,
extraConfig
:
AxiosRequestConfig
=
{})
{
if
(
url
.
startsWith
(
'
base64://
'
))
{
return
url
;
return
Buffer
.
from
(
url
.
slice
(
9
),
'
base64
'
)
;
}
const
buf
=
await
this
.
_http
.
get
(
url
,
{
return
this
.
_http
.
get
<
Buffer
>
(
url
,
{
responseType
:
'
arraybuffer
'
,
...
extraConfig
,
});
return
`base64://
${
buf
.
toString
(
'
base64
'
)}
`
;
}
bufferToUrl
(
buffer
:
Buffer
)
{
return
`base64://
${
buffer
.
toString
(
'
base64
'
)}
`
;
}
async
download
(
url
:
string
,
extraConfig
:
AxiosRequestConfig
=
{})
{
if
(
url
.
startsWith
(
'
base64://
'
))
{
return
url
;
}
const
buffer
=
await
this
.
urlToBuffer
(
url
,
extraConfig
);
return
this
.
bufferToUrl
(
buffer
);
}
async
resolveUrl
(
url
:
string
,
middlwares
=
this
.
picMiddlewares
)
{
...
...
src/middlewares/download.ts
View file @
55474879
...
...
@@ -5,9 +5,6 @@ import { PicMiddlewareConfig } from '../config';
@
DefinePlugin
({
schema
:
PicMiddlewareConfig
})
export
class
PicDownloaderMiddleware
extends
PicMiddlewareBase
{
override
async
use
(
url
:
string
,
next
:
PicNext
)
{
if
(
url
.
startsWith
(
'
base64://
'
))
{
return
next
();
}
const
downloadedUrl
=
await
this
.
pics
.
download
(
url
);
return
next
(
downloadedUrl
);
}
...
...
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