koishi-plugin-chatluna-storage-service 0.0.3 → 0.0.4
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.cjs +2 -29
- package/lib/index.d.ts +0 -1
- package/lib/index.mjs +2 -29
- package/lib/utils.d.ts +0 -1
- package/package.json +2 -4
package/lib/index.cjs
CHANGED
|
@@ -90,22 +90,6 @@ __name(plugins, "plugins");
|
|
|
90
90
|
var import_koishi = require("koishi");
|
|
91
91
|
|
|
92
92
|
// src/utils.ts
|
|
93
|
-
var import_image_tiny = __toESM(require("@mxsir/image-tiny"), 1);
|
|
94
|
-
async function compressImage(buffer, filename, quality) {
|
|
95
|
-
const image = bufferToFile(buffer, filename);
|
|
96
|
-
const compressedImage = await (0, import_image_tiny.default)(image, quality);
|
|
97
|
-
return await compressedImage.arrayBuffer();
|
|
98
|
-
}
|
|
99
|
-
__name(compressImage, "compressImage");
|
|
100
|
-
function bufferToFile(buffer, filename) {
|
|
101
|
-
const imageType = getImageType(buffer);
|
|
102
|
-
const fileNameWithoutExtension = filename.split(".")[0];
|
|
103
|
-
filename = fileNameWithoutExtension + "." + imageType;
|
|
104
|
-
return new File([buffer], filename, {
|
|
105
|
-
type: imageType
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
__name(bufferToFile, "bufferToFile");
|
|
109
93
|
function getImageType(buffer, pure = false, checkIsImage = false) {
|
|
110
94
|
const first10Bytes = new Uint8Array(buffer).slice(0, 10);
|
|
111
95
|
const type = Buffer.from(first10Bytes).toString("base64", 0, 10);
|
|
@@ -306,15 +290,7 @@ var ChatLunaStorageService = class extends import_koishi.Service {
|
|
|
306
290
|
}
|
|
307
291
|
async createTempFile(buffer, filename, expireHours) {
|
|
308
292
|
const isImage = getImageType(buffer, false, true) !== "unknown";
|
|
309
|
-
|
|
310
|
-
if (isImage && this.config.imageCompression < 80) {
|
|
311
|
-
const compressedImageBuffer = await compressImage(
|
|
312
|
-
buffer,
|
|
313
|
-
filename,
|
|
314
|
-
this.config.imageCompression
|
|
315
|
-
);
|
|
316
|
-
processedBuffer = Buffer.from(compressedImageBuffer);
|
|
317
|
-
}
|
|
293
|
+
const processedBuffer = buffer;
|
|
318
294
|
const randomName = randomFileName(filename);
|
|
319
295
|
const filePath = (0, import_path.join)(this.config.storagePath, "temp", randomName);
|
|
320
296
|
const fileType = isImage ? getImageType(buffer, false, false) : void 0;
|
|
@@ -399,10 +375,7 @@ var Config3 = import_koishi2.Schema.intersect([
|
|
|
399
375
|
tempCacheTime: import_koishi2.Schema.number().description("过期数据的缓存时间(小时)").default(24 * 30),
|
|
400
376
|
maxStorageSize: import_koishi2.Schema.number().description("最大存储空间(MB)").default(500).min(1),
|
|
401
377
|
maxStorageCount: import_koishi2.Schema.number().description("最大存储文件数").default(300).min(1)
|
|
402
|
-
}).description("基础配置")
|
|
403
|
-
import_koishi2.Schema.object({
|
|
404
|
-
imageCompression: import_koishi2.Schema.number().description("图片压缩的百分比,超过 80 以后将不会压缩图片").default(80).min(10).max(100)
|
|
405
|
-
}).description("附加配置")
|
|
378
|
+
}).description("基础配置")
|
|
406
379
|
]);
|
|
407
380
|
var name = "chatluna-storage-service";
|
|
408
381
|
// Annotate the CommonJS export names for ESM import in node:
|
package/lib/index.d.ts
CHANGED
package/lib/index.mjs
CHANGED
|
@@ -54,22 +54,6 @@ __name(plugins, "plugins");
|
|
|
54
54
|
import { Service, Time } from "koishi";
|
|
55
55
|
|
|
56
56
|
// src/utils.ts
|
|
57
|
-
import imageTiny from "@mxsir/image-tiny";
|
|
58
|
-
async function compressImage(buffer, filename, quality) {
|
|
59
|
-
const image = bufferToFile(buffer, filename);
|
|
60
|
-
const compressedImage = await imageTiny(image, quality);
|
|
61
|
-
return await compressedImage.arrayBuffer();
|
|
62
|
-
}
|
|
63
|
-
__name(compressImage, "compressImage");
|
|
64
|
-
function bufferToFile(buffer, filename) {
|
|
65
|
-
const imageType = getImageType(buffer);
|
|
66
|
-
const fileNameWithoutExtension = filename.split(".")[0];
|
|
67
|
-
filename = fileNameWithoutExtension + "." + imageType;
|
|
68
|
-
return new File([buffer], filename, {
|
|
69
|
-
type: imageType
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
__name(bufferToFile, "bufferToFile");
|
|
73
57
|
function getImageType(buffer, pure = false, checkIsImage = false) {
|
|
74
58
|
const first10Bytes = new Uint8Array(buffer).slice(0, 10);
|
|
75
59
|
const type = Buffer.from(first10Bytes).toString("base64", 0, 10);
|
|
@@ -270,15 +254,7 @@ var ChatLunaStorageService = class extends Service {
|
|
|
270
254
|
}
|
|
271
255
|
async createTempFile(buffer, filename, expireHours) {
|
|
272
256
|
const isImage = getImageType(buffer, false, true) !== "unknown";
|
|
273
|
-
|
|
274
|
-
if (isImage && this.config.imageCompression < 80) {
|
|
275
|
-
const compressedImageBuffer = await compressImage(
|
|
276
|
-
buffer,
|
|
277
|
-
filename,
|
|
278
|
-
this.config.imageCompression
|
|
279
|
-
);
|
|
280
|
-
processedBuffer = Buffer.from(compressedImageBuffer);
|
|
281
|
-
}
|
|
257
|
+
const processedBuffer = buffer;
|
|
282
258
|
const randomName = randomFileName(filename);
|
|
283
259
|
const filePath = join(this.config.storagePath, "temp", randomName);
|
|
284
260
|
const fileType = isImage ? getImageType(buffer, false, false) : void 0;
|
|
@@ -363,10 +339,7 @@ var Config3 = Schema.intersect([
|
|
|
363
339
|
tempCacheTime: Schema.number().description("过期数据的缓存时间(小时)").default(24 * 30),
|
|
364
340
|
maxStorageSize: Schema.number().description("最大存储空间(MB)").default(500).min(1),
|
|
365
341
|
maxStorageCount: Schema.number().description("最大存储文件数").default(300).min(1)
|
|
366
|
-
}).description("基础配置")
|
|
367
|
-
Schema.object({
|
|
368
|
-
imageCompression: Schema.number().description("图片压缩的百分比,超过 80 以后将不会压缩图片").default(80).min(10).max(100)
|
|
369
|
-
}).description("附加配置")
|
|
342
|
+
}).description("基础配置")
|
|
370
343
|
]);
|
|
371
344
|
var name = "chatluna-storage-service";
|
|
372
345
|
export {
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export declare function compressImage(buffer: Buffer, filename: string, quality: number): Promise<ArrayBuffer>;
|
|
2
1
|
export declare function getImageType(buffer: Buffer, pure?: boolean, checkIsImage?: boolean): string;
|
|
3
2
|
export declare function randomFileName(fileName: string): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-chatluna-storage-service",
|
|
3
3
|
"description": "storage service for chatluna",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
7
7
|
"module": "lib/index.mjs",
|
|
@@ -40,9 +40,7 @@
|
|
|
40
40
|
"url": "https://github.com/ChatLunaLab/storage-service/issues"
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://github.com/ChatLunaLab/storage-service#readme",
|
|
43
|
-
"dependencies": {
|
|
44
|
-
"@mxsir/image-tiny": "^0.1.0"
|
|
45
|
-
},
|
|
43
|
+
"dependencies": {},
|
|
46
44
|
"devDependencies": {
|
|
47
45
|
"@typescript-eslint/eslint-plugin": "^7.18.1-alpha.3",
|
|
48
46
|
"@typescript-eslint/parser": "^8.29.1-alpha.3",
|