fix: reseed sets createdAt from filename timestamp or file mtime
Photos reseeded from disk now sort by their original upload time instead of all getting the same insertion timestamp. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
633f1e2380
commit
0e4461e957
@ -48,11 +48,17 @@ async function main() {
|
|||||||
const baseName = path.basename(file, path.extname(file));
|
const baseName = path.basename(file, path.extname(file));
|
||||||
const caption = baseName.replace(/[-_]+/g, ' ');
|
const caption = baseName.replace(/[-_]+/g, ' ');
|
||||||
const tag = baseName.split('-')[1] || 'uncategorized';
|
const tag = baseName.split('-')[1] || 'uncategorized';
|
||||||
|
const tsMatch = file.match(/^(\d{13})-/);
|
||||||
|
const createdAt = tsMatch
|
||||||
|
? new Date(parseInt(tsMatch[1]))
|
||||||
|
: fs.statSync(path.join(UPLOAD_DIR, file)).mtime;
|
||||||
const doc = new Photo({
|
const doc = new Photo({
|
||||||
filename: file,
|
filename: file,
|
||||||
path: path.join('uploads', file),
|
path: path.join('uploads', file),
|
||||||
caption,
|
caption,
|
||||||
tags: [tag],
|
tags: [tag],
|
||||||
|
createdAt,
|
||||||
|
updatedAt: createdAt,
|
||||||
});
|
});
|
||||||
await doc.save();
|
await doc.save();
|
||||||
created++;
|
created++;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user