@wahaha216/koishi-plugin-jmcomic 0.2.2 → 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 +19 -13
- package/package.json +1 -1
- package/readme.md +8 -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");
|
|
@@ -1041,34 +1045,36 @@ 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
|
-
const path =
|
|
1048
|
+
const path = (0, import_path2.join)(this.root, "album", `${id}`);
|
|
1045
1049
|
const directorys = [];
|
|
1046
1050
|
if (series.length > 1) {
|
|
1047
1051
|
for (const s of series) {
|
|
1048
1052
|
directorys.push({
|
|
1049
|
-
directory:
|
|
1053
|
+
directory: (0, import_path2.join)(path, "decoded", s.id),
|
|
1050
1054
|
destpath: `第${s.sort}章`
|
|
1051
1055
|
});
|
|
1052
1056
|
}
|
|
1053
1057
|
} else {
|
|
1054
|
-
directorys.push({ directory:
|
|
1058
|
+
directorys.push({ directory: (0, import_path2.join)(path, "decoded"), destpath: false });
|
|
1055
1059
|
}
|
|
1056
|
-
|
|
1060
|
+
const zipPath = (0, import_path2.join)(path, `${zipName}.zip`);
|
|
1061
|
+
await archiverImage(directorys, zipPath, password, level);
|
|
1057
1062
|
if (this.config.debug) this.logger.info(`ZIP ${zipName}.zip 生成完成`);
|
|
1058
|
-
return
|
|
1063
|
+
return zipPath;
|
|
1059
1064
|
}
|
|
1060
1065
|
async photoToZip(photo, zipName, password, level = 6) {
|
|
1061
1066
|
const id = photo.getId();
|
|
1062
1067
|
zipName = sanitizeFileName(zipName);
|
|
1063
|
-
const path =
|
|
1068
|
+
const path = (0, import_path2.join)(this.root, "photo", `${id}`);
|
|
1069
|
+
const zipPath = (0, import_path2.join)(path, `${zipName}.zip`);
|
|
1064
1070
|
await archiverImage(
|
|
1065
|
-
[{ directory:
|
|
1066
|
-
|
|
1071
|
+
[{ directory: (0, import_path2.join)(path, "decoded"), destpath: false }],
|
|
1072
|
+
zipPath,
|
|
1067
1073
|
password,
|
|
1068
1074
|
level
|
|
1069
1075
|
);
|
|
1070
1076
|
if (this.config.debug) this.logger.info(`ZIP ${zipName}.zip 生成完成`);
|
|
1071
|
-
return
|
|
1077
|
+
return zipPath;
|
|
1072
1078
|
}
|
|
1073
1079
|
/**
|
|
1074
1080
|
* 获取时间戳
|
package/package.json
CHANGED