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

Function importByUrls

src/pages/components/layout/MainLayout.tsx:98–123  ·  view source on GitHub ↗
(urls: string[])

Source from the content-addressed store, hash-verified

96};
97
98const importByUrls = async (urls: string[]): Promise<TImportStat | undefined> => {
99 if (urls.length == 0) {
100 return;
101 }
102 const results = (await Promise.allSettled(
103 urls.map(async (url) => {
104 const formattedResult = await formatUrl(url);
105 if (formattedResult instanceof Object) {
106 return await Promise.resolve(formattedResult);
107 } else {
108 return await scriptClient.do("importByUrl", formattedResult);
109 }
110 })
111 // this.do 只会resolve 不会reject
112 )) as PromiseFulfilledResult<{ success: boolean; msg: string }>[];
113 const stat = { success: 0, fail: 0, msg: [] as string[] };
114 results.forEach(({ value }, index) => {
115 if (value.success) {
116 stat.success++;
117 } else {
118 stat.fail++;
119 stat.msg.push(`#${index + 1}: ${value.msg}`);
120 }
121 });
122 return stat;
123};
124
125const getSafePopupParent = (p: Element) => {
126 p = (p.closest("button")?.parentNode as Element) || p; // 確保 ancestor 沒有 button 元素

Callers 1

importByUrlsLocalFunction · 0.85

Calls 4

formatUrlFunction · 0.85
forEachMethod · 0.80
pushMethod · 0.80
doMethod · 0.45

Tested by

no test coverage detected