mirror of
https://github.com/IrosTheBeggar/mStream.git
synced 2025-10-27 07:31:02 +00:00
move download directory api
This commit is contained in:
parent
6271f7546e
commit
aed0943483
@ -39,36 +39,6 @@ exports.setup = function(mstream, program) {
|
||||
}
|
||||
}
|
||||
|
||||
mstream.post('/download-directory', (req, res) => {
|
||||
if (!req.body.directory) {
|
||||
return res.status(500).json({ error: 'Missing Params' });
|
||||
}
|
||||
|
||||
// Get full path
|
||||
const pathInfo = vpath.getVPathInfo(req.body.directory, req.user);
|
||||
if (!pathInfo) { return res.status(500).json({ error: "Could not find file" }); }
|
||||
|
||||
// Make sure it's a directory
|
||||
if (!fs.statSync(pathInfo.fullPath).isDirectory()) {
|
||||
res.status(500).json({ error: "Not a directory" });
|
||||
return;
|
||||
}
|
||||
|
||||
const archive = archiver('zip');
|
||||
archive.on('error', function (err) {
|
||||
winston.error(`Download Error: ${err.message}`);
|
||||
res.status(500).json({ error: err.message });
|
||||
});
|
||||
|
||||
// sets the archive name. TODO: Rename this
|
||||
res.attachment('zipped-playlist.zip');
|
||||
|
||||
// streaming magic
|
||||
archive.pipe(res);
|
||||
archive.directory(pathInfo.fullPath, false);
|
||||
archive.finalize();
|
||||
});
|
||||
|
||||
mstream.post('/fileplaylist/download', (req, res, next) => {
|
||||
try {
|
||||
const playlistPathInfo = getPathInfoOrThrow(req, req.body.path);
|
||||
|
||||
@ -1,10 +1,39 @@
|
||||
const archiver = require('archiver');
|
||||
const path = require('path');
|
||||
const fs = require('fs').promises;
|
||||
const winston = require('winston');
|
||||
const vpath = require('../util/vpath');
|
||||
const shared = require('../api/shared');
|
||||
|
||||
exports.setup = (mstream) => {
|
||||
mstream.post('/api/v1/download/directory', async (req, res) => {
|
||||
try {
|
||||
if (!req.body.directory) { throw 'Validation Error' }
|
||||
|
||||
const pathInfo = vpath.getVPathInfo(req.body.directory, req.user);
|
||||
if (!pathInfo) { return res.status(500).json({ error: "Could not find file" }); }
|
||||
|
||||
if (!(await fs.stat(pathInfo.fullPath)).isDirectory()) { throw 'Not A Directory'; }
|
||||
|
||||
const archive = archiver('zip');
|
||||
archive.on('error', (err) => {
|
||||
winston.error(`Download Error: ${err.message}`);
|
||||
res.status(500).json({ error: err.message });
|
||||
});
|
||||
|
||||
res.attachment('mstream-directory.zip');
|
||||
|
||||
// streaming magic
|
||||
archive.pipe(res);
|
||||
archive.directory(pathInfo.fullPath, false);
|
||||
archive.finalize();
|
||||
} catch (err) {
|
||||
winston.error('Download Error', { stack: err })
|
||||
res.status(500).json({ error: typeof err === 'string' ? err : 'Unknown Error' });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mstream.get('/api/v1/download/zip', (req, res) => {
|
||||
let fileArray;
|
||||
if (req.sharedPlaylistId) {
|
||||
|
||||
@ -727,7 +727,7 @@ $(document).ready(function () {
|
||||
var directoryString = getDirectoryString($(this));
|
||||
|
||||
// Use key if necessary
|
||||
$("#downform").attr("action", "/download-directory?token=" + MSTREAMAPI.currentServer.token);
|
||||
$("#downform").attr("action", "/api/v1/download/directory?token=" + MSTREAMAPI.currentServer.token);
|
||||
|
||||
$('<input>').attr({
|
||||
type: 'hidden',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user