Skip to content

Instantly share code, notes, and snippets.

@micahlt
Created August 4, 2023 01:58
Show Gist options
  • Select an option

  • Save micahlt/50f42dbe36864645295acd9a3c74d90e to your computer and use it in GitHub Desktop.

Select an option

Save micahlt/50f42dbe36864645295acd9a3c74d90e to your computer and use it in GitHub Desktop.
Archive Unrealbook files from the web interface API
const fs = require("fs");
const path = require("path");
const { Readable } = require('stream');
const { finished } = require('stream/promises');
const downloadFile = (async (url, path) => {
try {
const stream = fs.createWriteStream(path);
const { body } = await fetch(url);
return await finished(Readable.fromWeb(body).pipe(stream));
} catch {
console.log("Couldn't download to", path);
}
});
const main = () => {
fetch("http://192.168.1.171/list?path=%2F").then(res => res.json()).then(async files => {
for (file of files) {
await downloadFile(`http://192.168.1.171/download?path=${encodeURIComponent(file.path)}`, "SONGBACKUP"+ file.path);
console.log("Downloaded SONGBACKUP" + file.path);
}
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment