upd: dashboard admin
Deskripsi - edit upload ttd setting desa No Issues
This commit is contained in:
12
src/server/lib/rename-file.ts
Normal file
12
src/server/lib/rename-file.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { mimeToExtension } from "./mimetypeToExtension";
|
||||
|
||||
export function renameFile({ oldFile, newName }: { oldFile: File; newName: string }) {
|
||||
const ext = mimeToExtension(oldFile.type)
|
||||
const nameFix = newName == 'random' ? `${uuidv4()}.${ext}` : newName
|
||||
|
||||
return new File([oldFile], nameFix, {
|
||||
type: oldFile.type,
|
||||
lastModified: oldFile.lastModified,
|
||||
});
|
||||
}
|
||||
@@ -159,7 +159,7 @@ export async function uploadFile(config: Config, file: File): Promise<string> {
|
||||
|
||||
const text = await res.text();
|
||||
|
||||
if (!res.ok) throw new Error(`Upload failed: ${text}`);
|
||||
if (!res.ok) return 'gagal'
|
||||
return `✅ Uploaded ${file.name} successfully`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user