Simplified archive creation for subscriptions to reduce risk of error

If no subscriptions have ever been made, "No channel/playlist subscriptions" text will now show
This commit is contained in:
Isaac Grynsztein
2020-04-12 21:00:47 -04:00
parent 10b59191f6
commit d9f6b8c64c
2 changed files with 6 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
var fs = require('fs');
var fs = require('fs-extra');
const { uuid } = require('uuidv4');
var path = require('path');
@@ -82,16 +82,12 @@ async function getSubscriptionInfo(sub) {
if (!sub.archive) {
// must create the archive
const archive_dir = basePath + 'archives/' + sub.name;
const archive_dir = path.join(__dirname, basePath, 'archives', sub.name);
const archive_path = path.join(archive_dir, 'archive.txt');
// creates archive directory and text file if it doesn't exist
if (!fs.existsSync(archive_dir)) {
fs.mkdirSync(archive_dir);
fs.closeSync(fs.openSync(archive_path, 'w'));
} else if (!fs.existsSync(archive_path)) {
fs.closeSync(fs.openSync(archive_path, 'w'));
}
fs.ensureDirSync(archive_dir);
fs.ensureFileSync(archive_path);
// updates subscription
sub.archive = archive_dir;

View File

@@ -34,6 +34,8 @@ export class SubscriptionsComponent implements OnInit {
this.subscriptions_loading = false;
this.subscriptions = res['subscriptions'];
if (!this.subscriptions) {
// set it to an empty array so it can notify the user there are no subscriptions
this.subscriptions = [];
return;
}