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
656e86c8
Commit
656e86c8
authored
Jun 06, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support picsource without thirdeye
parent
fd74849b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
16 deletions
+97
-16
dev/extras.ts
dev/extras.ts
+31
-13
src/middleware.ts
src/middleware.ts
+34
-2
src/picsource.ts
src/picsource.ts
+32
-1
No files found.
dev/extras.ts
View file @
656e86c8
import
{
Awaitable
,
Context
}
from
'
koishi
'
;
import
{
Awaitable
,
Context
,
Schema
}
from
'
koishi
'
;
import
{
DefinePlugin
,
MultiInstancePlugin
,
RegisterSchema
,
SchemaProperty
,
}
from
'
koishi-thirdeye
'
;
import
{
PicResult
,
PicSourceConfig
,
PicSourcePlugin
}
from
'
../src
'
;
import
{
PicResult
,
PicSource
,
PicSourceConfig
,
PicSourceInfo
,
PicSourcePlugin
,
PlainPicSourcePlugin
,
}
from
'
../src
'
;
@
RegisterSchema
()
class
Config
{
...
...
@@ -28,6 +35,24 @@ class TestPicSourcePlugin extends PicSourcePlugin(Config) {
}
}
const
plainBase
=
PlainPicSourcePlugin
({
name
:
Schema
.
string
().
default
(
'
zh-CN
'
),
endpoint
:
Schema
.
string
().
default
(
'
https://cdn02.moecube.com:444
'
),
});
class
TestPlainPicSourcePlugin
extends
plainBase
{
static
using
=
[
'
pics
'
]
as
const
;
static
Config
=
plainBase
.
Config
;
randomPic
(
picTags
:
string
[]):
Awaitable
<
PicResult
>
{
return
{
url
:
`
${
this
.
config
.
endpoint
}
/images/ygopro-images-
${
this
.
name
}
/
${
picTags
[
0
]
||
'
10000
'
}
.jpg`
,
description
:
picTags
[
0
]
||
'
10000
'
,
};
}
}
@
DefinePlugin
()
export
class
TestMultiPicSourcePlugin
extends
MultiInstancePlugin
(
TestPicSourcePlugin
,
...
...
@@ -35,17 +60,10 @@ export class TestMultiPicSourcePlugin extends MultiInstancePlugin(
export
default
class
ExtrasInDev
{
constructor
(
ctx
:
Context
)
{
ctx
.
plugin
(
TestMultiPicSourcePlugin
,
{
instances
:
[
{
ctx
.
plugin
(
TestPlainPicSourcePlugin
,
{
// name: 'zh-CN',
isDefault
:
true
,
endpoint
:
'
https://cdn02.moecube.com:444
'
,
},
{
name
:
'
en-US
'
,
},
],
// endpoint: 'https://cdn02.moecube.com:444',
});
}
...
...
src/middleware.ts
View file @
656e86c8
import
{
Awaitable
,
Logger
}
from
'
koishi
'
;
import
{
Awaitable
,
Context
,
Logger
,
Schema
}
from
'
koishi
'
;
import
{
PicMiddlewareConfig
}
from
'
./config
'
;
import
{
BasePlugin
,
...
...
@@ -6,8 +6,10 @@ import {
Inject
,
InjectLogger
,
LifecycleEvents
,
PartialDeep
,
schemaFromClass
,
}
from
'
koishi-thirdeye
'
;
import
PicsContainer
from
'
./index
'
;
import
PicsContainer
,
{
PicMiddlewareInfo
}
from
'
./index
'
;
import
{
PicMiddleware
,
PicNext
}
from
'
./def
'
;
export
class
BasePicMiddlewarePlugin
...
...
@@ -34,3 +36,33 @@ export const PicMiddlewarePlugin = CreatePluginFactory(
BasePicMiddlewarePlugin
,
PicMiddlewareConfig
,
);
export
function
PlainPicMiddlewarePlugin
<
C
>
(
dict
:
{
[
K
in
keyof
C
]:
Schema
<
C
[
K
]
>
;
})
{
const
Config
=
schemaFromClass
(
PicMiddlewareConfig
)
as
Schema
<
PartialDeep
<
PicMiddlewareConfig
&
C
>
,
PicMiddlewareConfig
&
C
>
;
Object
.
assign
(
Config
.
dict
,
dict
);
return
class
PlainPicMiddlewarePluginBase
implements
PicMiddleware
{
name
?:
string
;
prepend
?:
boolean
;
config
:
PicMiddlewareInfo
&
C
;
static
Config
=
Config
;
static
using
=
[
'
pics
'
]
as
const
;
constructor
(
public
ctx
:
Context
,
config
:
PartialDeep
<
C
&
PicMiddlewareInfo
>
,
)
{
this
.
config
=
config
as
PicMiddlewareInfo
&
C
;
this
.
name
=
config
.
name
;
this
.
prepend
=
config
.
prepend
;
ctx
.
pics
.
middleware
(
this
);
}
use
(
url
:
string
,
next
:
PicNext
):
Awaitable
<
string
>
{
return
next
(
url
);
}
};
}
src/picsource.ts
View file @
656e86c8
import
{
Context
,
Awaitable
,
Logger
}
from
'
koishi
'
;
import
{
Context
,
Awaitable
,
Logger
,
Schema
}
from
'
koishi
'
;
import
{
PartialDeep
,
InjectConfig
,
Inject
,
InjectLogger
,
CreatePluginFactory
,
schemaFromClass
,
}
from
'
koishi-thirdeye
'
;
import
PicsContainer
from
'
.
'
;
import
{
PicSourceConfig
}
from
'
./config
'
;
...
...
@@ -17,6 +18,15 @@ export class PicSource implements PicSourceInfo {
name
=
'
default
'
;
description
=
''
;
isDefault
=
false
;
applyConfig
(
src
:
Partial
<
PicSourceInfo
>
)
{
this
.
name
=
src
.
name
;
this
.
tags
??
=
src
.
tags
;
this
.
weight
??
=
src
.
weight
;
this
.
description
??
=
src
.
description
;
this
.
isDefault
??
=
src
.
isDefault
;
}
randomPic
(
picTags
:
string
[]):
Awaitable
<
PicResult
>
{
// For override
throw
new
Error
(
`Not implemented`
);
...
...
@@ -64,3 +74,24 @@ export const PicSourcePlugin = CreatePluginFactory(
BasePicSourcePlugin
,
PicSourceConfig
,
);
export
function
PlainPicSourcePlugin
<
C
>
(
dict
:
{
[
K
in
keyof
C
]:
Schema
<
C
[
K
]
>
;
})
{
const
Config
=
schemaFromClass
(
PicSourceConfig
)
as
Schema
<
PartialDeep
<
PicSourceConfig
&
C
>
,
PicSourceConfig
&
C
>
;
Object
.
assign
(
Config
.
dict
,
dict
);
return
class
PlainPicSourcePluginBase
extends
PicSource
{
config
:
PicSourceInfo
&
C
;
constructor
(
ctx
:
Context
,
config
:
PartialDeep
<
C
&
PicSourceInfo
>
)
{
super
(
ctx
);
this
.
config
=
config
as
PicSourceInfo
&
C
;
this
.
applyConfig
(
config
);
ctx
.
pics
.
addSource
(
this
);
}
static
Config
=
Config
;
static
using
=
[
'
pics
'
]
as
const
;
};
}
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