add auth check
This commit is contained in:
@@ -39,21 +39,13 @@ async function callServer(payload, options = {}) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function downloadHeaders(options = {}) {
|
||||
if (!options.adminToken) return {};
|
||||
return {
|
||||
authorization: `Bearer ${options.adminToken}`,
|
||||
"x-admin-token": options.adminToken
|
||||
};
|
||||
}
|
||||
|
||||
async function downloadFromUrl(url, fileName, options = {}) {
|
||||
await fs.promises.mkdir(DOWNLOAD_DIR, { recursive: true });
|
||||
return downloadToPath(url, path.join(DOWNLOAD_DIR, path.basename(fileName)), options);
|
||||
}
|
||||
|
||||
async function downloadToPath(url, destination, options = {}) {
|
||||
const response = await fetch(url, { headers: downloadHeaders(options) });
|
||||
const response = await fetch(url);
|
||||
if (!response.ok || !response.body) {
|
||||
throw new Error(`下载失败: HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user