koishi-plugin-assets-copyparty 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +27 -0
- package/lib/index.js +133 -0
- package/package.json +51 -0
- package/readme.md +5 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Context, HTTP, Schema } from 'koishi';
|
|
2
|
+
import Assets from '@koishijs/assets';
|
|
3
|
+
export declare const name = "assets-copyparty";
|
|
4
|
+
declare class CopypartyAssets extends Assets<CopypartyAssets.Config> {
|
|
5
|
+
types: string[];
|
|
6
|
+
http: HTTP;
|
|
7
|
+
constructor(ctx: Context, config: CopypartyAssets.Config);
|
|
8
|
+
private logInfo;
|
|
9
|
+
upload(url: string, file: string): Promise<any>;
|
|
10
|
+
stats(): Promise<{}>;
|
|
11
|
+
}
|
|
12
|
+
declare namespace CopypartyAssets {
|
|
13
|
+
interface Config extends Assets.Config {
|
|
14
|
+
endpoint: string;
|
|
15
|
+
bin: string;
|
|
16
|
+
password: string;
|
|
17
|
+
replace: string;
|
|
18
|
+
loggerinfo: boolean;
|
|
19
|
+
}
|
|
20
|
+
const Config: Schema<Config>;
|
|
21
|
+
const usage = "\n ---\n \n \u8981\u4F7F\u7528\u672C\u63D2\u4EF6\u63D0\u4F9B\u7684 assets \u670D\u52A1\uFF0C\u4F60\u9700\u8981\u5148\u5173\u95ED\u9ED8\u8BA4\u5F00\u542F\u7684 assets-local \u63D2\u4EF6\uFF0C\u7136\u540E\u5F00\u542F\u672C\u63D2\u4EF6\u3002\n\n ---\n\n \u672C\u63D2\u4EF6\u4F7F\u7528 copyparty \u5B9E\u73B0\u670D\u52A1\uFF0C\u652F\u6301\u56FE\u7247\u3001\u97F3\u9891\u3001\u89C6\u9891\u548C\u5176\u4ED6\u6587\u4EF6\u7684\u4E0A\u4F20\u548C\u5B58\u50A8\u3002\n\n ---\n\n \u672C\u63D2\u4EF6\u540E\u7AEF\u670D\u52A1\u6765\u81EA: <a href=\"https://filebin.net\" target=\"_blank\">https://filebin.net</a>\n\n --- \n ";
|
|
22
|
+
}
|
|
23
|
+
export interface Config extends CopypartyAssets.Config {
|
|
24
|
+
}
|
|
25
|
+
export declare const Config: Schema<CopypartyAssets.Config>;
|
|
26
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
27
|
+
export default CopypartyAssets;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Config: () => Config,
|
|
34
|
+
apply: () => apply,
|
|
35
|
+
default: () => src_default,
|
|
36
|
+
name: () => name
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(src_exports);
|
|
39
|
+
var import_koishi = require("koishi");
|
|
40
|
+
var import_assets = __toESM(require("@koishijs/assets"));
|
|
41
|
+
var name = "assets-copyparty";
|
|
42
|
+
var CopypartyAssets = class extends import_assets.default {
|
|
43
|
+
static {
|
|
44
|
+
__name(this, "CopypartyAssets");
|
|
45
|
+
}
|
|
46
|
+
types = ["image", "img", "audio", "video", "file"];
|
|
47
|
+
// 支持所有类型
|
|
48
|
+
http;
|
|
49
|
+
constructor(ctx, config) {
|
|
50
|
+
super(ctx, config);
|
|
51
|
+
this.http = ctx.http.extend({
|
|
52
|
+
headers: { accept: "application/json" }
|
|
53
|
+
});
|
|
54
|
+
this.logInfo(`初始化完成 - 基础地址: ${config.endpoint}, 上传地址: ${config.bin}`);
|
|
55
|
+
}
|
|
56
|
+
logInfo(...args) {
|
|
57
|
+
if (this.config.loggerinfo) {
|
|
58
|
+
const logger = this.ctx.logger("assets-copyparty");
|
|
59
|
+
logger.info(...args);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async upload(url, file) {
|
|
63
|
+
const { buffer, filename, type } = await this.analyze(url, file);
|
|
64
|
+
const logger = this.ctx.logger("assets-copyparty");
|
|
65
|
+
try {
|
|
66
|
+
const uploadUrl = `${this.config.endpoint}/${this.config.bin}/${filename}`;
|
|
67
|
+
this.logInfo(`开始上传文件: ${filename}, 类型: ${type}, 目标URL: ${uploadUrl}`);
|
|
68
|
+
const response = await this.http.put(uploadUrl, buffer, {
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "application/octet-stream",
|
|
71
|
+
// 'Accept': 'url',
|
|
72
|
+
"CK": "no",
|
|
73
|
+
// thank you.
|
|
74
|
+
"PW": this.config.password
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
this.logInfo(`文件上传完成,获取访问链接...`);
|
|
78
|
+
var finalUrl = response.fileurl;
|
|
79
|
+
this.logInfo(`上传成功: ${finalUrl}`);
|
|
80
|
+
if (this.config.replace != null) {
|
|
81
|
+
finalUrl = finalUrl.replace(this.config.endpoint, this.config.replace);
|
|
82
|
+
this.logInfo(`replace: ${finalUrl}`);
|
|
83
|
+
}
|
|
84
|
+
return finalUrl;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
87
|
+
logger.error(`上传失败: ${err.message}`);
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async stats() {
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
((CopypartyAssets2) => {
|
|
96
|
+
CopypartyAssets2.Config = import_koishi.Schema.intersect([
|
|
97
|
+
import_koishi.Schema.object({
|
|
98
|
+
endpoint: import_koishi.Schema.string().role("link").description("copyparty 服务地址").required(),
|
|
99
|
+
bin: import_koishi.Schema.string().description("上传至文件夹").required(),
|
|
100
|
+
password: import_koishi.Schema.string().description("copyparty 密码(可不填)").experimental(),
|
|
101
|
+
replace: import_koishi.Schema.string().description("endpoint replace").hidden(),
|
|
102
|
+
loggerinfo: import_koishi.Schema.boolean().default(false).description("日志调试:一般输出<br>提issue时,请开启此功能 并且提供BUG复现日志").experimental()
|
|
103
|
+
}),
|
|
104
|
+
import_assets.default.Config
|
|
105
|
+
]);
|
|
106
|
+
CopypartyAssets2.usage = `
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
要使用本插件提供的 assets 服务,你需要先关闭默认开启的 assets-local 插件,然后开启本插件。
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
本插件使用 copyparty 实现服务,支持图片、音频、视频和其他文件的上传和存储。
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
本插件后端服务来自: <a href="https://filebin.net" target="_blank">https://filebin.net</a>
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
`;
|
|
121
|
+
})(CopypartyAssets || (CopypartyAssets = {}));
|
|
122
|
+
var Config = CopypartyAssets.Config;
|
|
123
|
+
function apply(ctx, config) {
|
|
124
|
+
ctx.plugin(CopypartyAssets, config);
|
|
125
|
+
}
|
|
126
|
+
__name(apply, "apply");
|
|
127
|
+
var src_default = CopypartyAssets;
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
Config,
|
|
131
|
+
apply,
|
|
132
|
+
name
|
|
133
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-assets-copyparty",
|
|
3
|
+
"description": "基于 copyparty 的资源转存服务",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"author": "ajchen",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"homepage": "https://github.com/ajchen02/assets-copyparty",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/ajchen02/assets-copyparty"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"bot",
|
|
20
|
+
"chatbot",
|
|
21
|
+
"koishi",
|
|
22
|
+
"plugin",
|
|
23
|
+
"assets",
|
|
24
|
+
"server",
|
|
25
|
+
"local",
|
|
26
|
+
"storage"
|
|
27
|
+
],
|
|
28
|
+
"koishi": {
|
|
29
|
+
"category": "storage",
|
|
30
|
+
"description": {
|
|
31
|
+
"en": "copyparty assets service",
|
|
32
|
+
"zh": "使用 copyparty 的存放资源文件"
|
|
33
|
+
},
|
|
34
|
+
"service": {
|
|
35
|
+
"implements": [
|
|
36
|
+
"assets"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"koishi": "^4.18.7"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@koishijs/plugin-server": "^3.2.3",
|
|
45
|
+
"koishi": "^4.17.7"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@koishijs/assets": "^1.1.2",
|
|
49
|
+
"file-type": "^16.5.4"
|
|
50
|
+
}
|
|
51
|
+
}
|