Skip to content

Instantly share code, notes, and snippets.

@lpil
Last active March 2, 2023 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lpil/841b81b67bd27361165253d075f39520 to your computer and use it in GitHub Desktop.
Save lpil/841b81b67bd27361165253d075f39520 to your computer and use it in GitHub Desktop.
A file uploader + tagger written in under 20 lines and under 30 minutes.
import { serve } from "https://deno.land/std@0.114.0/http/server.ts";
import { multiParser } from "https://deno.land/x/multiparser@0.114.0/mod.ts";
import * as uuid from "https://deno.land/std@0.175.0/uuid/mod.ts";
import NodeID3 from "npm:node-id3";
serve(async (req) => {
if (req.method == "POST") {
const { files, fields } = await multiParser(req);
const path = "uploads/" + uuid.v1.generate() + ".mp3";
await Deno.writeFile(path, files.track.content);
NodeID3.update({ artist: fields.artist, title: fields.title }, path);
}
return new Response(await Deno.readTextFile("./index.html"), {
headers: { "Content-Type": "text/html; charset=utf-8" },
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment