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

Function initAsync

src/pages/install/hooks.tsx:136–266  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134 };
135
136 const initAsync = async () => {
137 try {
138 const uuid = searchParams.get("uuid");
139 const fid = searchParams.get("file");
140
141 // 如果有 url 或 没有 uuid 和 file,跳过初始化逻辑
142 if (searchParams.get("url") || (!uuid && !fid)) {
143 return;
144 }
145 let info: ScriptInfo | undefined;
146 let isKnownUpdate: boolean = false;
147
148 if (window.history.length > 1) {
149 setDoBackwards(true);
150 }
151 setLoaded(true);
152
153 let paramOptions = {};
154 if (uuid) {
155 startKeepAlive(uuid);
156 const cachedInfo = await scriptClient.getInstallInfo(uuid);
157 if (cachedInfo?.[0]) isKnownUpdate = true;
158 info = cachedInfo?.[1] || undefined;
159 paramOptions = cachedInfo?.[2] || {};
160 if (!info) {
161 throw new Error("fetch script info failed");
162 }
163 const code = await getTempCode(uuid);
164 if (code === undefined) {
165 throw new Error("failed to load script code from temp storage");
166 }
167 info.code = code;
168 } else {
169 // 检查是不是本地文件安装
170 if (!fid) {
171 throw new Error("url param - local file id is not found");
172 }
173 const fileHandle = await loadHandle(fid);
174 if (!fileHandle) {
175 throw new Error("invalid file access - fileHandle is null");
176 }
177 const file = await fileHandle.getFile();
178 if (!file) {
179 throw new Error("invalid file access - file is null");
180 }
181 // 处理本地文件的安装流程
182 setLocalFileHandle((prev) => {
183 if (prev instanceof FileSystemFileHandle) unmountFileTrack(prev);
184 return fileHandle!;
185 });
186
187 // 刷新 timestamp, 使 10s~15s 后不会被立即清掉
188 intervalExecution(`${cIdKey}liveFileHandle`, () => saveHandle(fid, fileHandle), 5 * 60 * 1000, true);
189
190 const code = await file.text();
191 const metadata = parseMetadata(code);
192 if (!metadata) {
193 // 非 UserScript,尝试作为 SkillScript 处理(仅 agent 启用时)

Callers 1

useInstallDataFunction · 0.85

Calls 15

startKeepAliveFunction · 0.90
getTempCodeFunction · 0.90
loadHandleFunction · 0.90
unmountFileTrackFunction · 0.90
intervalExecutionFunction · 0.90
saveHandleFunction · 0.90
parseMetadataFunction · 0.90
parseSkillScriptMetadataFunction · 0.90
createScriptInfoLocalFunction · 0.90
prepareSubscribeByCodeFunction · 0.90
prepareScriptByCodeFunction · 0.90
timeoutExecutionFunction · 0.90

Tested by

no test coverage detected