Кнопка «Скачать» текущей версии фото (доступна при навигации по истории)
This commit is contained in:
@@ -34,6 +34,7 @@ const resultLabel = document.querySelector("#result-label");
|
||||
const jobStatus = document.querySelector("#job-status");
|
||||
const jobStatusText = document.querySelector("#job-status-text");
|
||||
const downloadLink = document.querySelector("#download-link");
|
||||
const downloadCurrent = document.querySelector("#download-current");
|
||||
|
||||
let currentVersionId = null;
|
||||
let historyVersions = [];
|
||||
@@ -61,6 +62,37 @@ function formatFileSize(bytes) {
|
||||
return `${(bytes / (1024 * 1024)).toFixed(1)} МБ`;
|
||||
}
|
||||
|
||||
function versionFileName(version) {
|
||||
const kindName = {
|
||||
original: "original",
|
||||
edit: "edited",
|
||||
upscale: "upscaled"
|
||||
}[version.kind] || "photo";
|
||||
|
||||
let stamp = "";
|
||||
try {
|
||||
const d = new Date(version.createdAt);
|
||||
stamp = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
||||
} catch {
|
||||
stamp = "photo";
|
||||
}
|
||||
|
||||
return `${kindName}-${stamp}.${version.ext || "jpg"}`;
|
||||
}
|
||||
|
||||
function updateDownloadCurrent(version) {
|
||||
if (!version) {
|
||||
downloadCurrent.hidden = true;
|
||||
downloadCurrent.removeAttribute("href");
|
||||
downloadCurrent.removeAttribute("download");
|
||||
return;
|
||||
}
|
||||
|
||||
downloadCurrent.href = version.url;
|
||||
downloadCurrent.download = versionFileName(version);
|
||||
downloadCurrent.hidden = false;
|
||||
}
|
||||
|
||||
function setHealthState(state, message, title = "") {
|
||||
healthStatus.className = `health-status health-${state}`;
|
||||
healthText.textContent = message;
|
||||
@@ -201,6 +233,7 @@ async function selectFile(file) {
|
||||
file.name,
|
||||
`${formatFileSize(file.size)} · готово к обработке`
|
||||
);
|
||||
updateDownloadCurrent(data.version);
|
||||
setJobStatus("", "");
|
||||
setBusy(false);
|
||||
} catch (error) {
|
||||
@@ -299,6 +332,7 @@ async function runJob(kind) {
|
||||
if (version) {
|
||||
historyVersions.push(version);
|
||||
currentVersionId = version.id;
|
||||
updateDownloadCurrent(version);
|
||||
renderHistory();
|
||||
}
|
||||
|
||||
@@ -428,6 +462,7 @@ function selectHistoryVersion(version) {
|
||||
currentVersionId = version.id;
|
||||
|
||||
resetResult();
|
||||
updateDownloadCurrent(version);
|
||||
showSourcePreviewFromUrl(
|
||||
version.url,
|
||||
version.label || "Версия",
|
||||
@@ -455,6 +490,7 @@ async function loadHistoryOnStart() {
|
||||
if (historyVersions.length > 0) {
|
||||
const latest = historyVersions[historyVersions.length - 1];
|
||||
currentVersionId = latest.id;
|
||||
updateDownloadCurrent(latest);
|
||||
showSourcePreviewFromUrl(
|
||||
latest.url,
|
||||
latest.label || "Текущая фотография",
|
||||
|
||||
Reference in New Issue
Block a user