feat: Added cron script for syncing all artifacts to gist

This commit is contained in:
Peng-YM 2022-06-21 16:01:02 +08:00
parent 94262e162a
commit 49ed9f1ff3
6 changed files with 92 additions and 5 deletions

16
backend/dist/cron-sync-artifacts.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -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

View File

@ -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))));

View 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());

View File

@ -414,4 +414,4 @@ async function produceArtifact({ type, item, platform, noProcessor }) {
}
}
export { produceArtifact };
export { syncArtifact, produceArtifact };

File diff suppressed because one or more lines are too long