From 4f39b3a41ebf6e3ec629b1bbcbd7722dbc75c1d9 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 27 May 2025 23:48:33 -0400 Subject: [PATCH] Support clipboard paste image uploads with UI cleanup (closes #40) --- CHANGELOG.md | 7 +++++- public/js/adminPanel.js | 2 +- public/js/upload.js | 49 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c3a64a..421d629 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,17 @@ # Changelog -## Changes 5/27/2025 +## Changes 5/27/2025 v1.3.9 - Support for mounting CIFS (SMB) network shares via Docker volumes - New `scripts/scan_uploads.php` script to generate metadata for imported files and folders - `SCAN_ON_START` environment variable to trigger automatic scanning on container startup - Documentation for configuring CIFS share mounting and scanning +- Clipboard Paste Upload Support (single image): + - Users can now paste images directly into the FileRise web interface. + - Pasted images are renamed to `image.png` and added to the upload queue using the existing drag-and-drop logic. + - Implemented using a `.isClipboard` flag and a delayed UI cleanup inside `xhr.addEventListener("load", ...)`. + --- ## Changes 5/26/2025 diff --git a/public/js/adminPanel.js b/public/js/adminPanel.js index 2368925..94af402 100644 --- a/public/js/adminPanel.js +++ b/public/js/adminPanel.js @@ -3,7 +3,7 @@ import { loadAdminConfigFunc } from './auth.js'; import { showToast, toggleVisibility, attachEnterKeyListener } from './domUtils.js'; import { sendRequest } from './networkUtils.js'; -const version = "v1.3.8"; +const version = "v1.3.9"; const adminTitle = `${t("admin_panel")} ${version}`; // ————— Inject updated styles ————— diff --git a/public/js/upload.js b/public/js/upload.js index 1355ae3..4d4a9af 100644 --- a/public/js/upload.js +++ b/public/js/upload.js @@ -669,6 +669,18 @@ function submitFiles(allFiles) { } allSucceeded = false; } + if (file.isClipboard) { + setTimeout(() => { + window.selectedFiles = []; + updateFileInfoCount(); + const progressContainer = document.getElementById("uploadProgressContainer"); + if (progressContainer) progressContainer.innerHTML = ""; + const fileInfoContainer = document.getElementById("fileInfoContainer"); + if (fileInfoContainer) { + fileInfoContainer.innerHTML = `No files selected`; + } + }, 5000); + } // ─── Only now count this chunk as finished ─────────────────── finishedCount++; @@ -847,4 +859,39 @@ function initUpload() { } } -export { initUpload }; \ No newline at end of file +export { initUpload }; + +// ------------------------- +// Clipboard Paste Handler (Mimics Drag-and-Drop) +// ------------------------- +document.addEventListener('paste', function handlePasteUpload(e) { + const items = e.clipboardData?.items; + if (!items) return; + + const files = []; + + for (let i = 0; i < items.length; i++) { + const item = items[i]; + if (item.kind === 'file') { + const file = item.getAsFile(); + if (file) { + const ext = file.name.split('.').pop() || 'png'; + const renamedFile = new File([file], `image${Date.now()}.${ext}`, { type: file.type }); + renamedFile.isClipboard = true; + + Object.defineProperty(renamedFile, 'customRelativePath', { + value: renamedFile.name, + writable: true, + configurable: true + }); + + files.push(renamedFile); + } + } + } + + if (files.length > 0) { + processFiles(files); + showToast('Pasted file added to upload list.', 'success'); + } +}); \ No newline at end of file