feat: 添加 GitHub 存储支持,更新相关文档和配置

This commit is contained in:
2025-11-08 20:54:55 +08:00
parent bafcb9d9df
commit e71734e2d6
10 changed files with 798 additions and 57 deletions

View File

@@ -9,6 +9,7 @@
--folder-color: #ffc107;
--file-color: #6c757d;
--shadow-color: rgba(0, 0, 0, 0.1);
--icon-bg: #f0f0f0;
}
[data-theme="dark"] {
@@ -22,6 +23,7 @@
--folder-color: #ffd54f;
--file-color: #b0b0b0;
--shadow-color: rgba(0, 0, 0, 0.3);
--icon-bg: #3a3a3a;
}
body {
@@ -149,7 +151,38 @@ h1 {
object-fit: cover;
border-radius: 6px;
margin-bottom: 8px;
background-color: #f0f0f0;
background-color: var(--icon-bg);
cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.grid-thumb:hover {
transform: scale(1.02);
box-shadow: 0 2px 8px var(--shadow-color);
}
/* 网格卡片中的图标容器 */
.grid-icon {
width: 100%;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 8px;
border-radius: 6px;
background-color: var(--icon-bg);
cursor: pointer;
transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}
.grid-icon:hover {
transform: scale(1.02);
background-color: var(--hover-bg);
box-shadow: 0 2px 8px var(--shadow-color);
}
.grid-icon i {
font-size: 64px;
}
.grid-name {

View File

@@ -295,20 +295,35 @@
}
}
function registerServiceWorker() {
function unregisterServiceWorker() {
if (!("serviceWorker" in navigator)) {
return;
}
window.addEventListener("load", () => {
navigator.serviceWorker
.register("/static/sw.js")
.then((registration) => {
console.log("SW registered:", registration);
.getRegistrations()
.then((registrations) => {
registrations.forEach((registration) => {
registration.unregister().then(() => {
console.log("Service Worker unregistered");
});
});
})
.catch((error) => {
console.log("SW registration failed:", error);
console.log("Error unregistering Service Worker:", error);
});
// 清理 Service Worker 相关的缓存
if ("caches" in window) {
caches.keys().then((cacheNames) => {
cacheNames.forEach((cacheName) => {
caches.delete(cacheName).then(() => {
console.log("Cache deleted:", cacheName);
});
});
});
}
});
}
@@ -527,24 +542,67 @@
updateSelectAllState();
}
function attachDownloadButtonListeners() {
const downloadButtons = document.querySelectorAll("[data-download-key]");
downloadButtons.forEach((button) => {
if (!button.dataset.listenerAttached) {
button.addEventListener("click", () => {
const key = button.dataset.downloadKey;
const name = button.dataset.downloadName;
downloadFile(`/download/${key}`, name);
});
button.dataset.listenerAttached = "true";
}
});
}
function downloadFile(url, filename) {
if (!url) {
updateStatus("✗ 无法下载:缺少下载链接", "error");
return;
}
const link = document.createElement("a");
link.href = url;
link.download = filename || "";
link.target = "_blank";
link.rel = "noopener";
// 对于 /download/ 路径,使用 fetch 以更好地处理大文件和错误
if (url.startsWith("/download/")) {
fetch(url)
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.blob();
})
.then((blob) => {
const link = document.createElement("a");
const blobUrl = URL.createObjectURL(blob);
link.href = blobUrl;
link.download = filename || "file";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(blobUrl);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
const statusDiv = updateStatus(`✓ 开始下载: ${filename || ""}`, "success");
hideStatusLater(statusDiv);
})
.catch((error) => {
console.error("Download error:", error);
updateStatus(`✗ 下载失败: ${error.message}`, "error");
});
} else {
// 对于外部 URL使用传统方法
const link = document.createElement("a");
link.href = url;
link.download = filename || "";
link.target = "_blank";
link.rel = "noopener";
const statusDiv = updateStatus(`✓ 开始下载: ${filename || ""}`, "success");
hideStatusLater(statusDiv);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
const statusDiv = updateStatus(`✓ 开始下载: ${filename || ""}`, "success");
hideStatusLater(statusDiv);
}
}
async function deleteSelectedEntries() {
@@ -885,8 +943,9 @@
initDialog();
initThemeAndView();
registerModalHandlers();
registerServiceWorker();
unregisterServiceWorker();
attachEntryCheckboxListeners();
attachDownloadButtonListeners();
});
window.uploadFiles = uploadFiles;