diff --git a/README.md b/README.md index f88650a..190bfd3 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ it's intended use is for small groups of people to self-host, and as such there' 3. `npm install` -4. (optionally) put the service on pm2 like such: `pm2 start src/index.js --name deemix-web-frontend` (or just run it with `node src/index.js`) +4. install the `zip` linux tool into your path (there are currently no plans for windows support, however feel free to contribute) + +5. (optionally) put the service on pm2 like such: `pm2 start src/index.js --name deemix-web-frontend` (or just run it with `node src/index.js`) ### nginx addenum diff --git a/public/index.js b/public/index.js index c4c96d2..22e0c61 100644 --- a/public/index.js +++ b/public/index.js @@ -79,7 +79,21 @@ function startDownload(id, isAlbum) { log = addlog(log, 'Download finished'); } - document.getElementById('progress-album').innerHTML = `
${title || ''}
by ${artist || ''}
${log || ''}
`; + document.getElementById('progress-album').innerHTML = ` +
+
+ +
${log || ''}
+
+
+ +
+
+ `; } ws.onerror = (e) => { console.log('error: ' + e); @@ -176,9 +190,9 @@ window.onload = () => { if (d.data.length === 0) return document.getElementById('albums').innerHTML = 'Not found!'; for (c of document.getElementById('albums').children) { - if (c.children[5]) { + if (c.children[0] && c.children[0].children[1]) { let id = c.id.split('-')[1]; - c.children[5].onclick = () => { + c.children[0].children[1].onclick = () => { clearError(); startDownload(id, true); } diff --git a/src/index.js b/src/index.js index 6eb5e7f..1bfeb20 100644 --- a/src/index.js +++ b/src/index.js @@ -2,9 +2,10 @@ const express = require('express'); const deezer = require('deezer-js'); const deemix = require('deemix'); const path = require('path'); -const { inspect } = require('util'); +const { inspect, promisify } = require('util'); const ws = require('ws'); const fs = require('fs'); +const { exec } = require('child_process'); const port = process.env.PORT || 4500; @@ -83,11 +84,14 @@ app.get('/api/album', async (req, res) => { app.ws('/api/album', async (ws, req) => { if (!req.query.id) return ws.close(1008, 'Supply a track ID in the query!'); + let trackpaths = []; + const listener = { send(key, data) { if (data.downloaded) { - ws.send(JSON.stringify({key: 'download', data: data.downloadPath.replace(process.cwd(), '')})); - console.log('downloaded ' + data.downloadPath + ', deleting in 1hr') + // ws.send(JSON.stringify({key: 'download', data: data.downloadPath.replace(process.cwd(), '')})); + trackpaths.push(data.downloadPath); + console.log('downloaded ' + data.downloadPath + ', deleting in 1hr'); setTimeout(() => { try { fs.unlinkSync(data.downloadPath); @@ -117,6 +121,24 @@ app.ws('/api/album', async (ws, req) => { await deemixDownloader.start(); + const folderName = trackpaths[0].split('/').slice(-2)[0]; + try { + await promisify(exec)(`zip -0rD "data/${folderName}.zip" "data/${folderName}"`); + } catch(err) { + return ws.close(1006, 'Zipping album failed'); + } + + await ws.send(JSON.stringify({key: 'download', data: `data/${folderName}.zip`})); + + console.log('zipped up data/' + folderName + '.zip, deleting in 1hr'); + setTimeout(() => { + try { + fs.unlinkSync('./data/' + folderName + '.zip'); + } catch(err) { + console.log('tried to delete ' + folderName + '.zip, but failed? its likely already gone'); + } + }, 1000 * 60 * 60 /* 1 hour */); + ws.close(1000); });