MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / parse

Method parse

src/pkg/backup/import.ts:51–237  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49
50 // 解析出备份数据
51 async parse(): Promise<BackupData> {
52 const map = new Map<string, Partial<ScriptData> & ScriptBackupData>();
53 const subscribe = new Map<string, Partial<SubscribeData> & SubscribeBackupData>();
54 let files = await this.fs.list();
55
56 // 处理订阅
57 files = await this.dealFile(files, async (file) => {
58 const { name } = file;
59 if (!name.endsWith(".user.sub.js")) {
60 return false;
61 }
62 const key = name.substring(0, name.length - 12);
63 const subData = {
64 source: <string>await this.getFileContent(file, false),
65 lastModificationDate: file.updatetime,
66 } satisfies Partial<SubscribeData> & SubscribeBackupData;
67 subscribe.set(key, subData);
68 return true;
69 });
70 // 处理订阅options
71 files = await this.dealFile(files, async (file) => {
72 const { name } = file;
73 if (!name.endsWith(".user.sub.options.json")) {
74 return false;
75 }
76 const key = name.substring(0, name.length - 22);
77 const data = <SubscribeOptionsFile>await this.getFileContent(file, true);
78 subscribe.get(key)!.options = data;
79 return true;
80 });
81
82 // 先处理*.user.js文件
83 files = await this.dealFile(files, async (file) => {
84 const { name } = file;
85 if (!name.endsWith(".user.js")) {
86 return false;
87 }
88 // 遍历与脚本同名的文件
89 const key = name.substring(0, name.length - 8);
90 const backupData = {
91 code: <string>await this.getFileContent(file, false),
92 storage: { data: {}, ts: 0 },
93 requires: [],
94 requiresCss: [],
95 resources: [],
96 lastModificationDate: file.updatetime,
97 } satisfies Partial<ScriptData> & ScriptBackupData;
98 map.set(key, backupData);
99 return true;
100 });
101 // 处理options.json文件
102 files = await this.dealFile(files, async (file) => {
103 const { name } = file;
104 if (!name.endsWith(".options.json")) {
105 return false;
106 }
107 const key = name.substring(0, name.length - 13);
108 const data = <ScriptOptionsFile>await this.getFileContent(file, true);

Callers 15

rspack.config.tsFile · 0.45
transformFunction · 0.45
runFunction · 0.45
createResponseErrorMethod · 0.45
parseS3ErrorFunction · 0.45
parseListObjectsV2Function · 0.45
onedrive.test.tsFile · 0.45
createResponseErrorMethod · 0.45
ScriptStorageFunction · 0.45
lintFunction · 0.45

Calls 15

dealFileMethod · 0.95
getFileContentMethod · 0.95
parseStorageValueFunction · 0.90
blobToBase64Function · 0.90
isTextFunction · 0.90
keysMethod · 0.80
pushMethod · 0.80
warnMethod · 0.80
errorMethod · 0.80
EMethod · 0.80
listMethod · 0.65
setMethod · 0.65

Tested by 3

runAndCaptureFunction · 0.36
runXhrFunction · 0.36
createMockWSServerFunction · 0.36