@wahaha216/koishi-plugin-jmcomic 0.2.2 → 0.2.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.js +23 -15
- package/package.json +1 -1
- package/readme.md +16 -0
package/lib/index.js
CHANGED
|
@@ -135,11 +135,15 @@ function fileSizeAsync(path) {
|
|
|
135
135
|
}
|
|
136
136
|
__name(fileSizeAsync, "fileSizeAsync");
|
|
137
137
|
function sanitizeFileName(fileName) {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
}
|
|
146
|
+
return sanitizedFileName;
|
|
143
147
|
}
|
|
144
148
|
__name(sanitizeFileName, "sanitizeFileName");
|
|
145
149
|
async function limitPromiseAll(promises, limit) {
|
|
@@ -988,8 +992,8 @@ var JMAppClient = class _JMAppClient extends JMClientAbstract {
|
|
|
988
992
|
async photoToPdf(photo, pdfName, type = "photo", albumId = "", single = false, password) {
|
|
989
993
|
const images = photo.getImages();
|
|
990
994
|
const id = photo.getId();
|
|
991
|
-
if (this.config.debug) this.logger.info(`开始生成PDF ${pdfName}.pdf`);
|
|
992
995
|
pdfName = sanitizeFileName(pdfName);
|
|
996
|
+
if (this.config.debug) this.logger.info(`开始生成PDF ${pdfName}.pdf`);
|
|
993
997
|
let path = (0, import_path2.join)(this.root, type, `${id}`);
|
|
994
998
|
if (type === "album") {
|
|
995
999
|
path = (0, import_path2.join)(this.root, type, `${albumId}`);
|
|
@@ -1041,34 +1045,38 @@ var JMAppClient = class _JMAppClient extends JMClientAbstract {
|
|
|
1041
1045
|
const id = album.getId();
|
|
1042
1046
|
const series = album.getSeries();
|
|
1043
1047
|
const zipName = sanitizeFileName(album.getName());
|
|
1044
|
-
|
|
1048
|
+
if (this.config.debug) this.logger.info(`开始生成ZIP ${zipName}.zip`);
|
|
1049
|
+
const path = (0, import_path2.join)(this.root, "album", `${id}`);
|
|
1045
1050
|
const directorys = [];
|
|
1046
1051
|
if (series.length > 1) {
|
|
1047
1052
|
for (const s of series) {
|
|
1048
1053
|
directorys.push({
|
|
1049
|
-
directory:
|
|
1054
|
+
directory: (0, import_path2.join)(path, "decoded", s.id),
|
|
1050
1055
|
destpath: `第${s.sort}章`
|
|
1051
1056
|
});
|
|
1052
1057
|
}
|
|
1053
1058
|
} else {
|
|
1054
|
-
directorys.push({ directory:
|
|
1059
|
+
directorys.push({ directory: (0, import_path2.join)(path, "decoded"), destpath: false });
|
|
1055
1060
|
}
|
|
1056
|
-
|
|
1061
|
+
const zipPath = (0, import_path2.join)(path, `${zipName}.zip`);
|
|
1062
|
+
await archiverImage(directorys, zipPath, password, level);
|
|
1057
1063
|
if (this.config.debug) this.logger.info(`ZIP ${zipName}.zip 生成完成`);
|
|
1058
|
-
return
|
|
1064
|
+
return zipPath;
|
|
1059
1065
|
}
|
|
1060
1066
|
async photoToZip(photo, zipName, password, level = 6) {
|
|
1061
1067
|
const id = photo.getId();
|
|
1062
1068
|
zipName = sanitizeFileName(zipName);
|
|
1063
|
-
|
|
1069
|
+
if (this.config.debug) this.logger.info(`开始生成ZIP ${zipName}.zip`);
|
|
1070
|
+
const path = (0, import_path2.join)(this.root, "photo", `${id}`);
|
|
1071
|
+
const zipPath = (0, import_path2.join)(path, `${zipName}.zip`);
|
|
1064
1072
|
await archiverImage(
|
|
1065
|
-
[{ directory:
|
|
1066
|
-
|
|
1073
|
+
[{ directory: (0, import_path2.join)(path, "decoded"), destpath: false }],
|
|
1074
|
+
zipPath,
|
|
1067
1075
|
password,
|
|
1068
1076
|
level
|
|
1069
1077
|
);
|
|
1070
1078
|
if (this.config.debug) this.logger.info(`ZIP ${zipName}.zip 生成完成`);
|
|
1071
|
-
return
|
|
1079
|
+
return zipPath;
|
|
1072
1080
|
}
|
|
1073
1081
|
/**
|
|
1074
1082
|
* 获取时间戳
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -17,6 +17,22 @@ jm queue
|
|
|
17
17
|
|
|
18
18
|
## 更新日志
|
|
19
19
|
|
|
20
|
+
<details>
|
|
21
|
+
<summary>0.2.4</summary>
|
|
22
|
+
|
|
23
|
+
1. 调整debug日志
|
|
24
|
+
2. 修正文化名返回值
|
|
25
|
+
|
|
26
|
+
</details>
|
|
27
|
+
|
|
28
|
+
<details>
|
|
29
|
+
<summary>0.2.3</summary>
|
|
30
|
+
|
|
31
|
+
1. 将手动路径拼接替换为join
|
|
32
|
+
2. 健壮文件名序列化,尝试修复部分文件名导致无法创建文件
|
|
33
|
+
|
|
34
|
+
</details>
|
|
35
|
+
|
|
20
36
|
<details>
|
|
21
37
|
<summary>0.2.2</summary>
|
|
22
38
|
|