mirror of
https://github.com/RhenCloud/Cloud-Index.git
synced 2025-12-06 15:26:10 +08:00
feat: 完整的 R2 文件管理系统初始化
- 实现 11 个 API 端点:上传、删除、重命名、复制、移动、创建文件夹等 - 构建存储抽象层,支持多后端(R2、S3、GitHub) - 添加完整的前端界面:列表/网格视图、文件操作、批量管理 - 添加深色/浅色主题支持 - 迁移至 Jinja2 模板继承架构 - 添加完整的 API 文档和项目文档 - 优化 Vercel 部署配置
This commit is contained in:
705
static/css/main.css
Normal file
705
static/css/main.css
Normal file
@@ -0,0 +1,705 @@
|
||||
:root {
|
||||
--bg-color: #f5f5f5;
|
||||
--container-bg: white;
|
||||
--text-color: #2c3e50;
|
||||
--border-color: #eee;
|
||||
--hover-bg: #f8f9fa;
|
||||
--secondary-text: #6c757d;
|
||||
--link-color: #007bff;
|
||||
--folder-color: #ffc107;
|
||||
--file-color: #6c757d;
|
||||
--shadow-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--bg-color: #1a1a1a;
|
||||
--container-bg: #2d2d2d;
|
||||
--text-color: #e1e1e1;
|
||||
--border-color: #404040;
|
||||
--hover-bg: #363636;
|
||||
--secondary-text: #a0a0a0;
|
||||
--link-color: #66b3ff;
|
||||
--folder-color: #ffd54f;
|
||||
--file-color: #b0b0b0;
|
||||
--shadow-color: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: var(--bg-color);
|
||||
color: var(--text-color);
|
||||
transition: background-color 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
.container {
|
||||
background-color: var(--container-bg);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px var(--shadow-color);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: var(--text-color);
|
||||
margin-bottom: 30px;
|
||||
border-bottom: 2px solid var(--border-color);
|
||||
padding-bottom: 10px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* 通用按钮样式 */
|
||||
.btn {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 1em;
|
||||
transition: all 0.2s ease;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background-color: var(--hover-bg);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* 导航栏按钮 */
|
||||
.nav-btn {
|
||||
color: var(--secondary-text);
|
||||
font-size: 1.1em;
|
||||
padding: 8px 10px;
|
||||
}
|
||||
|
||||
.nav-btn:hover {
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
/* 兼容旧的类名 */
|
||||
.theme-toggle,
|
||||
.view-toggle {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--secondary-text);
|
||||
cursor: pointer;
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 1.1em;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.theme-toggle:hover,
|
||||
.view-toggle:hover {
|
||||
background-color: var(--hover-bg);
|
||||
color: var(--text-color);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.theme-toggle:active,
|
||||
.view-toggle:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* 导航栏删除按钮特殊样式 */
|
||||
.view-toggle[style*="color: #dc3545"]:hover {
|
||||
color: #c82333 !important;
|
||||
background-color: rgba(220, 53, 69, 0.1);
|
||||
}
|
||||
|
||||
/* Grid view styles */
|
||||
.grid-container {
|
||||
display: none;
|
||||
margin-top: 20px;
|
||||
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.grid-card {
|
||||
background: var(--container-bg);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
box-shadow: 0 1px 2px var(--shadow-color);
|
||||
}
|
||||
|
||||
.grid-checkbox {
|
||||
text-align: left;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.grid-checkbox input {
|
||||
transform: scale(1.05);
|
||||
accent-color: var(--link-color);
|
||||
}
|
||||
|
||||
.grid-thumb {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
object-fit: cover;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 8px;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.grid-name {
|
||||
display: block;
|
||||
font-size: 0.95em;
|
||||
color: var(--text-color);
|
||||
margin-bottom: 6px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* 网格卡片操作按钮 */
|
||||
.grid-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
justify-content: center;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.grid-action-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 4px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85em;
|
||||
transition: all 0.2s ease;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.grid-action-btn.preview {
|
||||
color: var(--link-color);
|
||||
}
|
||||
|
||||
.grid-action-btn.preview:hover {
|
||||
background-color: rgba(0, 123, 255, 0.1);
|
||||
}
|
||||
|
||||
.grid-action-btn.download {
|
||||
color: #28a745;
|
||||
}
|
||||
|
||||
.grid-action-btn.download:hover {
|
||||
background-color: rgba(40, 167, 69, 0.1);
|
||||
}
|
||||
|
||||
.grid-action-btn.delete {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.grid-action-btn.delete:hover {
|
||||
background-color: rgba(220, 53, 69, 0.1);
|
||||
}
|
||||
|
||||
/* Toggle visibility based on data-view on root */
|
||||
:root[data-view="grid"] .files-table {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:root[data-view="grid"] .grid-container {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
.files-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.checkbox-col {
|
||||
width: 48px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.checkbox-col input {
|
||||
transform: scale(1.05);
|
||||
accent-color: var(--link-color);
|
||||
}
|
||||
|
||||
.files-table th,
|
||||
.files-table td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.files-table th {
|
||||
background-color: var(--hover-bg);
|
||||
color: var(--text-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.files-table tr:hover {
|
||||
background-color: var(--hover-bg);
|
||||
}
|
||||
|
||||
.file-icon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.folder {
|
||||
color: var(--folder-color);
|
||||
}
|
||||
|
||||
.file {
|
||||
color: var(--file-color);
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--link-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
color: var(--secondary-text);
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.last-modified {
|
||||
color: var(--secondary-text);
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.empty-message {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: var(--secondary-text);
|
||||
}
|
||||
|
||||
.breadcrumb {
|
||||
margin-bottom: 12px;
|
||||
font-size: 0.95em;
|
||||
color: var(--secondary-text);
|
||||
background-color: var(--container-bg);
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* 页脚样式 */
|
||||
.site-footer {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
color: var(--secondary-text);
|
||||
font-size: 0.9em;
|
||||
padding: 14px 12px;
|
||||
}
|
||||
|
||||
.site-footer a {
|
||||
color: var(--link-color);
|
||||
text-decoration: none;
|
||||
margin: 0 6px;
|
||||
}
|
||||
|
||||
.site-footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.site-footer {
|
||||
font-size: 0.85em;
|
||||
padding: 12px 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* 文件上传输入框 */
|
||||
.upload-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* 删除按钮 */
|
||||
.delete-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #dc3545;
|
||||
cursor: pointer;
|
||||
padding: 6px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 0.9em;
|
||||
transition: all 0.2s ease;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.delete-btn:hover {
|
||||
background-color: rgba(220, 53, 69, 0.1);
|
||||
color: #c82333;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.delete-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* 操作链接按钮 */
|
||||
.action-link {
|
||||
color: var(--link-color);
|
||||
text-decoration: none;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
transition: all 0.2s ease;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.action-link:hover {
|
||||
background-color: var(--hover-bg);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* 预览按钮(button标签样式) */
|
||||
button.action-link {
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
font-size: 0.9em;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
/* 下载按钮 */
|
||||
.download-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #28a745;
|
||||
cursor: pointer;
|
||||
padding: 6px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 0.9em;
|
||||
transition: all 0.2s ease;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.download-btn:hover {
|
||||
background-color: rgba(40, 167, 69, 0.1);
|
||||
color: #218838;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.download-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* 预览模态框 */
|
||||
.preview-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.9);
|
||||
z-index: 1000;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.preview-modal.show {
|
||||
display: flex;
|
||||
opacity: 1;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.preview-container {
|
||||
position: relative;
|
||||
max-width: 90%;
|
||||
max-height: 90%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.preview-content {
|
||||
max-width: 100%;
|
||||
max-height: 85vh;
|
||||
object-fit: contain;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.preview-controls {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
z-index: 1001;
|
||||
}
|
||||
|
||||
.preview-btn {
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
border: none;
|
||||
color: #333;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
font-size: 1.2em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s ease;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.preview-btn:hover {
|
||||
background-color: white;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.preview-info {
|
||||
margin-top: 15px;
|
||||
color: white;
|
||||
text-align: center;
|
||||
font-size: 0.95em;
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
padding: 10px 20px;
|
||||
border-radius: 20px;
|
||||
max-width: 80%;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.preview-loading {
|
||||
color: white;
|
||||
font-size: 1.2em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.preview-error {
|
||||
color: #ff6b6b;
|
||||
font-size: 1.1em;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
video.preview-content {
|
||||
background-color: #000;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.preview-container {
|
||||
max-width: 95%;
|
||||
}
|
||||
|
||||
.preview-controls {
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
}
|
||||
|
||||
.preview-btn {
|
||||
width: 35px;
|
||||
height: 35px;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.preview-info {
|
||||
font-size: 0.85em;
|
||||
padding: 8px 15px;
|
||||
}
|
||||
}
|
||||
|
||||
/* 上传进度提示 */
|
||||
.upload-status {
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 10px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.upload-status.success {
|
||||
background-color: #d4edda;
|
||||
color: #155724;
|
||||
border: 1px solid #c3e6cb;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.upload-status.error {
|
||||
background-color: #f8d7da;
|
||||
color: #721c24;
|
||||
border: 1px solid #f5c6cb;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* 自定义对话框样式 */
|
||||
.app-dialog[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.app-dialog {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: rgba(0, 0, 0, 0.35);
|
||||
backdrop-filter: blur(2px);
|
||||
z-index: 1100;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.app-dialog.is-visible {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.app-dialog__backdrop {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
|
||||
.app-dialog__panel {
|
||||
position: relative;
|
||||
background-color: var(--container-bg);
|
||||
color: var(--text-color);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
|
||||
padding: 24px;
|
||||
min-width: 320px;
|
||||
max-width: min(420px, 90vw);
|
||||
transform: translateY(20px);
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.app-dialog.is-visible .app-dialog__panel {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.app-dialog__title {
|
||||
margin: 0 0 12px;
|
||||
font-size: 1.15em;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.app-dialog__message {
|
||||
margin-bottom: 18px;
|
||||
line-height: 1.5;
|
||||
color: var(--text-color);
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.app-dialog__input {
|
||||
margin-bottom: 18px;
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.app-dialog__input input {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--border-color);
|
||||
background-color: var(--container-bg);
|
||||
color: var(--text-color);
|
||||
font-size: 0.95em;
|
||||
box-sizing: border-box;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.app-dialog__input input::placeholder {
|
||||
color: var(--secondary-text);
|
||||
}
|
||||
|
||||
.app-dialog__input input:focus {
|
||||
outline: none;
|
||||
border-color: var(--link-color);
|
||||
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.15);
|
||||
}
|
||||
|
||||
.app-dialog__actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.app-dialog__btn {
|
||||
padding: 8px 16px;
|
||||
border-radius: 6px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 0.95em;
|
||||
transition: transform 0.15s ease, background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.app-dialog__btn:hover {
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.app-dialog__cancel {
|
||||
background-color: var(--hover-bg);
|
||||
color: var(--secondary-text);
|
||||
}
|
||||
|
||||
.app-dialog__cancel:hover {
|
||||
background-color: rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.app-dialog__confirm {
|
||||
background-color: #dc3545;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.app-dialog__confirm:hover {
|
||||
background-color: #c82333;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.app-dialog__panel {
|
||||
width: calc(100vw - 40px);
|
||||
padding: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.action-link:hover,
|
||||
.grid-action-btn:hover {
|
||||
color: var(--link-hover-color);
|
||||
background-color: var(--hover-bg-color);
|
||||
}
|
||||
|
||||
#deleteTrigger,
|
||||
.delete-btn,
|
||||
.grid-action-btn.delete {
|
||||
color: var(--danger-color, #dc3545);
|
||||
}
|
||||
|
||||
#deleteTrigger:hover,
|
||||
.delete-btn:hover,
|
||||
.grid-action-btn.delete:hover {
|
||||
color: var(--danger-hover-color, #a0202d);
|
||||
}
|
||||
|
||||
.rename-btn,
|
||||
.grid-action-btn.rename {
|
||||
color: var(--warning-color, #ffc107);
|
||||
}
|
||||
|
||||
.rename-btn:hover,
|
||||
.grid-action-btn.rename:hover {
|
||||
color: var(--warning-hover-color, #e0a800);
|
||||
}
|
||||
947
static/js/main.js
Normal file
947
static/js/main.js
Normal file
@@ -0,0 +1,947 @@
|
||||
(function () {
|
||||
function updateStatus(message, state) {
|
||||
const statusDiv = document.getElementById("uploadStatus");
|
||||
if (!statusDiv) {
|
||||
return null;
|
||||
}
|
||||
|
||||
statusDiv.textContent = message;
|
||||
statusDiv.className = "upload-status" + (state ? ` ${state}` : "");
|
||||
statusDiv.style.display = "block";
|
||||
return statusDiv;
|
||||
}
|
||||
|
||||
function hideStatusLater(statusDiv, delay = 2000) {
|
||||
if (!statusDiv) {
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
statusDiv.style.display = "none";
|
||||
}, delay);
|
||||
}
|
||||
|
||||
const dialogState = {
|
||||
container: null,
|
||||
title: null,
|
||||
message: null,
|
||||
inputWrapper: null,
|
||||
input: null,
|
||||
confirmBtn: null,
|
||||
cancelBtn: null,
|
||||
resolve: null,
|
||||
options: null,
|
||||
previousActiveElement: null,
|
||||
};
|
||||
|
||||
function isDialogOpen() {
|
||||
return Boolean(dialogState.container && !dialogState.container.hasAttribute("hidden"));
|
||||
}
|
||||
|
||||
function closeDialog(confirmed) {
|
||||
if (!dialogState.resolve || !dialogState.container) {
|
||||
return;
|
||||
}
|
||||
|
||||
const showInput = dialogState.options?.showInput;
|
||||
const value = confirmed && showInput && dialogState.input ? dialogState.input.value : undefined;
|
||||
|
||||
dialogState.container.classList.remove("is-visible");
|
||||
dialogState.container.setAttribute("aria-hidden", "true");
|
||||
|
||||
window.setTimeout(() => {
|
||||
if (!dialogState.container.classList.contains("is-visible")) {
|
||||
dialogState.container.setAttribute("hidden", "");
|
||||
}
|
||||
}, 200);
|
||||
|
||||
if (dialogState.inputWrapper) {
|
||||
dialogState.inputWrapper.hidden = true;
|
||||
}
|
||||
|
||||
const resolve = dialogState.resolve;
|
||||
dialogState.resolve = null;
|
||||
const options = dialogState.options || {};
|
||||
dialogState.options = null;
|
||||
|
||||
if (dialogState.previousActiveElement && typeof dialogState.previousActiveElement.focus === "function") {
|
||||
dialogState.previousActiveElement.focus({ preventScroll: true });
|
||||
}
|
||||
dialogState.previousActiveElement = null;
|
||||
|
||||
resolve({
|
||||
confirmed,
|
||||
value: value !== undefined ? value : undefined,
|
||||
options,
|
||||
});
|
||||
}
|
||||
|
||||
function openDialog(options) {
|
||||
if (!dialogState.container) {
|
||||
return Promise.resolve({ confirmed: false });
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
dialogState.resolve = resolve;
|
||||
dialogState.options = options;
|
||||
dialogState.previousActiveElement =
|
||||
document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
|
||||
dialogState.container.removeAttribute("hidden");
|
||||
dialogState.container.setAttribute("aria-hidden", "false");
|
||||
|
||||
if (dialogState.title) {
|
||||
dialogState.title.textContent = options.title || "";
|
||||
dialogState.title.hidden = !options.title;
|
||||
}
|
||||
|
||||
if (dialogState.message) {
|
||||
dialogState.message.textContent = options.message || "";
|
||||
}
|
||||
|
||||
if (dialogState.inputWrapper && dialogState.input) {
|
||||
dialogState.inputWrapper.hidden = !options.showInput;
|
||||
dialogState.input.value = options.defaultValue || "";
|
||||
dialogState.input.placeholder = options.placeholder || "";
|
||||
}
|
||||
|
||||
if (dialogState.confirmBtn) {
|
||||
dialogState.confirmBtn.textContent = options.confirmLabel || "确定";
|
||||
}
|
||||
|
||||
if (dialogState.cancelBtn) {
|
||||
dialogState.cancelBtn.textContent = options.cancelLabel || "取消";
|
||||
dialogState.cancelBtn.hidden = options.hideCancel || false;
|
||||
}
|
||||
|
||||
window.requestAnimationFrame(() => {
|
||||
if (!dialogState.container) {
|
||||
return;
|
||||
}
|
||||
dialogState.container.classList.add("is-visible");
|
||||
|
||||
if (options.showInput && dialogState.input) {
|
||||
dialogState.input.focus();
|
||||
dialogState.input.select();
|
||||
} else if (dialogState.confirmBtn) {
|
||||
dialogState.confirmBtn.focus();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initDialog() {
|
||||
const container = document.getElementById("appDialog");
|
||||
if (!container || container.dataset.initialized === "true") {
|
||||
return;
|
||||
}
|
||||
|
||||
container.dataset.initialized = "true";
|
||||
dialogState.container = container;
|
||||
dialogState.title = document.getElementById("appDialogTitle");
|
||||
dialogState.message = document.getElementById("appDialogMessage");
|
||||
dialogState.inputWrapper = document.getElementById("appDialogInputWrapper");
|
||||
dialogState.input = document.getElementById("appDialogInput");
|
||||
dialogState.confirmBtn = document.getElementById("appDialogConfirm");
|
||||
dialogState.cancelBtn = document.getElementById("appDialogCancel");
|
||||
|
||||
if (dialogState.confirmBtn) {
|
||||
dialogState.confirmBtn.addEventListener("click", () => closeDialog(true));
|
||||
}
|
||||
|
||||
if (dialogState.cancelBtn) {
|
||||
dialogState.cancelBtn.addEventListener("click", () => closeDialog(false));
|
||||
}
|
||||
|
||||
container.addEventListener("click", (event) => {
|
||||
if (
|
||||
event.target === container ||
|
||||
(event.target instanceof HTMLElement && event.target.dataset.dialogDismiss === "true")
|
||||
) {
|
||||
closeDialog(false);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (!isDialogOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
closeDialog(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.key === "Enter" && dialogState.options?.showInput) {
|
||||
const active = document.activeElement;
|
||||
if (active === dialogState.input) {
|
||||
event.preventDefault();
|
||||
closeDialog(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showConfirm(message, options = {}) {
|
||||
return openDialog({
|
||||
title: options.title || "确认操作",
|
||||
message,
|
||||
confirmLabel: options.confirmLabel || "确定",
|
||||
cancelLabel: options.cancelLabel || "取消",
|
||||
hideCancel: options.hideCancel || false,
|
||||
}).then((result) => Boolean(result.confirmed));
|
||||
}
|
||||
|
||||
async function showPrompt(message, options = {}) {
|
||||
const result = await openDialog({
|
||||
title: options.title || "请输入内容",
|
||||
message,
|
||||
confirmLabel: options.confirmLabel || "确定",
|
||||
cancelLabel: options.cancelLabel || "取消",
|
||||
showInput: true,
|
||||
defaultValue: options.defaultValue || "",
|
||||
placeholder: options.placeholder || "",
|
||||
});
|
||||
|
||||
if (!result.confirmed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const value = typeof result.value === "string" ? result.value.trim() : "";
|
||||
return value === "" ? null : value;
|
||||
}
|
||||
|
||||
function initThemeAndView() {
|
||||
const themeToggle = document.getElementById("themeToggle");
|
||||
const viewToggle = document.getElementById("viewToggle");
|
||||
|
||||
if (!themeToggle || !viewToggle) {
|
||||
return;
|
||||
}
|
||||
|
||||
const themeIcon = themeToggle.querySelector("i");
|
||||
const viewIcon = viewToggle.querySelector("i");
|
||||
|
||||
const savedTheme = localStorage.getItem("theme");
|
||||
if (savedTheme === "dark") {
|
||||
document.documentElement.setAttribute("data-theme", "dark");
|
||||
if (themeIcon) {
|
||||
themeIcon.classList.remove("fa-moon");
|
||||
themeIcon.classList.add("fa-sun");
|
||||
}
|
||||
}
|
||||
|
||||
const savedView = localStorage.getItem("view") || "list";
|
||||
document.documentElement.setAttribute("data-view", savedView);
|
||||
if (viewIcon) {
|
||||
if (savedView === "grid") {
|
||||
viewIcon.classList.remove("fa-th-large");
|
||||
viewIcon.classList.add("fa-th-list");
|
||||
} else {
|
||||
viewIcon.classList.remove("fa-th-list");
|
||||
viewIcon.classList.add("fa-th-large");
|
||||
}
|
||||
}
|
||||
|
||||
viewToggle.addEventListener("click", () => {
|
||||
const current = document.documentElement.getAttribute("data-view") || "list";
|
||||
const next = current === "grid" ? "list" : "grid";
|
||||
document.documentElement.setAttribute("data-view", next);
|
||||
localStorage.setItem("view", next);
|
||||
|
||||
if (!viewIcon) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (next === "grid") {
|
||||
viewIcon.classList.remove("fa-th-large");
|
||||
viewIcon.classList.add("fa-th-list");
|
||||
} else {
|
||||
viewIcon.classList.remove("fa-th-list");
|
||||
viewIcon.classList.add("fa-th-large");
|
||||
}
|
||||
});
|
||||
|
||||
themeToggle.addEventListener("click", () => {
|
||||
const currentTheme = document.documentElement.getAttribute("data-theme");
|
||||
const newTheme = currentTheme === "dark" ? "light" : "dark";
|
||||
|
||||
document.documentElement.setAttribute("data-theme", newTheme);
|
||||
localStorage.setItem("theme", newTheme);
|
||||
|
||||
if (!themeIcon) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newTheme === "dark") {
|
||||
themeIcon.classList.remove("fa-moon");
|
||||
themeIcon.classList.add("fa-sun");
|
||||
} else {
|
||||
themeIcon.classList.remove("fa-sun");
|
||||
themeIcon.classList.add("fa-moon");
|
||||
}
|
||||
});
|
||||
|
||||
if (!savedTheme) {
|
||||
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
if (prefersDark) {
|
||||
document.documentElement.setAttribute("data-theme", "dark");
|
||||
if (themeIcon) {
|
||||
themeIcon.classList.remove("fa-moon");
|
||||
themeIcon.classList.add("fa-sun");
|
||||
}
|
||||
localStorage.setItem("theme", "dark");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function registerServiceWorker() {
|
||||
if (!("serviceWorker" in navigator)) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker
|
||||
.register("/static/sw.js")
|
||||
.then((registration) => {
|
||||
console.log("SW registered:", registration);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("SW registration failed:", error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function registerModalHandlers() {
|
||||
const modal = document.getElementById("previewModal");
|
||||
if (!modal) {
|
||||
return;
|
||||
}
|
||||
|
||||
modal.addEventListener("click", (event) => {
|
||||
if (event.target === modal) {
|
||||
closePreview();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape" && !isDialogOpen()) {
|
||||
closePreview();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function uploadFiles(files) {
|
||||
const currentPrefix = document.body.dataset.currentPrefix || "";
|
||||
|
||||
for (const file of files) {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("prefix", currentPrefix);
|
||||
|
||||
try {
|
||||
updateStatus(`正在上传: ${file.name}...`, null);
|
||||
|
||||
const response = await fetch("/upload", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const statusDiv = updateStatus(`✓ ${file.name} 上传成功!`, "success");
|
||||
hideStatusLater(statusDiv);
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
} else {
|
||||
updateStatus(`✗ ${file.name} 上传失败: ${result.error}`, "error");
|
||||
}
|
||||
} catch (error) {
|
||||
updateStatus(`✗ ${file.name} 上传失败: ${error.message}`, "error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function promptDelete() {
|
||||
const suggested = "";
|
||||
const path = await showPrompt("请输入要删除的文件路径(相对于存储桶),例如:folder/file.jpg", {
|
||||
title: "删除文件",
|
||||
defaultValue: suggested,
|
||||
placeholder: "folder/file.jpg",
|
||||
confirmLabel: "删除",
|
||||
});
|
||||
|
||||
if (path) {
|
||||
await deleteFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteFolder(prefix) {
|
||||
const confirmed = await showConfirm(`确定要删除文件夹 "${prefix}" 及其所有内容吗?此操作不可逆!`, {
|
||||
title: "删除文件夹",
|
||||
confirmLabel: "确认删除",
|
||||
});
|
||||
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateStatus(`正在删除文件夹: ${prefix}...`, null);
|
||||
|
||||
try {
|
||||
const response = await fetch(`/delete_folder/${prefix}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const statusDiv = updateStatus("✓ 文件夹删除成功!", "success");
|
||||
hideStatusLater(statusDiv);
|
||||
|
||||
setTimeout(() => {
|
||||
// 返回上一级目录
|
||||
const parentPath = prefix.split("/").slice(0, -2).join("/");
|
||||
window.location.href = parentPath ? `/${parentPath}` : "/";
|
||||
}, 1500);
|
||||
} else {
|
||||
updateStatus(`✗ 删除失败: ${result.error}`, "error");
|
||||
}
|
||||
} catch (error) {
|
||||
updateStatus(`✗ 删除失败: ${error.message}`, "error");
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteFile(filePath, options = {}) {
|
||||
const { skipConfirm = false, suppressReload = false, suppressStatus = false } = options;
|
||||
|
||||
if (!skipConfirm) {
|
||||
const confirmed = await showConfirm(`确定要删除 "${filePath}" 吗?`, {
|
||||
title: "删除文件",
|
||||
confirmLabel: "删除",
|
||||
});
|
||||
|
||||
if (!confirmed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!suppressStatus) {
|
||||
updateStatus(`正在删除: ${filePath}...`, null);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/delete/${filePath}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
if (!suppressStatus) {
|
||||
const statusDiv = updateStatus("✓ 文件删除成功!", "success");
|
||||
hideStatusLater(statusDiv);
|
||||
}
|
||||
|
||||
if (!suppressReload) {
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!suppressStatus) {
|
||||
updateStatus(`✗ 删除失败: ${result.error}`, "error");
|
||||
}
|
||||
return false;
|
||||
} catch (error) {
|
||||
if (!suppressStatus) {
|
||||
updateStatus(`✗ 删除失败: ${error.message}`, "error");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getEntryCheckboxes() {
|
||||
return document.querySelectorAll(".entry-checkbox");
|
||||
}
|
||||
|
||||
function updateSelectAllState() {
|
||||
const master = document.getElementById("selectAll");
|
||||
if (!master) {
|
||||
return;
|
||||
}
|
||||
|
||||
const checkboxes = Array.from(getEntryCheckboxes());
|
||||
if (checkboxes.length === 0) {
|
||||
master.checked = false;
|
||||
master.indeterminate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const checkedCount = checkboxes.filter((checkbox) => checkbox.checked).length;
|
||||
|
||||
if (checkedCount === 0) {
|
||||
master.checked = false;
|
||||
master.indeterminate = false;
|
||||
} else if (checkedCount === checkboxes.length) {
|
||||
master.checked = true;
|
||||
master.indeterminate = false;
|
||||
} else {
|
||||
master.checked = false;
|
||||
master.indeterminate = true;
|
||||
}
|
||||
}
|
||||
|
||||
function toggleSelectAll(master) {
|
||||
const checkboxes = getEntryCheckboxes();
|
||||
const desiredState = Boolean(master.checked);
|
||||
|
||||
checkboxes.forEach((checkbox) => {
|
||||
checkbox.checked = desiredState;
|
||||
});
|
||||
|
||||
master.indeterminate = false;
|
||||
updateSelectAllState();
|
||||
}
|
||||
|
||||
function attachEntryCheckboxListeners() {
|
||||
const master = document.getElementById("selectAll");
|
||||
if (master && !master.dataset.listenerAttached) {
|
||||
master.addEventListener("change", () => toggleSelectAll(master));
|
||||
master.dataset.listenerAttached = "true";
|
||||
}
|
||||
|
||||
getEntryCheckboxes().forEach((checkbox) => {
|
||||
if (!checkbox.dataset.listenerAttached) {
|
||||
checkbox.addEventListener("change", updateSelectAllState);
|
||||
checkbox.dataset.listenerAttached = "true";
|
||||
}
|
||||
});
|
||||
|
||||
updateSelectAllState();
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
const statusDiv = updateStatus(`✓ 开始下载: ${filename || ""}`, "success");
|
||||
hideStatusLater(statusDiv);
|
||||
}
|
||||
|
||||
async function deleteSelectedEntries() {
|
||||
const selected = Array.from(getEntryCheckboxes()).filter((checkbox) => checkbox.checked);
|
||||
|
||||
if (selected.length === 0) {
|
||||
const statusDiv = updateStatus("✗ 请先选择要删除的项目", "error");
|
||||
hideStatusLater(statusDiv);
|
||||
return;
|
||||
}
|
||||
|
||||
const directories = selected.filter((checkbox) => checkbox.dataset.type === "dir");
|
||||
if (directories.length > 0) {
|
||||
const statusDiv = updateStatus("✗ 暂不支持批量删除文件夹,请仅选择文件", "error");
|
||||
hideStatusLater(statusDiv);
|
||||
return;
|
||||
}
|
||||
|
||||
const files = selected.map((checkbox) => checkbox.value);
|
||||
const confirmMessage =
|
||||
files.length === 1 ? `确定要删除 "${files[0]}" 吗?` : `确定要删除选中的 ${files.length} 个文件吗?`;
|
||||
|
||||
const confirmed = await showConfirm(confirmMessage, {
|
||||
title: "批量删除",
|
||||
confirmLabel: "删除",
|
||||
});
|
||||
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const deleteButton = document.getElementById("deleteTrigger");
|
||||
if (deleteButton) {
|
||||
deleteButton.disabled = true;
|
||||
deleteButton.classList.add("is-disabled");
|
||||
}
|
||||
|
||||
const inProgressStatus = updateStatus(`正在删除 ${files.length} 个文件...`, null);
|
||||
|
||||
const failures = [];
|
||||
let successCount = 0;
|
||||
|
||||
for (const filePath of files) {
|
||||
// 跳过额外提示和页面刷新,在批量完成后统一处理
|
||||
const result = await deleteFile(filePath, {
|
||||
skipConfirm: true,
|
||||
suppressReload: true,
|
||||
suppressStatus: true,
|
||||
});
|
||||
|
||||
if (result) {
|
||||
successCount += 1;
|
||||
} else {
|
||||
failures.push(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
if (deleteButton) {
|
||||
deleteButton.disabled = false;
|
||||
deleteButton.classList.remove("is-disabled");
|
||||
}
|
||||
|
||||
if (inProgressStatus) {
|
||||
inProgressStatus.style.display = "none";
|
||||
}
|
||||
|
||||
if (failures.length === 0 && successCount > 0) {
|
||||
const statusDiv = updateStatus(`✓ 已删除 ${successCount} 个文件`, "success");
|
||||
hideStatusLater(statusDiv, 3000);
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
if (failures.length > 0) {
|
||||
const message =
|
||||
failures.length === files.length
|
||||
? "✗ 删除失败,请稍后重试"
|
||||
: `删除部分文件失败:${failures.join(", ")}`;
|
||||
const statusDiv = updateStatus(message, "error");
|
||||
hideStatusLater(statusDiv, 4000);
|
||||
|
||||
if (successCount > 0) {
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function promptRename(oldKey, oldName, isFolder = false) {
|
||||
const title = isFolder ? "重命名文件夹" : "重命名文件";
|
||||
const newName = await showPrompt(`请输入新的名称:`, {
|
||||
title: title,
|
||||
defaultValue: oldName,
|
||||
confirmLabel: "重命名",
|
||||
});
|
||||
|
||||
if (newName && newName !== oldName) {
|
||||
if (isFolder) {
|
||||
await renameFolder(oldKey, newName);
|
||||
} else {
|
||||
await renameFile(oldKey, newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function renameFile(oldKey, newName) {
|
||||
updateStatus(`正在重命名: ${oldKey}...`, null);
|
||||
|
||||
try {
|
||||
const response = await fetch(`/rename/${oldKey}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ newName: newName }),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const statusDiv = updateStatus("✓ 文件重命名成功!", "success");
|
||||
hideStatusLater(statusDiv);
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1500);
|
||||
} else {
|
||||
updateStatus(`✗ 重命名失败: ${result.error}`, "error");
|
||||
}
|
||||
} catch (error) {
|
||||
updateStatus(`✗ 重命名失败: ${error.message}`, "error");
|
||||
}
|
||||
}
|
||||
|
||||
async function renameFolder(oldPrefix, newName) {
|
||||
updateStatus(`正在重命名文件夹: ${oldPrefix}...`, null);
|
||||
|
||||
try {
|
||||
const response = await fetch(`/rename_folder/${oldPrefix}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ newName: newName }),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const statusDiv = updateStatus("✓ 文件夹重命名成功!", "success");
|
||||
hideStatusLater(statusDiv);
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1500);
|
||||
} else {
|
||||
updateStatus(`✗ 重命名失败: ${result.error}`, "error");
|
||||
}
|
||||
} catch (error) {
|
||||
updateStatus(`✗ 重命名失败: ${error.message}`, "error");
|
||||
}
|
||||
}
|
||||
|
||||
async function promptCopyOrMove(source, isFolder, operation) {
|
||||
const opText = operation === "copy" ? "复制" : "移动";
|
||||
const itemText = isFolder ? "文件夹" : "文件";
|
||||
const dest = await showPrompt(`请输入目标目录路径:`, {
|
||||
title: `${opText}${itemText}`,
|
||||
confirmLabel: opText,
|
||||
});
|
||||
|
||||
if (dest) {
|
||||
// 确保 dest 以 / 结尾
|
||||
let normalizedDest = dest;
|
||||
if (!normalizedDest.endsWith("/")) {
|
||||
normalizedDest += "/";
|
||||
}
|
||||
// 提取源名称
|
||||
let name = source
|
||||
.split("/")
|
||||
.filter((p) => p)
|
||||
.pop();
|
||||
if (isFolder) {
|
||||
name += "/";
|
||||
}
|
||||
const fullDest = normalizedDest + name;
|
||||
|
||||
if (operation === "copy") {
|
||||
await copyItem(source, fullDest, isFolder);
|
||||
} else {
|
||||
await moveItem(source, fullDest, isFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function copyItem(source, destination, isFolder) {
|
||||
updateStatus(`正在复制...`, null);
|
||||
await performOperation("/copy", "复制", { source, destination, is_folder: isFolder });
|
||||
}
|
||||
|
||||
async function moveItem(source, destination, isFolder) {
|
||||
updateStatus(`正在移动...`, null);
|
||||
await performOperation("/move", "移动", { source, destination, is_folder: isFolder });
|
||||
}
|
||||
|
||||
async function performOperation(endpoint, opText, body) {
|
||||
try {
|
||||
const response = await fetch(endpoint, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const statusDiv = updateStatus(`✓ ${opText}成功!`, "success");
|
||||
hideStatusLater(statusDiv);
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1500);
|
||||
} else {
|
||||
updateStatus(`✗ ${opText}失败: ${result.error}`, "error");
|
||||
}
|
||||
} catch (error) {
|
||||
updateStatus(`✗ ${opText}失败: ${error.message}`, "error");
|
||||
}
|
||||
}
|
||||
|
||||
function getFileType(filename) {
|
||||
const extension = filename.toLowerCase().split(".").pop();
|
||||
const imageExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", "ico"];
|
||||
const videoExtensions = ["mp4", "webm", "ogg", "mov", "avi", "mkv", "m4v"];
|
||||
|
||||
if (imageExtensions.includes(extension)) {
|
||||
return "image";
|
||||
}
|
||||
if (videoExtensions.includes(extension)) {
|
||||
return "video";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
function openPreview(url, filename) {
|
||||
const modal = document.getElementById("previewModal");
|
||||
const container = document.getElementById("previewContainer");
|
||||
const info = document.getElementById("previewInfo");
|
||||
|
||||
if (!modal || !container || !info) {
|
||||
window.open(url, "_blank");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileType = getFileType(filename);
|
||||
|
||||
if (fileType === "unknown") {
|
||||
window.open(url, "_blank");
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = '<div class="preview-loading">加载中...</div>';
|
||||
info.textContent = filename;
|
||||
modal.classList.add("show");
|
||||
document.body.style.overflow = "hidden";
|
||||
|
||||
setTimeout(() => {
|
||||
if (fileType === "image") {
|
||||
const image = document.createElement("img");
|
||||
image.className = "preview-content";
|
||||
image.src = url;
|
||||
image.alt = filename;
|
||||
|
||||
image.onload = () => {
|
||||
container.innerHTML = "";
|
||||
container.appendChild(image);
|
||||
};
|
||||
|
||||
image.onerror = () => {
|
||||
container.innerHTML = '<div class="preview-error">图片加载失败</div>';
|
||||
};
|
||||
} else if (fileType === "video") {
|
||||
const video = document.createElement("video");
|
||||
video.className = "preview-content";
|
||||
video.src = url;
|
||||
video.controls = true;
|
||||
video.autoplay = false;
|
||||
|
||||
video.onloadedmetadata = () => {
|
||||
container.innerHTML = "";
|
||||
container.appendChild(video);
|
||||
};
|
||||
|
||||
video.onerror = () => {
|
||||
container.innerHTML = '<div class="preview-error">视频加载失败</div>';
|
||||
};
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function closePreview() {
|
||||
const modal = document.getElementById("previewModal");
|
||||
const container = document.getElementById("previewContainer");
|
||||
|
||||
if (!modal || !container) {
|
||||
return;
|
||||
}
|
||||
|
||||
modal.classList.remove("show");
|
||||
document.body.style.overflow = "";
|
||||
|
||||
setTimeout(() => {
|
||||
container.innerHTML = "";
|
||||
}, 300);
|
||||
}
|
||||
|
||||
function downloadPreview() {
|
||||
const container = document.getElementById("previewContainer");
|
||||
const info = document.getElementById("previewInfo");
|
||||
|
||||
if (!container || !info) {
|
||||
return;
|
||||
}
|
||||
|
||||
const media = container.querySelector(".preview-content");
|
||||
if (media && media.src) {
|
||||
downloadFile(media.src, info.textContent);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
initDialog();
|
||||
initThemeAndView();
|
||||
registerModalHandlers();
|
||||
registerServiceWorker();
|
||||
attachEntryCheckboxListeners();
|
||||
});
|
||||
|
||||
window.uploadFiles = uploadFiles;
|
||||
window.promptDelete = promptDelete;
|
||||
window.deleteFile = deleteFile;
|
||||
window.deleteSelectedEntries = deleteSelectedEntries;
|
||||
window.toggleSelectAll = (master) => toggleSelectAll(master);
|
||||
window.downloadFile = downloadFile;
|
||||
window.openPreview = openPreview;
|
||||
window.closePreview = closePreview;
|
||||
window.downloadPreview = downloadPreview;
|
||||
window.promptRename = promptRename;
|
||||
window.deleteFolder = deleteFolder;
|
||||
window.promptCopyOrMove = promptCopyOrMove;
|
||||
|
||||
async function promptCreateFolder() {
|
||||
const currentPrefix = document.body.dataset.currentPrefix || "";
|
||||
const folderName = await showPrompt("请输入新文件夹的名称:", {
|
||||
title: "新建文件夹",
|
||||
confirmLabel: "创建",
|
||||
});
|
||||
|
||||
if (folderName) {
|
||||
const path = currentPrefix + folderName;
|
||||
await createFolder(path);
|
||||
}
|
||||
}
|
||||
|
||||
async function createFolder(path) {
|
||||
updateStatus(`正在创建文件夹: ${path}...`, null);
|
||||
|
||||
try {
|
||||
const response = await fetch(`/create_folder`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ path: path }),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const statusDiv = updateStatus("✓ 文件夹创建成功!", "success");
|
||||
hideStatusLater(statusDiv);
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1500);
|
||||
} else {
|
||||
updateStatus(`✗ 创建失败: ${result.error}`, "error");
|
||||
}
|
||||
} catch (error) {
|
||||
updateStatus(`✗ 创建失败: ${error.message}`, "error");
|
||||
}
|
||||
}
|
||||
window.promptCreateFolder = promptCreateFolder;
|
||||
})();
|
||||
37
static/sw.js
37
static/sw.js
@@ -1,37 +0,0 @@
|
||||
const CACHE_NAME = 'thumbnail-cache-v1';
|
||||
const THUMB_URL_PATTERN = /^\/thumb\//;
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(clients.claim());
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
const { request } = event;
|
||||
const url = new URL(request.url);
|
||||
|
||||
// 只缓存缩略图请求
|
||||
if (THUMB_URL_PATTERN.test(url.pathname)) {
|
||||
event.respondWith(
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
return cache.match(request).then((response) => {
|
||||
// 如果缓存中有响应,直接返回
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
// 否则发起网络请求,并将响应添加到缓存中
|
||||
return fetch(request).then((networkResponse) => {
|
||||
// 复制响应,因为流只能读取一次
|
||||
const responseToCache = networkResponse.clone();
|
||||
cache.put(request, responseToCache);
|
||||
return networkResponse;
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user