Skip to content

Commit

Permalink
feat: mfsdk
Browse files Browse the repository at this point in the history
  • Loading branch information
lovegaoshi committed Dec 18, 2024
1 parent 4070a5d commit 0de5a45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/localization/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"RegExpName": "Update RegExp",
"RegExpDesc": "Update RegExp rules from GitHub",
"MusicFreeName": "MusicFree Plugins",
"MusicFreeDesc": "Enable MusicFree plugins",
"MusicFreeDesc": "Do NOT use, uve been warned.",
"MusicFreeCheckTitle": "MusicFree Plugins",
"R128GainName": "Update R18Gain",
"R128GainDesc": "Update R18Gain rules from GitHub",
Expand Down
2 changes: 1 addition & 1 deletion src/localization/zhcn/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
"RegExpName": "更新 RegExp",
"RegExpDesc": "从 Github 更新 RegExp 规则",
"MusicFreeName": "MusicFree 插件",
"MusicFreeDesc": "启用 MusicFree 插件",
"MusicFreeDesc": "不要使用 后果自负",
"MusicFreeCheckTitle": "MusicFree 插件",
"R128GainName": "更新 R18Gain",
"R128GainDesc": "从 GitHub 更新 R18Gain 规则",
Expand Down
13 changes: 9 additions & 4 deletions src/utils/mfsdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { saveItem, getItem } from '@utils/ChromeStorageAPI';
import { StorageKeys } from '@enums/Storage';
import { readTxtFile, rmTxtFile, writeTxtFile } from '@utils/fs';
import logger from './Logger';
import { loadEvalPlugin } from './mediafetch/evalsdk';
import { loadEvalPlugin, MFsdk } from './mediafetch/evalsdk';
import bFetch from './BiliFetch';

const mfsdkSubFolder = 'mfsdk';
Expand Down Expand Up @@ -39,17 +39,22 @@ export const initMFsdk = async () => {
return mfsdks.filter(v => v !== undefined);
};

export const fetchMFsdk = async (url: string) => {
export const fetchMFsdk = async (url: string): Promise<MFsdk[]> => {
try {
const res = await bFetch(url);
const text = await res.text();
try {
const json = JSON.parse(text) as { plugins: { url: string }[] };
const sdks = await Promise.all(json.plugins.map(p => fetchMFsdk(p.url)));
return sdks.flat();
} catch {}
const loadedSDK = loadEvalPlugin(text, url);
const sdkLocalPath = `${loadedSDK.platform}.${loadedSDK.version}.js`;
loadedSDK.path = sdkLocalPath;
writeTxtFile(sdkLocalPath, [text], mfsdkSubFolder);
return [loadedSDK];
} catch {
logger.warn(`[mfsdk] failed to fetch and parse ${url}`);
} catch (e) {
logger.warn(`[mfsdk] failed to fetch and parse ${url}: ${e}`);
}
return [];
};

0 comments on commit 0de5a45

Please sign in to comment.