import * as path from "https://deno.land/std/path/mod.ts"; import { exists } from "./fsUtilis.ts"; let __dirname = path.dirname(new URL(import.meta.url).pathname); (__dirname.startsWith("/") || __dirname.startsWith("//")) && (__dirname = __dirname.slice(1)) const filePath = path.join(__dirname, "..", "uploads"); !await exists(filePath) && (await Deno.mkdir(filePath)); export async function fileParser(file: File){ const imageBytes = new Uint8Array(await file.arrayBuffer()); const rngName = crypto.randomUUID(); const fileName = rngName + "." + file.type.split("/")[1] await Deno.writeFile(path.join(filePath, fileName), imageBytes); return { newFileName: rngName, newFileNameWithExt: fileName, filePath: path.join(filePath, fileName), fileLength: imageBytes.length } }