Saving original filename to database for optional post-tagging
This commit is contained in:
@@ -844,7 +844,8 @@ CREATE TABLE public.items (
|
|||||||
has_coverart boolean DEFAULT false,
|
has_coverart boolean DEFAULT false,
|
||||||
is_pinned boolean DEFAULT false,
|
is_pinned boolean DEFAULT false,
|
||||||
is_oc boolean DEFAULT false,
|
is_oc boolean DEFAULT false,
|
||||||
xd_score integer DEFAULT 0 NOT NULL
|
xd_score integer DEFAULT 0 NOT NULL,
|
||||||
|
original_filename text
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ export default router => {
|
|||||||
group.get(/\/meta\/extract\/item\/(?<id>\d+)$/, lib.loggedin, async (req, res) => {
|
group.get(/\/meta\/extract\/item\/(?<id>\d+)$/, lib.loggedin, async (req, res) => {
|
||||||
const id = req.params.id;
|
const id = req.params.id;
|
||||||
try {
|
try {
|
||||||
const rows = await db`SELECT dest, mime FROM items WHERE id = ${id}`;
|
const rows = await db`SELECT dest, mime, original_filename FROM items WHERE id = ${id}`;
|
||||||
const item = rows[0];
|
const item = rows[0];
|
||||||
if (!item) return res.json({ success: false, msg: 'Item not found' }, 404);
|
if (!item) return res.json({ success: false, msg: 'Item not found' }, 404);
|
||||||
|
|
||||||
@@ -187,6 +187,14 @@ export default router => {
|
|||||||
results.push(val.substring(0, 255));
|
results.push(val.substring(0, 255));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Original filename is always surfaced first — most useful for tagging
|
||||||
|
if (item.original_filename) {
|
||||||
|
let baseName = item.original_filename;
|
||||||
|
const lastDot = baseName.lastIndexOf('.');
|
||||||
|
if (lastDot > 0) baseName = baseName.substring(0, lastDot);
|
||||||
|
addResult(baseName.trim());
|
||||||
|
}
|
||||||
|
|
||||||
if (item.mime.startsWith('image/')) {
|
if (item.mime.startsWith('image/')) {
|
||||||
// Use exiftool for images — reads EXIF, IPTC, XMP tags properly
|
// Use exiftool for images — reads EXIF, IPTC, XMP tags properly
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ const sendJson = (res, data, code = 200) => {
|
|||||||
res.end(JSON.stringify(data));
|
res.end(JSON.stringify(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// One-time migration: add original_filename column if it doesn't exist
|
||||||
|
db`ALTER TABLE items ADD COLUMN IF NOT EXISTS original_filename text`.catch(() => {});
|
||||||
|
|
||||||
export const handleUpload = async (req, res, self) => {
|
export const handleUpload = async (req, res, self) => {
|
||||||
// Manual session lookup is required here because this handler is called from a
|
// Manual session lookup is required here because this handler is called from a
|
||||||
// bypass middleware that runs in parallel with the main session middleware.
|
// bypass middleware that runs in parallel with the main session middleware.
|
||||||
@@ -294,6 +297,7 @@ export const handleUpload = async (req, res, self) => {
|
|||||||
const insertChecksum = getBypassDuplicateCheck() ? `${checksum}_bypass_${Date.now()}` : checksum;
|
const insertChecksum = getBypassDuplicateCheck() ? `${checksum}_bypass_${Date.now()}` : checksum;
|
||||||
|
|
||||||
// Insert
|
// Insert
|
||||||
|
const originalFilename = file.filename || null;
|
||||||
await db`
|
await db`
|
||||||
insert into items ${db({
|
insert into items ${db({
|
||||||
src: '',
|
src: '',
|
||||||
@@ -307,8 +311,9 @@ export const handleUpload = async (req, res, self) => {
|
|||||||
usernetwork: 'web',
|
usernetwork: 'web',
|
||||||
stamp: ~~(Date.now() / 1000),
|
stamp: ~~(Date.now() / 1000),
|
||||||
active: !manualApproval,
|
active: !manualApproval,
|
||||||
is_oc: is_oc
|
is_oc: is_oc,
|
||||||
}, 'src', 'dest', 'mime', 'size', 'checksum', 'phash', 'username', 'userchannel', 'usernetwork', 'stamp', 'active', 'is_oc')
|
original_filename: originalFilename
|
||||||
|
}, 'src', 'dest', 'mime', 'size', 'checksum', 'phash', 'username', 'userchannel', 'usernetwork', 'stamp', 'active', 'is_oc', 'original_filename')
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user