mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2026-03-20 08:12:42 +08:00
feat: 模块接口; 脚本参数支持 JSON 和 URL编码
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { FILES_KEY } from '@/constants';
|
||||
import { FILES_KEY, MODULES_KEY } from '@/constants';
|
||||
import { findByName } from '@/utils/database';
|
||||
import { HTTP, ENV } from '@/vendor/open-api';
|
||||
import { hex_md5 } from '@/vendor/md5';
|
||||
@@ -8,19 +8,21 @@ import $ from '@/core/app';
|
||||
const tasks = new Map();
|
||||
|
||||
export default async function download(url, ua) {
|
||||
const downloadUrlMatch = url.match(/^\/api\/file\/(.+)/);
|
||||
const downloadUrlMatch = url.match(/^\/api\/(file|module)\/(.+)/);
|
||||
if (downloadUrlMatch) {
|
||||
let fileName = downloadUrlMatch?.[1];
|
||||
if (fileName == null) {
|
||||
throw new Error(`本地文件 URL 无效: ${url}`);
|
||||
let type = downloadUrlMatch?.[1];
|
||||
let name = downloadUrlMatch?.[2];
|
||||
if (name == null) {
|
||||
throw new Error(`本地 ${type} URL 无效: ${url}`);
|
||||
}
|
||||
fileName = decodeURIComponent(fileName);
|
||||
const allFiles = $.read(FILES_KEY);
|
||||
const file = findByName(allFiles, fileName);
|
||||
if (!file) {
|
||||
throw new Error(`找不到本地文件: ${fileName}`);
|
||||
name = decodeURIComponent(name);
|
||||
const key = type === 'module' ? MODULES_KEY : FILES_KEY;
|
||||
const item = findByName($.read(key), name);
|
||||
if (!item) {
|
||||
throw new Error(`找不到本地 ${type}: ${name}`);
|
||||
}
|
||||
return file.content;
|
||||
|
||||
return item.content;
|
||||
}
|
||||
|
||||
const { isNode } = ENV();
|
||||
|
||||
Reference in New Issue
Block a user