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
f5d61070
Commit
f5d61070
authored
Jan 01, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve url handling
parent
bd23db52
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
526 additions
and
233 deletions
+526
-233
package-lock.json
package-lock.json
+483
-202
package.json
package.json
+7
-5
src/index.ts
src/index.ts
+36
-26
No files found.
package-lock.json
View file @
f5d61070
This diff is collapsed.
Click to expand it.
package.json
View file @
f5d61070
...
@@ -28,12 +28,14 @@
...
@@ -28,12 +28,14 @@
"homepage"
:
"
https://github.com/koishijs/koishi-plugin-pics
"
,
"homepage"
:
"
https://github.com/koishijs/koishi-plugin-pics
"
,
"dependencies"
:
{
"dependencies"
:
{
"
@koishijs/assets
"
:
"
^1.0.1
"
,
"
@koishijs/assets
"
:
"
^1.0.1
"
,
"
koishi-thirdeye
"
:
"
^11.1.17
"
,
"
ext2mime
"
:
"
^1.0.1
"
,
"
file-type
"
:
"
16.5.3
"
,
"
koishi-thirdeye
"
:
"
^11.1.20
"
,
"
lodash
"
:
"
^4.17.21
"
"
lodash
"
:
"
^4.17.21
"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"
@koishijs/plugin-console
"
:
"
^5.0.
0
"
,
"
@koishijs/plugin-console
"
:
"
^5.0.
2
"
,
"
@koishijs/plugin-database-memory
"
:
"
^2.
0.1
"
,
"
@koishijs/plugin-database-memory
"
:
"
^2.
2.0
"
,
"
@koishijs/plugin-sandbox
"
:
"
^2.5.0
"
,
"
@koishijs/plugin-sandbox
"
:
"
^2.5.0
"
,
"
@types/jest
"
:
"
^29.2.0
"
,
"
@types/jest
"
:
"
^29.2.0
"
,
"
@types/lodash
"
:
"
^4.14.176
"
,
"
@types/lodash
"
:
"
^4.14.176
"
,
...
@@ -51,13 +53,13 @@
...
@@ -51,13 +53,13 @@
"
ts-jest
"
:
"
^29.0.3
"
,
"
ts-jest
"
:
"
^29.0.3
"
,
"
ts-loader
"
:
"
^9.3.1
"
,
"
ts-loader
"
:
"
^9.3.1
"
,
"
ts-node
"
:
"
^10.9.1
"
,
"
ts-node
"
:
"
^10.9.1
"
,
"
typescript
"
:
"
^4.
8
.4
"
,
"
typescript
"
:
"
^4.
9
.4
"
,
"
webpack
"
:
"
^5.74.0
"
,
"
webpack
"
:
"
^5.74.0
"
,
"
webpack-cli
"
:
"
^4.10.0
"
,
"
webpack-cli
"
:
"
^4.10.0
"
,
"
ws
"
:
"
^8.3.0
"
"
ws
"
:
"
^8.3.0
"
},
},
"peerDependencies"
:
{
"peerDependencies"
:
{
"koishi"
:
"^4.1
0.1
0"
"koishi"
:
"^4.1
1.
0"
},
},
"jest"
:
{
"jest"
:
{
"moduleFileExtensions"
:
[
"moduleFileExtensions"
:
[
...
...
src/index.ts
View file @
f5d61070
// import 'source-map-support/register';
// import 'source-map-support/register';
import
{
Context
,
Random
,
Logger
,
Bot
,
remove
,
Session
,
Dict
}
from
'
koishi
'
;
import
{
Context
,
Random
,
Logger
,
remove
,
Session
,
Dict
}
from
'
koishi
'
;
import
{
PicsPluginConfig
}
from
'
./config
'
;
import
{
PicsPluginConfig
}
from
'
./config
'
;
import
_
from
'
lodash
'
;
import
_
from
'
lodash
'
;
import
{
segment
,
Quester
,
Element
}
from
'
koishi
'
;
import
{
segment
,
Quester
,
Element
}
from
'
koishi
'
;
...
@@ -20,11 +20,14 @@ import {
...
@@ -20,11 +20,14 @@ import {
UseCommand
,
UseCommand
,
UseComponent
,
UseComponent
,
}
from
'
koishi-thirdeye
'
;
}
from
'
koishi-thirdeye
'
;
import
{
AxiosRequestConfig
}
from
'
axios
'
;
import
{
PicAssetsTransformMiddleware
}
from
'
./middlewares/assets
'
;
import
{
PicAssetsTransformMiddleware
}
from
'
./middlewares/assets
'
;
import
{
PicDownloaderMiddleware
}
from
'
./middlewares/download
'
;
import
{
PicDownloaderMiddleware
}
from
'
./middlewares/download
'
;
import
{
PicMiddleware
,
PicNext
,
PicResult
}
from
'
./def
'
;
import
{
PicMiddleware
,
PicNext
,
PicResult
}
from
'
./def
'
;
import
{
PicSource
}
from
'
./picsource
'
;
import
{
PicSource
}
from
'
./picsource
'
;
import
FileType
from
'
file-type
'
;
import
path
from
'
path
'
;
import
ext2mime
from
'
ext2mime
'
;
import
*
as
fs
from
'
fs
'
;
export
*
from
'
./config
'
;
export
*
from
'
./config
'
;
export
*
from
'
./middleware
'
;
export
*
from
'
./middleware
'
;
export
*
from
'
./picsource
'
;
export
*
from
'
./picsource
'
;
...
@@ -174,38 +177,45 @@ export default class PicsContainer
...
@@ -174,38 +177,45 @@ export default class PicsContainer
return
this
.
fetchPicsWithSources
(
sources
,
picTags
);
return
this
.
fetchPicsWithSources
(
sources
,
picTags
);
}
}
isOneBotBot
(
bot
?:
Bot
)
{
async
urlToBuffer
(
url
:
string
):
Promise
<
{
buffer
:
Buffer
;
mime
:
string
}
>
{
return
(
bot
&&
(
bot
.
platform
===
'
onebot
'
||
(
bot
.
platform
===
'
qqguild
'
&&
bot
[
'
parentBot
'
]?.
platform
===
'
onebot
'
))
);
}
async
urlToBuffer
(
url
:
string
,
extraConfig
:
AxiosRequestConfig
=
{},
):
Promise
<
Buffer
>
{
if
(
url
.
startsWith
(
'
base64://
'
))
{
if
(
url
.
startsWith
(
'
base64://
'
))
{
return
Buffer
.
from
(
url
.
slice
(
9
),
'
base64
'
);
const
buf
=
Buffer
.
from
(
url
.
slice
(
9
),
'
base64
'
);
const
type
=
await
FileType
.
fromBuffer
(
buf
);
return
{
buffer
:
buf
,
mime
:
type
?.
mime
||
'
application/octet-stream
'
};
}
}
const
data
=
await
this
.
_http
.
get
<
Buffer
>
(
url
,
{
if
(
url
.
startsWith
(
'
file://
'
))
{
responseType
:
'
arraybuffer
'
,
const
filePath
=
url
.
slice
(
7
);
...
extraConfig
,
const
buf
=
await
fs
.
promises
.
readFile
(
filePath
);
});
const
mime
=
return
data
as
Buffer
;
ext2mime
(
path
.
extname
(
filePath
))
||
(
await
FileType
.
fromBuffer
(
buf
)).
mime
;
return
{
buffer
:
buf
,
mime
};
}
const
data
=
await
this
.
_http
.
file
(
url
);
return
{
buffer
:
data
.
data
as
Buffer
,
mime
:
data
.
mime
,
};
}
}
bufferToUrl
(
buffer
:
Buffer
)
{
async
bufferToUrl
(
buffer
:
Buffer
,
mime
?:
string
)
{
return
`base64://
${
buffer
.
toString
(
'
base64
'
)}
`
;
if
(
!
mime
)
{
const
result
=
await
FileType
.
fromBuffer
(
buffer
);
if
(
result
)
{
mime
=
result
.
mime
;
}
else
{
mime
=
'
application/octet-stream
'
;
}
}
return
`data:
${
mime
}
;base64,
${
buffer
.
toString
(
'
base64
'
)}
`
;
}
}
async
download
(
url
:
string
,
extraConfig
:
AxiosRequestConfig
=
{}
)
{
async
download
(
url
:
string
)
{
if
(
url
.
startsWith
(
'
base64://
'
))
{
if
(
url
.
startsWith
(
'
base64://
'
))
{
return
url
;
return
this
.
bufferToUrl
(
Buffer
.
from
(
url
.
slice
(
9
),
'
base64
'
))
;
}
}
const
buffer
=
await
this
.
urlToBuffer
(
url
,
extraConfig
);
const
data
=
await
this
.
urlToBuffer
(
url
);
return
this
.
bufferToUrl
(
buffer
);
return
this
.
bufferToUrl
(
data
.
buffer
,
data
.
mime
);
}
}
async
resolveUrl
(
url
:
string
,
middlewares
=
this
.
picMiddlewares
)
{
async
resolveUrl
(
url
:
string
,
middlewares
=
this
.
picMiddlewares
)
{
...
...
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