refactor: 优化文件存储路径逻辑,按年月进行分组归档

This commit is contained in:
seahi committed 2026-07-29 21:46:36 +08:00
1 parent d76932ae34
commit 44f81ef0c7
1 file changed
+4 -2
+4 -2
View File
@@ -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