Experiment to rebuild Diffuse using web applets.
at s3 29 lines 938 B view raw
1<script> 2 import { applets } from "@web-applets/sdk"; 3 import { parseWebStream } from "music-metadata"; 4 import { contentType } from "@std/media-types"; 5 import * as URI from "uri-js"; 6 7 //////////////////////////////////////////// 8 // SETUP 9 //////////////////////////////////////////// 10 const context = applets.register(); 11 12 //////////////////////////////////////////// 13 // ACTIONS 14 //////////////////////////////////////////// 15 context.setActionHandler("extract", extract); 16 17 async function extract(url: string) { 18 const uri = URI.parse(url); 19 const pathParts = uri.path?.split("/"); 20 const mimeType = pathParts?.[pathParts.length - 1]?.includes(".") 21 ? contentType(pathParts[pathParts.length - 1].split(".").reverse()[0]) 22 : undefined; 23 const resp = await fetch(url); 24 const stream = resp.body; 25 const metadata = await parseWebStream(stream, { mimeType }); 26 27 return metadata; 28 } 29</script>