Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Thirdeye
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 Thirdeye
Commits
8b1b1dfc
Commit
8b1b1dfc
authored
Feb 09, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add HttpClientPlugin
parent
54b40592
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
0 deletions
+67
-0
src/plugin-operators/http-client.ts
src/plugin-operators/http-client.ts
+32
-0
src/plugin-operators/index.ts
src/plugin-operators/index.ts
+1
-0
tests/http-client.spec.ts
tests/http-client.spec.ts
+34
-0
No files found.
src/plugin-operators/http-client.ts
0 → 100644
View file @
8b1b1dfc
import
{
Quester
,
Schema
}
from
'
koishi
'
;
import
{
CreatePluginFactory
,
SchemaProperty
}
from
'
cordis-decorators
'
;
import
{
StarterPlugin
}
from
'
../registrar
'
;
import
{
Apply
}
from
'
cordis-decorators/dist/src/decorators
'
;
const
questerConfigDict
=
{
...
Quester
.
Config
.
dict
};
delete
questerConfigDict
.
endpoint
;
export
class
HttpClientPluginConfig
{
@
SchemaProperty
({
type
:
Schema
.
object
(
questerConfigDict
),
description
:
'
请求设置
'
,
default
:
{},
})
http
:
Omit
<
Quester
.
Config
,
'
endpoint
'
>
;
}
export
class
HttpClientPluginBase
extends
StarterPlugin
(
HttpClientPluginConfig
,
)
{
http
:
Quester
;
@
Apply
()
_initializeQuester
()
{
this
.
http
=
this
.
ctx
.
http
.
extend
(
this
.
config
.
http
||
{});
}
}
export
const
HttpClientPlugin
=
CreatePluginFactory
(
HttpClientPluginBase
,
HttpClientPluginConfig
,
);
src/plugin-operators/index.ts
View file @
8b1b1dfc
export
*
from
'
./map-plugin
'
;
export
*
from
'
./merge-plugin
'
;
export
*
from
'
./multi-plugin
'
;
export
*
from
'
./http-client
'
;
tests/http-client.spec.ts
0 → 100644
View file @
8b1b1dfc
import
{
Provide
}
from
'
cordis-decorators/dist/src/decorators
'
;
import
{
DefinePlugin
}
from
'
../src/decorators
'
;
import
{
HttpClientPlugin
}
from
'
../src/plugin-operators
'
;
import
{
App
}
from
'
koishi
'
;
import
{
RegisterSchema
,
SchemaProperty
}
from
'
cordis-decorators
'
;
@
RegisterSchema
()
class
TestHttpPluginConfig
{
@
SchemaProperty
({
default
:
'
https://sapi.moecube.com:444/apps.json
'
})
endpoint
:
string
;
}
@
Provide
(
'
testHttp
'
,
{
immediate
:
true
})
@
DefinePlugin
()
class
TestHttpPlugin
extends
HttpClientPlugin
(
TestHttpPluginConfig
)
{
req
()
{
return
this
.
http
.
get
(
this
.
config
.
endpoint
);
}
}
describe
(
'
register map plugin instance
'
,
()
=>
{
it
(
'
should make http ok
'
,
async
()
=>
{
const
app
=
new
App
();
app
.
plugin
(
TestHttpPlugin
,
{
http
:
{
headers
:
{
'
User-Agent
'
:
'
test
'
,
},
},
});
await
app
.
start
();
expect
(
app
[
'
testHttp
'
].
req
()).
resolves
.
toBeInstanceOf
(
Array
);
});
});
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