Skip to content

Commit a805dde

Browse files
committed
✨ match和更新URL管理
1 parent 707d391 commit a805dde

File tree

6 files changed

+499
-7
lines changed

6 files changed

+499
-7
lines changed

src/app/service/script/controller.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,16 @@ export default class ScriptController {
5454
exclude(id: number, exclude: string, remove: boolean) {
5555
return this.dispatchEvent("exclude", { id, exclude, remove });
5656
}
57+
58+
resetExclude(id: number, exclude: string[] | undefined) {
59+
return this.dispatchEvent("resetExclude", { id, exclude });
60+
}
61+
62+
resetMatch(id: number, match: string[] | undefined) {
63+
return this.dispatchEvent("resetMatch", { id, match });
64+
}
65+
66+
updateCheckUpdateUrl(id: number, url: string) {
67+
return this.dispatchEvent("updateCheckUpdateUrl", { id, url });
68+
}
5769
}

src/app/service/script/event.ts

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export type ScriptEvent =
1717
| "disable"
1818
| "delete"
1919
| "exclude"
20+
| "resetExclude"
21+
| "resetMatch"
22+
| "updateCheckUpdateUrl"
2023
| "checkUpdate"
2124
| "importByUrl";
2225

@@ -196,7 +199,8 @@ export default class ScriptEventListener {
196199
return reject(new Error("脚本不存在"));
197200
}
198201
script.selfMetadata = script.selfMetadata || {};
199-
const excludes = script.selfMetadata.exclude || [];
202+
const excludes =
203+
script.selfMetadata.exclude || script.metadata.exclude || [];
200204
if (remove) {
201205
for (let i = 0; i < excludes.length; i += 1) {
202206
if (excludes[i] === exclude) {
@@ -226,4 +230,119 @@ export default class ScriptEventListener {
226230
});
227231
});
228232
}
233+
234+
@ListenEventDecorator("resetExclude")
235+
public resetExcludeHandler({
236+
id,
237+
exclude,
238+
}: {
239+
id: number;
240+
exclude: string[] | undefined;
241+
}) {
242+
const logger = this.logger.with({ scriptId: id });
243+
return new Promise((resolve, reject) => {
244+
this.dao
245+
.findById(id)
246+
.then((script) => {
247+
if (!script) {
248+
return reject(new Error("脚本不存在"));
249+
}
250+
script.selfMetadata = script.selfMetadata || {};
251+
if (exclude) {
252+
script.selfMetadata.exclude = exclude;
253+
} else {
254+
delete script.selfMetadata.exclude;
255+
}
256+
this.dao.save(script).then(
257+
() => {
258+
logger.info("script resetExclude success");
259+
ScriptManager.hook.trigger("upsert", script, "system");
260+
resolve({ id: script.id });
261+
},
262+
(e) => {
263+
logger.error("script resetExclude failed", Logger.E(e));
264+
reject(e);
265+
}
266+
);
267+
return resolve(1);
268+
})
269+
.catch((e) => {
270+
logger.error("resetMatch error", Logger.E(e));
271+
reject(e);
272+
});
273+
});
274+
}
275+
276+
@ListenEventDecorator("resetMatch")
277+
public resetMatchHandler({
278+
id,
279+
match,
280+
}: {
281+
id: number;
282+
match: string[] | undefined;
283+
}) {
284+
const logger = this.logger.with({ scriptId: id });
285+
return new Promise((resolve, reject) => {
286+
this.dao
287+
.findById(id)
288+
.then((script) => {
289+
if (!script) {
290+
return reject(new Error("脚本不存在"));
291+
}
292+
script.selfMetadata = script.selfMetadata || {};
293+
if (match) {
294+
script.selfMetadata.match = match;
295+
} else {
296+
delete script.selfMetadata.match;
297+
}
298+
this.dao.save(script).then(
299+
() => {
300+
logger.info("script resetMatch success");
301+
ScriptManager.hook.trigger("upsert", script, "system");
302+
resolve({ id: script.id });
303+
},
304+
(e) => {
305+
logger.error("script resetMatch failed", Logger.E(e));
306+
reject(e);
307+
}
308+
);
309+
return resolve(1);
310+
})
311+
.catch((e) => {
312+
logger.error("resetMatch error", Logger.E(e));
313+
reject(e);
314+
});
315+
});
316+
}
317+
318+
@ListenEventDecorator("updateCheckUpdateUrl")
319+
public updateCheckUpdateUrlHandler({ id, url }: { id: number; url: string }) {
320+
const logger = this.logger.with({ scriptId: id });
321+
return new Promise((resolve, reject) => {
322+
this.dao
323+
.findById(id)
324+
.then((script) => {
325+
if (!script) {
326+
return reject(new Error("脚本不存在"));
327+
}
328+
script.checkUpdateUrl = url;
329+
script.downloadUrl = url;
330+
this.dao.save(script).then(
331+
() => {
332+
logger.info("script updateCheckUpdateUrl success");
333+
resolve({ id: script.id });
334+
},
335+
(e) => {
336+
logger.error("script updateCheckUpdateUrl failed", Logger.E(e));
337+
reject(e);
338+
}
339+
);
340+
return resolve(1);
341+
})
342+
.catch((e) => {
343+
logger.error("updateCheckUpdateUrl error", Logger.E(e));
344+
reject(e);
345+
});
346+
});
347+
}
229348
}

src/app/service/synchronize/event.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export default class SynchronizeEventListener {
6060

6161
// 生成备份文件
6262
public async backupHandler(ids?: number[]) {
63-
console.log(ids);
6463
const zip = new JSZip();
6564
const fs = new ZipFileSystem(zip);
6665
await this.manager.backup(fs, ids);

0 commit comments

Comments
 (0)