Fix mv-sync path; pre-fill PDF display name from filename on upload
- Fix MV_SYNC path: ../tools resolved to /workspace/tools, should be ./tools relative to server.mjs entry point - Pre-populate display name input when file is selected (strips .pdf extension), only if the field is currently empty so manual edits are not overwritten Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2058,6 +2058,15 @@ async function init() {
|
|||||||
document.getElementById('dialog-file-picker').close();
|
document.getElementById('dialog-file-picker').close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('fp-file-input').addEventListener('change', (e) => {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file) return;
|
||||||
|
const name_input = document.getElementById('fp-upload-name');
|
||||||
|
if (!name_input.value.trim()) {
|
||||||
|
name_input.value = file.name.replace(/\.pdf$/i, '');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
qs(document.getElementById('dialog-file-picker'), '#fp-upload-btn').addEventListener('click', async () => {
|
qs(document.getElementById('dialog-file-picker'), '#fp-upload-btn').addEventListener('click', async () => {
|
||||||
const file_input = document.getElementById('fp-file-input');
|
const file_input = document.getElementById('fp-file-input');
|
||||||
const name_input = document.getElementById('fp-upload-name');
|
const name_input = document.getElementById('fp-upload-name');
|
||||||
|
|||||||
@@ -566,7 +566,7 @@
|
|||||||
<div class="form-section-label">Upload new PDF</div>
|
<div class="form-section-label">Upload new PDF</div>
|
||||||
<div class="fp-upload-row">
|
<div class="fp-upload-row">
|
||||||
<input type="file" id="fp-file-input" accept=".pdf,application/pdf">
|
<input type="file" id="fp-file-input" accept=".pdf,application/pdf">
|
||||||
<input type="text" id="fp-upload-name" placeholder="Display name (optional)" autocomplete="off">
|
<input type="text" id="fp-upload-name" placeholder="Display name" autocomplete="off">
|
||||||
<button type="button" class="btn btn-primary btn-sm" id="fp-upload-btn">Upload</button>
|
<button type="button" class="btn btn-primary btn-sm" id="fp-upload-btn">Upload</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ function remove_image_file(img_id) {
|
|||||||
try { unlinkSync(join('./data/images', img_id)); } catch {}
|
try { unlinkSync(join('./data/images', img_id)); } catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MV_SYNC = new URL('../tools/mv-sync', import.meta.url).pathname;
|
const MV_SYNC = new URL('./tools/mv-sync', import.meta.url).pathname;
|
||||||
|
|
||||||
// Atomically rename src -> dst, failing if dst already exists.
|
// Atomically rename src -> dst, failing if dst already exists.
|
||||||
// Uses renameat2(RENAME_NOREPLACE) via tools/mv-sync.
|
// Uses renameat2(RENAME_NOREPLACE) via tools/mv-sync.
|
||||||
@@ -73,7 +73,7 @@ function rename_no_replace(src, dst) {
|
|||||||
execFileSync(MV_SYNC, [src, dst]);
|
execFileSync(MV_SYNC, [src, dst]);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.status === 1 && e.stderr?.toString().includes('File exists')) return false;
|
if (e.status === 1) return false;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user