mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-10 00:11:29 +03:00
DB implementation of subs now can properly delete subs
This commit is contained in:
@@ -2149,10 +2149,11 @@ app.post('/api/unsubscribe', optionalJwt, async (req, res) => {
|
|||||||
app.post('/api/deleteSubscriptionFile', optionalJwt, async (req, res) => {
|
app.post('/api/deleteSubscriptionFile', optionalJwt, async (req, res) => {
|
||||||
let deleteForever = req.body.deleteForever;
|
let deleteForever = req.body.deleteForever;
|
||||||
let file = req.body.file;
|
let file = req.body.file;
|
||||||
|
let file_uid = req.body.file_uid;
|
||||||
let sub = req.body.sub;
|
let sub = req.body.sub;
|
||||||
let user_uid = req.isAuthenticated() ? req.user.uid : null;
|
let user_uid = req.isAuthenticated() ? req.user.uid : null;
|
||||||
|
|
||||||
let success = await subscriptions_api.deleteSubscriptionFile(sub, file, deleteForever, user_uid);
|
let success = await subscriptions_api.deleteSubscriptionFile(sub, file, deleteForever, file_uid, user_uid);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
res.send({
|
res.send({
|
||||||
@@ -2181,6 +2182,7 @@ app.post('/api/getSubscription', optionalJwt, async (req, res) => {
|
|||||||
if (subscription.name && !subscription.streamingOnly) {
|
if (subscription.name && !subscription.streamingOnly) {
|
||||||
var parsed_files = subscription.videos;
|
var parsed_files = subscription.videos;
|
||||||
if (!parsed_files) {
|
if (!parsed_files) {
|
||||||
|
parsed_files = [];
|
||||||
let base_path = null;
|
let base_path = null;
|
||||||
if (user_uid)
|
if (user_uid)
|
||||||
base_path = path.join(config_api.getConfigItem('ytdl_users_base_path'), user_uid, 'subscriptions');
|
base_path = path.join(config_api.getConfigItem('ytdl_users_base_path'), user_uid, 'subscriptions');
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ async function subscribe(sub, user_uid = null) {
|
|||||||
let success = await getSubscriptionInfo(sub, user_uid);
|
let success = await getSubscriptionInfo(sub, user_uid);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
sub = sub_db.get().value();
|
sub = sub_db.value();
|
||||||
getVideosForSub(sub, user_uid);
|
getVideosForSub(sub, user_uid);
|
||||||
} else {
|
} else {
|
||||||
logger.error('Subscribe: Failed to get subscription info. Subscribe failed.')
|
logger.error('Subscribe: Failed to get subscription info. Subscribe failed.')
|
||||||
@@ -175,16 +175,21 @@ async function unsubscribe(sub, deleteMode, user_uid = null) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteSubscriptionFile(sub, file, deleteForever, user_uid = null) {
|
async function deleteSubscriptionFile(sub, file, deleteForever, file_uid = null, user_uid = null) {
|
||||||
let basePath = null;
|
let basePath = null;
|
||||||
if (user_uid)
|
let sub_db = null;
|
||||||
|
if (user_uid) {
|
||||||
basePath = path.join(config_api.getConfigItem('ytdl_users_base_path'), user_uid, 'subscriptions');
|
basePath = path.join(config_api.getConfigItem('ytdl_users_base_path'), user_uid, 'subscriptions');
|
||||||
else
|
sub_db = users_db.get('users').find({uid: user_uid}).get('subscriptions').find({id: sub.id});
|
||||||
|
} else {
|
||||||
basePath = config_api.getConfigItem('ytdl_subscriptions_base_path');
|
basePath = config_api.getConfigItem('ytdl_subscriptions_base_path');
|
||||||
|
sub_db = db.get('subscriptions').find({id: sub.id});
|
||||||
|
}
|
||||||
const useArchive = config_api.getConfigItem('ytdl_subscriptions_use_youtubedl_archive');
|
const useArchive = config_api.getConfigItem('ytdl_subscriptions_use_youtubedl_archive');
|
||||||
const appendedBasePath = getAppendedBasePath(sub, basePath);
|
const appendedBasePath = getAppendedBasePath(sub, basePath);
|
||||||
const name = file;
|
const name = file;
|
||||||
let retrievedID = null;
|
let retrievedID = null;
|
||||||
|
sub_db.get('videos').remove({uid: file_uid}).write();
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
let filePath = appendedBasePath;
|
let filePath = appendedBasePath;
|
||||||
var jsonPath = path.join(__dirname,filePath,name+'.info.json');
|
var jsonPath = path.join(__dirname,filePath,name+'.info.json');
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ var fs = require('fs-extra')
|
|||||||
var path = require('path')
|
var path = require('path')
|
||||||
const config_api = require('./config');
|
const config_api = require('./config');
|
||||||
|
|
||||||
|
const is_windows = process.platform === 'win32';
|
||||||
|
|
||||||
function getTrueFileName(unfixed_path, type) {
|
function getTrueFileName(unfixed_path, type) {
|
||||||
let fixed_path = unfixed_path;
|
let fixed_path = unfixed_path;
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ export class PlayerComponent implements OnInit {
|
|||||||
this.currentItem = this.playlist[0];
|
this.currentItem = this.playlist[0];
|
||||||
this.currentIndex = 0;
|
this.currentIndex = 0;
|
||||||
this.show_player = true;
|
this.show_player = true;
|
||||||
} else if (this.type === 'subscription' || this.fileNames) {
|
} else if (this.subscriptionName || this.fileNames) {
|
||||||
this.show_player = true;
|
this.show_player = true;
|
||||||
this.parseFileNames();
|
this.parseFileNames();
|
||||||
}
|
}
|
||||||
@@ -181,9 +181,6 @@ export class PlayerComponent implements OnInit {
|
|||||||
fileType = 'audio/mp3';
|
fileType = 'audio/mp3';
|
||||||
} else if (this.type === 'video') {
|
} else if (this.type === 'video') {
|
||||||
fileType = 'video/mp4';
|
fileType = 'video/mp4';
|
||||||
} else if (this.type === 'subscription') {
|
|
||||||
// only supports mp4 for now
|
|
||||||
fileType = 'video/mp4';
|
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
console.error('Must have valid file type! Use \'audio\', \'video\', or \'subscription\'.');
|
console.error('Must have valid file type! Use \'audio\', \'video\', or \'subscription\'.');
|
||||||
|
|||||||
@@ -289,8 +289,9 @@ export class PostsService implements CanActivate {
|
|||||||
return this.http.post(this.path + 'unsubscribe', {sub: sub, deleteMode: deleteMode}, this.httpOptions)
|
return this.http.post(this.path + 'unsubscribe', {sub: sub, deleteMode: deleteMode}, this.httpOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteSubscriptionFile(sub, file, deleteForever) {
|
deleteSubscriptionFile(sub, file, deleteForever, file_uid) {
|
||||||
return this.http.post(this.path + 'deleteSubscriptionFile', {sub: sub, file: file, deleteForever: deleteForever}, this.httpOptions)
|
return this.http.post(this.path + 'deleteSubscriptionFile', {sub: sub, file: file, deleteForever: deleteForever,
|
||||||
|
file_uid: file_uid}, this.httpOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
getSubscription(id) {
|
getSubscription(id) {
|
||||||
|
|||||||
@@ -71,14 +71,14 @@ export class SubscriptionFileCardComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteAndRedownload() {
|
deleteAndRedownload() {
|
||||||
this.postsService.deleteSubscriptionFile(this.sub, this.file.id, false).subscribe(res => {
|
this.postsService.deleteSubscriptionFile(this.sub, this.file.id, false, this.file.uid).subscribe(res => {
|
||||||
this.reloadSubscription.emit(true);
|
this.reloadSubscription.emit(true);
|
||||||
this.openSnackBar(`Successfully deleted file: '${this.file.id}'`, 'Dismiss.');
|
this.openSnackBar(`Successfully deleted file: '${this.file.id}'`, 'Dismiss.');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteForever() {
|
deleteForever() {
|
||||||
this.postsService.deleteSubscriptionFile(this.sub, this.file.id, true).subscribe(res => {
|
this.postsService.deleteSubscriptionFile(this.sub, this.file.id, true, this.file.uid).subscribe(res => {
|
||||||
this.reloadSubscription.emit(true);
|
this.reloadSubscription.emit(true);
|
||||||
this.openSnackBar(`Successfully deleted file: '${this.file.id}'`, 'Dismiss.');
|
this.openSnackBar(`Successfully deleted file: '${this.file.id}'`, 'Dismiss.');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user