@wahaha216/koishi-plugin-jmcomic 0.2.1 → 0.2.3
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.js +23 -13
- package/package.json +1 -1
- package/readme.md +15 -0
package/lib/index.js
CHANGED
|
@@ -135,10 +135,14 @@ function fileSizeAsync(path) {
|
|
|
135
135
|
}
|
|
136
136
|
__name(fileSizeAsync, "fileSizeAsync");
|
|
137
137
|
function sanitizeFileName(fileName) {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
const forbiddenAndShellSpecialChars = /[<>:"/\\|?*()[\]{}!#$&;'`~]/g;
|
|
139
|
+
let sanitizedFileName = fileName.replace(forbiddenAndShellSpecialChars, "_");
|
|
140
|
+
sanitizedFileName = sanitizedFileName.replace(/\s+/g, "_");
|
|
141
|
+
sanitizedFileName = sanitizedFileName.replace(/_+/g, "_");
|
|
142
|
+
sanitizedFileName = sanitizedFileName.replace(/^[._]+|[._]+$/g, "");
|
|
143
|
+
if (sanitizedFileName.trim() === "") {
|
|
144
|
+
return "untitled_document";
|
|
145
|
+
}
|
|
142
146
|
return fileName;
|
|
143
147
|
}
|
|
144
148
|
__name(sanitizeFileName, "sanitizeFileName");
|
|
@@ -652,6 +656,10 @@ async function decodeImage(imageBuffer, num, path) {
|
|
|
652
656
|
const metadata = await (0, import_sharp.default)(Buffer.from(imageBuffer)).metadata();
|
|
653
657
|
const height = metadata.height || 0;
|
|
654
658
|
const width = metadata.width || 0;
|
|
659
|
+
if (height < num) {
|
|
660
|
+
await (0, import_sharp.default)(Buffer.from(imageBuffer)).toFile(path);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
655
663
|
const over = height % num;
|
|
656
664
|
const move = Math.floor(height / num);
|
|
657
665
|
let decodedImageInstance = (0, import_sharp.default)({
|
|
@@ -1037,34 +1045,36 @@ var JMAppClient = class _JMAppClient extends JMClientAbstract {
|
|
|
1037
1045
|
const id = album.getId();
|
|
1038
1046
|
const series = album.getSeries();
|
|
1039
1047
|
const zipName = sanitizeFileName(album.getName());
|
|
1040
|
-
const path =
|
|
1048
|
+
const path = (0, import_path2.join)(this.root, "album", `${id}`);
|
|
1041
1049
|
const directorys = [];
|
|
1042
1050
|
if (series.length > 1) {
|
|
1043
1051
|
for (const s of series) {
|
|
1044
1052
|
directorys.push({
|
|
1045
|
-
directory:
|
|
1053
|
+
directory: (0, import_path2.join)(path, "decoded", s.id),
|
|
1046
1054
|
destpath: `第${s.sort}章`
|
|
1047
1055
|
});
|
|
1048
1056
|
}
|
|
1049
1057
|
} else {
|
|
1050
|
-
directorys.push({ directory:
|
|
1058
|
+
directorys.push({ directory: (0, import_path2.join)(path, "decoded"), destpath: false });
|
|
1051
1059
|
}
|
|
1052
|
-
|
|
1060
|
+
const zipPath = (0, import_path2.join)(path, `${zipName}.zip`);
|
|
1061
|
+
await archiverImage(directorys, zipPath, password, level);
|
|
1053
1062
|
if (this.config.debug) this.logger.info(`ZIP ${zipName}.zip 生成完成`);
|
|
1054
|
-
return
|
|
1063
|
+
return zipPath;
|
|
1055
1064
|
}
|
|
1056
1065
|
async photoToZip(photo, zipName, password, level = 6) {
|
|
1057
1066
|
const id = photo.getId();
|
|
1058
1067
|
zipName = sanitizeFileName(zipName);
|
|
1059
|
-
const path =
|
|
1068
|
+
const path = (0, import_path2.join)(this.root, "photo", `${id}`);
|
|
1069
|
+
const zipPath = (0, import_path2.join)(path, `${zipName}.zip`);
|
|
1060
1070
|
await archiverImage(
|
|
1061
|
-
[{ directory:
|
|
1062
|
-
|
|
1071
|
+
[{ directory: (0, import_path2.join)(path, "decoded"), destpath: false }],
|
|
1072
|
+
zipPath,
|
|
1063
1073
|
password,
|
|
1064
1074
|
level
|
|
1065
1075
|
);
|
|
1066
1076
|
if (this.config.debug) this.logger.info(`ZIP ${zipName}.zip 生成完成`);
|
|
1067
|
-
return
|
|
1077
|
+
return zipPath;
|
|
1068
1078
|
}
|
|
1069
1079
|
/**
|
|
1070
1080
|
* 获取时间戳
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -17,6 +17,21 @@ jm queue
|
|
|
17
17
|
|
|
18
18
|
## 更新日志
|
|
19
19
|
|
|
20
|
+
<details>
|
|
21
|
+
<summary>0.2.3</summary>
|
|
22
|
+
|
|
23
|
+
1. 将手动路径拼接替换为join
|
|
24
|
+
2. 健壮文件名序列化,尝试修复部分文件名导致无法创建文件
|
|
25
|
+
|
|
26
|
+
</details>
|
|
27
|
+
|
|
28
|
+
<details>
|
|
29
|
+
<summary>0.2.2</summary>
|
|
30
|
+
|
|
31
|
+
高度不足图片分割数时输出原图,尝试规避提取图片高度为0的情况
|
|
32
|
+
|
|
33
|
+
</details>
|
|
34
|
+
|
|
20
35
|
<details>
|
|
21
36
|
<summary>0.2.1</summary>
|
|
22
37
|
|