Created
August 4, 2023 01:58
-
-
Save micahlt/50f42dbe36864645295acd9a3c74d90e to your computer and use it in GitHub Desktop.
Archive Unrealbook files from the web interface API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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