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

Function NetDisk

packages/filesystem/auth.ts:37–69  ·  view source on GitHub ↗
(netDiskType: NetDiskType)

Source from the content-addressed store, hash-verified

35}
36
37export async function NetDisk(netDiskType: NetDiskType) {
38 try {
39 let isWindowClosed: any;
40 const url = `${ExtServer}api/v1/auth/net-disk?netDiskType=${netDiskType}`;
41 if (typeof chrome !== "undefined" && typeof chrome?.tabs?.create === "function") {
42 const t = await chrome.tabs.create({
43 url,
44 });
45 isWindowClosed = async () => {
46 try {
47 const tab = await chrome.tabs.get(t.id!);
48 // 如果到了callback页面,调用关闭
49 if (tab && tab.url?.includes("/auth/net-disk/callback")) {
50 chrome.tabs.remove(t.id!);
51 }
52 return !tab || tab.id !== t.id;
53 } catch {
54 return true;
55 }
56 };
57 } else {
58 const loginWindow = window.open(url);
59 if (!loginWindow) throw new Error("The window cannot be opened.");
60 isWindowClosed = () => loginWindow.closed === true;
61 }
62 while (true) {
63 await sleep(1000);
64 if (await isWindowClosed()) break;
65 }
66 } catch (e) {
67 console.error(e);
68 }
69}
70
71export type Token = {
72 accessToken: string;

Callers 1

AuthVerifyFunction · 0.85

Calls 6

sleepFunction · 0.90
errorMethod · 0.80
createMethod · 0.65
getMethod · 0.65
removeMethod · 0.65
openMethod · 0.65

Tested by

no test coverage detected