mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-04-23 22:29:32 +08:00
feat: Added cron script for syncing all artifacts to gist
This commit is contained in:
parent
94262e162a
commit
49ed9f1ff3
16
backend/dist/cron-sync-artifacts.min.js
vendored
Normal file
16
backend/dist/cron-sync-artifacts.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
backend/dist/sub-store-parser.loon.min.js
vendored
2
backend/dist/sub-store-parser.loon.min.js
vendored
@ -6,7 +6,7 @@
|
||||
* ███████║╚██████╔╝██████╔╝ ███████║ ██║ ╚██████╔╝██║ ██║███████╗
|
||||
* ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
|
||||
* Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket!
|
||||
* @updated: 2022/6/21 04:41:29
|
||||
* @updated: 2022/6/21 15:59:41
|
||||
* @version: 2.1.2
|
||||
* @author: Peng-YM
|
||||
* @github: https://github.com/Peng-YM/Sub-Store
|
||||
|
@ -82,7 +82,8 @@ function banner(dest) {
|
||||
|
||||
const artifacts = [
|
||||
{src: 'src/main.js', dest: 'sub-store.min.js'},
|
||||
{src: 'src/products/resource-parser.loon.js', dest: 'dist/sub-store-parser.loon.min.js'}
|
||||
{src: 'src/products/resource-parser.loon.js', dest: 'dist/sub-store-parser.loon.min.js'},
|
||||
{src: 'src/products/cron-sync-artifacts.js', dest: 'dist/cron-sync-artifacts.min.js'}
|
||||
];
|
||||
|
||||
export const build = gulp.series(gulp.parallel(artifacts.map(artifact => scripts(artifact.src, artifact.dest))), gulp.parallel(artifacts.map(artifact => banner(artifact.dest))));
|
||||
|
70
backend/src/products/cron-sync-artifacts.js
Normal file
70
backend/src/products/cron-sync-artifacts.js
Normal file
@ -0,0 +1,70 @@
|
||||
import {
|
||||
ARTIFACTS_KEY,
|
||||
SUBS_KEY,
|
||||
COLLECTIONS_KEY,
|
||||
RULES_KEY,
|
||||
} from '@/restful/constants';
|
||||
import { syncArtifact, produceArtifact } from '@/restful/artifacts';
|
||||
import $ from '@/core/app';
|
||||
|
||||
console.log(
|
||||
`
|
||||
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
|
||||
𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 © 𝑷𝒆𝒏𝒈-𝒀𝑴
|
||||
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
|
||||
`,
|
||||
);
|
||||
!(async function () {
|
||||
$.info('开始同步所有远程配置...');
|
||||
const allArtifacts = $.read(ARTIFACTS_KEY);
|
||||
const files = {};
|
||||
|
||||
try {
|
||||
await Promise.all(
|
||||
Object.values(allArtifacts).map(async (artifact) => {
|
||||
if (artifact.sync) {
|
||||
$.info(`正在同步云配置:${artifact.name}...`);
|
||||
let item;
|
||||
switch (artifact.type) {
|
||||
case 'subscription':
|
||||
item = $.read(SUBS_KEY)[artifact.source];
|
||||
break;
|
||||
case 'collection':
|
||||
item = $.read(COLLECTIONS_KEY)[artifact.source];
|
||||
break;
|
||||
case 'rule':
|
||||
item = $.read(RULES_KEY)[artifact.source];
|
||||
break;
|
||||
}
|
||||
const output = await produceArtifact({
|
||||
type: artifact.type,
|
||||
item,
|
||||
platform: artifact.platform,
|
||||
});
|
||||
|
||||
files[artifact.name] = {
|
||||
content: output,
|
||||
};
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
const resp = await syncArtifact(files);
|
||||
const body = JSON.parse(resp.body);
|
||||
|
||||
for (const artifact of Object.values(allArtifacts)) {
|
||||
artifact.updated = new Date().getTime();
|
||||
// extract real url from gist
|
||||
artifact.url = body.files[artifact.name].raw_url.replace(
|
||||
/\/raw\/[^/]*\/(.*)/,
|
||||
'/raw/$1',
|
||||
);
|
||||
}
|
||||
|
||||
$.write(allArtifacts, ARTIFACTS_KEY);
|
||||
$.notify('🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』', '全部订阅同步成功!');
|
||||
} catch (err) {
|
||||
$.notify('🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』', '同步订阅失败', `原因:${err}`);
|
||||
$.error(`无法同步订阅配置到 Gist,原因:${err}`);
|
||||
}
|
||||
})().finally(() => $.done());
|
@ -414,4 +414,4 @@ async function produceArtifact({ type, item, platform, noProcessor }) {
|
||||
}
|
||||
}
|
||||
|
||||
export { produceArtifact };
|
||||
export { syncArtifact, produceArtifact };
|
||||
|
4
backend/sub-store.min.js
vendored
4
backend/sub-store.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user