MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / scriptImportAsync

Function scriptImportAsync

src/pages/import/App.tsx:167–209  ·  view source on GitHub ↗
(item: ScriptData)

Source from the content-addressed store, hash-verified

165 }, []);
166
167 const scriptImportAsync = async (item: ScriptData) => {
168 try {
169 if (item.script?.script) {
170 if (item.script.script.ignoreVersion) item.script.script.ignoreVersion = "";
171 }
172 const scriptDetails = item.script!.script!;
173 const createtime = item.lastModificationDate;
174 const updatetime = item.lastModificationDate;
175 await scriptClient.install({ script: scriptDetails, code: item.code, createtime, updatetime });
176 await Promise.all([
177 (async () => {
178 // 导入资源
179 if (!item.requires || !item.resources || !item.requiresCss) return;
180 if (!item.requires[0] && !item.resources[0] && !item.requiresCss[0]) return;
181 await sleep(((Math.random() * 600) | 0) + 200);
182 await synchronizeClient.importResources(
183 item.script?.script.uuid,
184 item.requires,
185 item.resources,
186 item.requiresCss
187 );
188 })(),
189 (async () => {
190 // 导入数据
191 const { data } = item.storage;
192 const ts = item.storage.ts || 0;
193 const entries = Object.entries(data);
194 if (entries.length === 0) return;
195 await sleep(((Math.random() * 600) | 0) + 200);
196 const uuid = item.script!.script.uuid!;
197 const keyValuePairs = [] as TKeyValuePair[];
198 for (const [key, value] of entries) {
199 keyValuePairs.push([key, encodeRValue(value)]);
200 }
201 await valueClient.setScriptValues({ uuid: uuid, keyValuePairs, isReplace: false, ts: ts });
202 })(),
203 ]);
204 setInstallNum((prev) => [prev[0] + 1, prev[1]]);
205 } catch (e: any) {
206 // 跳過失敗
207 item.error = e.toString();
208 }
209 };
210
211 const importScripts = async (scripts: ScriptData[]) => {
212 const promises: Promise<any>[] = [];

Callers 1

importScriptsFunction · 0.85

Calls 7

sleepFunction · 0.90
encodeRValueFunction · 0.90
entriesMethod · 0.80
pushMethod · 0.80
installMethod · 0.65
importResourcesMethod · 0.45
setScriptValuesMethod · 0.45

Tested by

no test coverage detected