From 98c010b51c923ce398155fea3f9af7e23f215f8d Mon Sep 17 00:00:00 2001 From: borja Date: Wed, 13 Dec 2023 13:11:09 +0100 Subject: [PATCH] ya carga archivos, ahora hay que hacer que los transforme --- .gitignore | 4 ++++ src/routes/+page.js | 2 +- src/routes/+page.server.js | 16 ++++++++++++++++ src/routes/+page.svelte | 7 +++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8f6c617..478bd96 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,7 @@ node_modules .output vite.config.js.timestamp-* vite.config.ts.timestamp-* +/static/uploads/* +/static/wav/* + + diff --git a/src/routes/+page.js b/src/routes/+page.js index a72419a..2b8e145 100644 --- a/src/routes/+page.js +++ b/src/routes/+page.js @@ -1,3 +1,3 @@ // since there's no dynamic data here, we can prerender // it so that it gets served as a static asset in production -export const prerender = true; +// export const prerender = true; diff --git a/src/routes/+page.server.js b/src/routes/+page.server.js index e69de29..2cb8294 100644 --- a/src/routes/+page.server.js +++ b/src/routes/+page.server.js @@ -0,0 +1,16 @@ +import { writeFile } from 'node:fs/promises'; + +/** @type {import('./$types').Actions} */ +export const actions = { + default: async ({ request }) => { + const formData = await request.formData(); + const uploadedFile = formData?.get('file'); + console.log(uploadedFile); + const filename = `./static/uploads/${crypto.randomUUID()}-${uploadedFile?.name}`; + await writeFile(filename, Buffer.from(await uploadedFile?.arrayBuffer())); + // Bun.writeFile(filename, await uploadedFile?.arrayBuffer()); + + return { success: true }; + } +}; + diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index dec6ad0..96793ef 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -21,6 +21,7 @@ name="file" accept=".mp4,.mov,.avi,.mkv,.mp3,.flac,.wav,.aac" /> + @@ -38,6 +39,12 @@ margin: 1rem 0; } + button { + display: block; + margin: 2rem 0; + font-size: 1.1rem; + padding: 0.25rem 0.5rem; + } code { font-size: 1rem; font-family: monospace;