Skip to content

Commit

Permalink
finish download
Browse files Browse the repository at this point in the history
  • Loading branch information
Sianao committed Nov 24, 2024
1 parent c38f6db commit 1c3d852
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/theme/logic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@ import { Button } from "@mui/material";

import { saveAs } from 'file-saver';

async function downloadFile(url: string, filename?: string): Promise<void> {
try {
const response = await fetch(url);
async function downloadFile(url: string): Promise<void> {
try {
url="https://gitproxy.click/"+url;
const response = await fetch(url);

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const blob = await response.blob();
const blob = await response.blob();

if (!filename) {
const urlSegments = url.split('/');
filename = urlSegments[urlSegments.length - 1];
}
const urlSegments = url.split('/');
let filename = urlSegments[urlSegments.length - 1];

saveAs(blob, filename);
} catch (error) {
console.error('下载文件时出错:', error);
}
saveAs(blob, filename);
} catch (error) {
console.error('下载文件时出错:', error);
}
}


Expand All @@ -51,11 +50,11 @@ const GetDownloadAddress = () => {

// 更新 onClick 函数逻辑
const onClick = (req: string) => {
if (req==""){
if (req == "") {
setSnackbarSeverity("error");
setSnackbarMessage("请输入链接再开始下载");
setSnackbarOpen(true);
}else if (req.startsWith('https://')) {
} else if (req.startsWith('https://')) {
setSnackbarSeverity("success");
setSnackbarMessage("下载即将开始");
setSnackbarOpen(true);
Expand All @@ -64,7 +63,7 @@ const GetDownloadAddress = () => {
setSnackbarMessage("无效的链接,请使用 HTTPS 链接。");
setSnackbarOpen(true);
}
saveAs(req)
downloadFile(req)
};

return (
Expand All @@ -77,15 +76,15 @@ const GetDownloadAddress = () => {
onClick(address.value)
}}
sx={{ minWidth: 'fit-content' }}>
开始下载
</Button>
开始下载
</Button>
<CustomizedSnackbars
open={snackbarOpen}
onClose={() => setSnackbarOpen(false)}
message={snackbarMessage}
severity={snackbarSeverity}
/>
</>
</>
);
};

Expand Down
Binary file removed tmp/runner-build
Binary file not shown.

0 comments on commit 1c3d852

Please sign in to comment.