Added new methods to facilitate server-side download management

This commit is contained in:
Isaac Grynsztein
2020-04-18 01:31:32 -04:00
parent 4617362270
commit d887380fd1
2 changed files with 40 additions and 0 deletions

View File

@@ -141,6 +141,7 @@ if (writeConfigMode) {
loadConfig();
}
var downloads = {};
var descriptors = {};
app.use(bodyParser.urlencoded({ extended: false }));
@@ -1363,7 +1364,18 @@ app.post('/api/tomp3', async function(req, res) {
}
}
// adds download to download helper
const download_uid = uuid();
downloads[download_uid] = {
uid: download_uid,
downloading: true,
complete: false,
url: url,
type: 'audio'
};
youtubedl.exec(url, downloadConfig, {}, function(err, output) {
downloads[download_uid]['downloading'] = false;
var uid = null;
let new_date = Date.now();
let difference = (new_date - date)/1000;
@@ -1423,6 +1435,8 @@ app.post('/api/tomp3', async function(req, res) {
fs.unlinkSync(merged_path)
}
downloads[download_uid]['complete'] = true;
var audiopathEncoded = encodeURIComponent(file_names[0]);
res.send({
audiopathEncoded: audiopathEncoded,
@@ -1510,7 +1524,20 @@ app.post('/api/tomp4', async function(req, res) {
}
// adds download to download helper
const download_uid = uuid();
downloads[download_uid] = {
uid: download_uid,
downloading: true,
complete: false,
url: url,
type: 'video',
percent_complete: 0,
is_playlist: url.includes('playlist')
};
youtubedl.exec(url, downloadConfig, {}, function(err, output) {
downloads[download_uid]['downloading'] = false;
var uid = null;
let new_date = Date.now();
let difference = (new_date - date)/1000;
@@ -1568,6 +1595,8 @@ app.post('/api/tomp4', async function(req, res) {
const archive_path = path.join(archivePath, 'archive_video.txt');
fs.appendFileSync(archive_path, diff);
}
downloads[download_uid]['complete'] = true;
var videopathEncoded = encodeURIComponent(file_names[0]);
res.send({
@@ -2282,6 +2311,12 @@ app.get('/api/audio/:id', function(req , res){
}
});
// Downloads management
app.get('/api/downloads', async (req, res) => {
res.send({downloads: downloads});
});
app.post('/api/getVideoInfos', async (req, res) => {
let fileNames = req.body.fileNames;

View File

@@ -215,6 +215,11 @@ export class PostsService {
return this.http.post(this.path + 'getAllSubscriptions', {}, this.httpOptions);
}
// current downloads
getCurrentDownloads() {
return this.http.get(this.path + 'downloads', this.httpOptions);
}
// updates the server to the latest version
updateServer(tag) {
return this.http.post(this.path + 'updateServer', {tag: tag}, this.httpOptions);