fix: 修复任务空状态和浏览器刷新

This commit is contained in:
2026-06-20 13:14:47 +08:00
parent c2289f889e
commit ff73470142
9 changed files with 69 additions and 87 deletions
+25 -27
View File
@@ -1,8 +1,8 @@
// views/browser.js — file/folder listing with breadcrumbs, mkdir, upload, delete, rename.
import { post, uploadFile, downloadURL } from "../rc.js?v=job-stats-1";
import { toast, formatBytes, formatTime } from "../state.js?v=job-stats-1";
import { t } from "../i18n.js?v=job-stats-1";
import { post, uploadFile, downloadURL } from "../rc.js?v=review-fixes-1";
import { escapeHtml, toast, formatBytes, formatTime } from "../state.js?v=review-fixes-1";
import { t } from "../i18n.js?v=review-fixes-1";
export async function renderBrowse({ remote, path }) {
const app = document.getElementById("app");
@@ -37,18 +37,7 @@ export async function renderBrowse({ remote, path }) {
const card = document.getElementById("browser-card");
const fileInput = document.getElementById("upload-input");
try {
const res = await post("operations/list", {
fs,
remote: path || "",
opt: { noModTime: false, noMimeType: true, showHash: false },
});
const items = (res && res.list) || [];
renderTable(card, fs, path, items);
} catch (e) {
card.innerHTML = `<div class="empty"><h3>${t("error.couldnt_list")}</h3><p>${escapeHtml(e.message)}</p></div>`;
toast(`${t("browser.browse_failed")}: ${e.message}`, "error");
}
await refreshListing(card, fs, path);
app.querySelector('[data-action="mkdir"]').addEventListener("click", () => {
openModal(
@@ -61,6 +50,7 @@ export async function renderBrowse({ remote, path }) {
const target = path ? `${path}/${name}` : name;
await post("operations/mkdir", { fs, remote: target });
toast(t("browser.mkdir_created", name), "success");
await refreshListing(card, fs, path);
},
).catch((e) => toast(`${t("browser.mkdir_failed")}: ${e.message}`, "error"));
});
@@ -76,13 +66,30 @@ export async function renderBrowse({ remote, path }) {
try {
await uploadFile(fs, path || "", files);
toast(t("browser.uploaded", files.length), "success");
location.reload();
await refreshListing(card, fs, path);
} catch (e) {
toast(`${t("browser.upload_failed")}: ${e.message}`, "error");
}
});
}
async function refreshListing(card, fs, path) {
if (!card) return;
card.innerHTML = `<p class="empty">${t("loading.title")}…</p>`;
try {
const res = await post("operations/list", {
fs,
remote: path || "",
opt: { noModTime: false, noMimeType: true, showHash: false },
});
const items = (res && res.list) || [];
renderTable(card, fs, path, items);
} catch (e) {
card.innerHTML = `<div class="empty"><h3>${t("error.couldnt_list")}</h3><p>${escapeHtml(e.message)}</p></div>`;
toast(`${t("browser.browse_failed")}: ${e.message}`, "error");
}
}
function renderBreadcrumbs(el, remote, path) {
const segments = (path || "").split("/").filter(Boolean);
let html = `<a href="#/remotes">${t("nav.remotes")}</a><span class="sep">/</span>`;
@@ -198,7 +205,7 @@ async function onDelete(fs, path, itemPath) {
try {
await post("operations/deletefile", { fs, remote: itemPath });
toast(t("browser.deleted", itemPath), "success");
location.reload();
await refreshListing(document.getElementById("browser-card"), fs, path);
} catch (e) {
toast(`${t("browser.delete_file_failed")}: ${e.message}`, "error");
}
@@ -224,7 +231,7 @@ async function onRename(fs, path, itemPath) {
toast(t("browser.renamed", name), "success");
},
);
location.reload();
await refreshListing(document.getElementById("browser-card"), fs, path);
} catch (e) {
toast(`${t("browser.rename_failed")}: ${e.message}`, "error");
}
@@ -289,12 +296,3 @@ export function openModal(title, fields, onSubmit) {
if (first) first.focus();
});
}
function escapeHtml(s) {
return String(s)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}
+3 -12
View File
@@ -9,9 +9,9 @@
// OAuth backends (option named "token" with IsPassword) get a banner
// and disabled submit — user must run `rclone config` in a terminal.
import { post } from "../rc.js?v=job-stats-1";
import { getState, setState, toast } from "../state.js?v=job-stats-1";
import { t } from "../i18n.js?v=job-stats-1";
import { post } from "../rc.js?v=review-fixes-1";
import { escapeHtml, getState, setState, toast } from "../state.js?v=review-fixes-1";
import { t } from "../i18n.js?v=review-fixes-1";
// --- Route entrypoints ---
@@ -426,15 +426,6 @@ async function ensureProviders() {
return providers;
}
function escapeHtml(s) {
return String(s)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}
function escapeAttr(s) {
return escapeHtml(s);
}
+11 -14
View File
@@ -1,13 +1,14 @@
// views/jobs.js — submit sync/copy/move jobs and manage recurring transfers.
import { post } from "../rc.js?v=job-stats-1";
import { post } from "../rc.js?v=review-fixes-1";
import {
toast,
formatBytes,
formatSpeed,
formatDuration,
} from "../state.js?v=job-stats-1";
import { t } from "../i18n.js?v=job-stats-1";
escapeHtml,
} from "../state.js?v=review-fixes-1";
import { t } from "../i18n.js?v=review-fixes-1";
import {
createOneTimeJob,
createRecurringJob,
@@ -20,7 +21,7 @@ import {
runRecurringJobNow,
stopOneTimeJob,
stopRecurringJob,
} from "../jobs_api.js?v=job-stats-1";
} from "../jobs_api.js?v=review-fixes-1";
let pollTimer = null;
const LOCAL_FS_VALUE = "__local__";
@@ -502,7 +503,7 @@ async function refreshJobs() {
card.innerHTML = `
<div class="empty">
<h3>${currentJobsView === "once" ? t("jobs.empty_once_title") : t("jobs.empty_recurring_title")}</h3>
<p>${t("jobs.empty_body").replace("New Job", `<a href="#/jobs/new">${t("jobs.new_btn")}</a>`)}</p>
<p>${emptyJobsBody()}</p>
</div>
`;
return false;
@@ -524,6 +525,11 @@ async function refreshJobs() {
return jobs.some((job) => job.running);
}
function emptyJobsBody() {
const link = `<a href="#/jobs/new">${escapeHtml(t("jobs.new_btn"))}</a>`;
return t("jobs.empty_body", link);
}
function renderJobTable(statuses) {
statuses.sort((a, b) => {
const bTime = Date.parse(b.updatedAt || b.createdAt || b.startedAt || 0) || 0;
@@ -890,15 +896,6 @@ function oneTimeIdFromKey(key) {
return Number(String(key).replace(/^once:/, ""));
}
function escapeHtml(s) {
return String(s)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}
function escapeAttr(s) {
return escapeHtml(s);
}
+3 -12
View File
@@ -1,8 +1,8 @@
// views/remotes.js — connector-tile grid of configured remotes with CRUD.
import { post } from "../rc.js?v=job-stats-1";
import { getState, setState, toast } from "../state.js?v=job-stats-1";
import { t } from "../i18n.js?v=job-stats-1";
import { post } from "../rc.js?v=review-fixes-1";
import { escapeHtml, getState, setState, toast } from "../state.js?v=review-fixes-1";
import { t } from "../i18n.js?v=review-fixes-1";
export async function renderRemotes() {
const app = document.getElementById("app");
@@ -94,12 +94,3 @@ export async function renderRemotes() {
toast(`${t("remotes.load_failed")}: ${e.message}`, "error");
}
}
function escapeHtml(s) {
return String(s)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}