koguma 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -4
- package/src/admin/_bundle.ts +1 -1
- package/src/media/index.ts +11 -2
package/src/media/index.ts
CHANGED
|
@@ -217,16 +217,25 @@ export async function replaceMedia(c: Context): Promise<Response> {
|
|
|
217
217
|
const newKey = buildKey(id, file.name);
|
|
218
218
|
const { width, height } = await processAndUploadFile(media, file, newKey);
|
|
219
219
|
|
|
220
|
+
// Update title extension if the file type changed (e.g., photo.jpg → photo.webp)
|
|
221
|
+
const oldTitle = existing.title as string;
|
|
222
|
+
const newExt = file.name.split('.').pop();
|
|
223
|
+
const updatedTitle =
|
|
224
|
+
newExt && /\.\w+$/.test(oldTitle)
|
|
225
|
+
? oldTitle.replace(/\.\w+$/, `.${newExt}`)
|
|
226
|
+
: oldTitle;
|
|
227
|
+
|
|
220
228
|
const newUrl = `/api/media/${newKey}`;
|
|
221
229
|
await db
|
|
222
230
|
.prepare(
|
|
223
|
-
`UPDATE _assets SET url = ?, content_type = ?, file_size = ?, width = ?, height = ?, updated_at = datetime('now') WHERE id = ?`
|
|
231
|
+
`UPDATE _assets SET title = ?, url = ?, content_type = ?, file_size = ?, width = ?, height = ?, updated_at = datetime('now') WHERE id = ?`
|
|
224
232
|
)
|
|
225
|
-
.bind(newUrl, file.type, file.size, width, height, id)
|
|
233
|
+
.bind(updatedTitle, newUrl, file.type, file.size, width, height, id)
|
|
226
234
|
.run();
|
|
227
235
|
|
|
228
236
|
return c.json({
|
|
229
237
|
id,
|
|
238
|
+
title: updatedTitle,
|
|
230
239
|
url: newUrl,
|
|
231
240
|
content_type: file.type,
|
|
232
241
|
file_size: file.size,
|