From 44f81ef0c7a256fb00ee0b81f5ebf763bea4555f Mon Sep 17 00:00:00 2001 From: seaHi Date: Wed, 29 Jul 2026 21:46:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=AD=98=E5=82=A8=E8=B7=AF=E5=BE=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E6=8C=89=E5=B9=B4=E6=9C=88=E8=BF=9B=E8=A1=8C=E5=88=86?= =?UTF-8?q?=E7=BB=84=E5=BD=92=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/admin/files/+page.server.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/routes/admin/files/+page.server.ts b/src/routes/admin/files/+page.server.ts index 0064aa8..0024327 100644 --- a/src/routes/admin/files/+page.server.ts +++ b/src/routes/admin/files/+page.server.ts @@ -64,10 +64,12 @@ export const actions: Actions = { return fail(400, { error: '没有提供有效的文件' }); } - // Generate unique key (timestamp + random string + original name) + // Generate unique key with year-month grouping (e.g. uploads/2026-07/timestamp-random.ext) const ext = file.name.split('.').pop() || ''; const randomStr = Math.random().toString(36).substring(2, 8); - const key = `${Date.now()}-${randomStr}.${ext}`; + const now = new Date(); + const yearMonth = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`; + const key = `uploads/${yearMonth}/${Date.now()}-${randomStr}.${ext}`; try { // Upload to R2