Updated migration

- Fixed bug in migration process for single-user mode
- Changed name of migration

Removed unused code for getmp3/mp4 and fixed bug when retrieving playlist if it didn't exist

Fixed bug in streaming code where playlist audio files would not play if the file path was not present

Fixed bug in getallsubscriptions for single user mode
This commit is contained in:
Isaac Abadi
2020-12-22 01:23:43 -05:00
parent afb5e3800c
commit 3f1532b4c6
2 changed files with 11 additions and 23 deletions

View File

@@ -212,8 +212,8 @@ async function checkMigrations() {
// 4.1->4.2 migration // 4.1->4.2 migration
const add_description_migration_complete = db.get('add_description_migration_complete').value(); const simplified_db_migration_complete = db.get('simplified_db_migration_complete').value();
if (!add_description_migration_complete) { if (!simplified_db_migration_complete) {
logger.info('Beginning migration: 4.1->4.2+') logger.info('Beginning migration: 4.1->4.2+')
let success = await simplifyDBFileStructure(); let success = await simplifyDBFileStructure();
success = success && await addMetadataPropertyToDB('view_count'); success = success && await addMetadataPropertyToDB('view_count');
@@ -276,12 +276,12 @@ async function simplifyDBFileStructure() {
} }
if (db.get('files.video').value() !== undefined && db.get('files.audio').value() !== undefined) { if (db.get('files.video').value() !== undefined && db.get('files.audio').value() !== undefined) {
const files = db.get('files.video').value().concat(db.get('files.audio')); const files = db.get('files.video').value().concat(db.get('files.audio').value());
db.assign({files: files}).write(); db.assign({files: files}).write();
} }
if (db.get('playlists.video').value() !== undefined && db.get('playlists.audio').value() !== undefined) { if (db.get('playlists.video').value() !== undefined && db.get('playlists.audio').value() !== undefined) {
const playlists = db.get('playlists.video').value().concat(db.get('playlists.audio')); const playlists = db.get('playlists.video').value().concat(db.get('playlists.audio').value());
db.assign({playlists: playlists}).write(); db.assign({playlists: playlists}).write();
} }
@@ -303,7 +303,7 @@ async function addMetadataPropertyToDB(property_key) {
} }
// sets migration to complete // sets migration to complete
db.set('add_description_migration_complete', true).write(); db.set('simplified_db_migration_complete', true).write();
return true; return true;
} catch(err) { } catch(err) {
logger.error(err); logger.error(err);
@@ -1935,8 +1935,8 @@ async function addThumbnails(files) {
// gets all download mp3s // gets all download mp3s
app.get('/api/getMp3s', optionalJwt, async function(req, res) { app.get('/api/getMp3s', optionalJwt, async function(req, res) {
var mp3s = db.get('files').chain().find({isAudio: true}).value(); // getMp3s(); var mp3s = db.get('files').value().filter(file => file.isAudio === true);
var playlists = db.get('playlists.audio').value(); var playlists = db.get('playlists').value();
const is_authenticated = req.isAuthenticated(); const is_authenticated = req.isAuthenticated();
if (is_authenticated) { if (is_authenticated) {
// get user audio files/playlists // get user audio files/playlists
@@ -1947,12 +1947,6 @@ app.get('/api/getMp3s', optionalJwt, async function(req, res) {
mp3s = JSON.parse(JSON.stringify(mp3s)); mp3s = JSON.parse(JSON.stringify(mp3s));
if (config_api.getConfigItem('ytdl_include_thumbnail')) {
// add thumbnails if present
// await addThumbnails(mp3s);
}
res.send({ res.send({
mp3s: mp3s, mp3s: mp3s,
playlists: playlists playlists: playlists
@@ -1961,7 +1955,7 @@ app.get('/api/getMp3s', optionalJwt, async function(req, res) {
// gets all download mp4s // gets all download mp4s
app.get('/api/getMp4s', optionalJwt, async function(req, res) { app.get('/api/getMp4s', optionalJwt, async function(req, res) {
var mp4s = db.get('files').chain().find({isAudio: false}).value(); // getMp4s(); var mp4s = db.get('files').value().filter(file => file.isAudio === false);
var playlists = db.get('playlists').value(); var playlists = db.get('playlists').value();
const is_authenticated = req.isAuthenticated(); const is_authenticated = req.isAuthenticated();
@@ -1974,11 +1968,6 @@ app.get('/api/getMp4s', optionalJwt, async function(req, res) {
mp4s = JSON.parse(JSON.stringify(mp4s)); mp4s = JSON.parse(JSON.stringify(mp4s));
if (config_api.getConfigItem('ytdl_include_thumbnail')) {
// add thumbnails if present
// await addThumbnails(mp4s);
}
res.send({ res.send({
mp4s: mp4s, mp4s: mp4s,
playlists: playlists playlists: playlists
@@ -2501,14 +2490,13 @@ app.post('/api/getPlaylist', optionalJwt, async (req, res) => {
if (req.isAuthenticated()) { if (req.isAuthenticated()) {
playlist = auth_api.getUserPlaylist(uuid ? uuid : req.user.uid, playlistID); playlist = auth_api.getUserPlaylist(uuid ? uuid : req.user.uid, playlistID);
type = playlist.type;
} else { } else {
playlist = db.get(`playlists`).find({id: playlistID}).value(); playlist = db.get(`playlists`).find({id: playlistID}).value();
} }
res.send({ res.send({
playlist: playlist, playlist: playlist,
type: type, type: playlist && playlist.type,
success: !!playlist success: !!playlist
}); });
}); });
@@ -2746,7 +2734,7 @@ app.get('/api/stream/:id', optionalJwt, (req, res) => {
} }
if (!file_path) { if (!file_path) {
file_path = path.join(videoFolderPath, id + ext); file_path = path.join(type === 'audio' ? audioFolderPath : videoFolderPath, id + ext);
} }
const stat = fs.statSync(file_path) const stat = fs.statSync(file_path)

View File

@@ -483,7 +483,7 @@ function getAllSubscriptions() {
if (users[i]['subscriptions']) subscriptions = subscriptions.concat(users[i]['subscriptions']); if (users[i]['subscriptions']) subscriptions = subscriptions.concat(users[i]['subscriptions']);
} }
} else { } else {
subscriptions = subscriptions_api.getSubscriptions(); subscriptions = getSubscriptions();
} }
return subscriptions; return subscriptions;
} }