refactor db props listings
This commit is contained in:
parent
deed3a7eb8
commit
7cc928e1e9
2 changed files with 130 additions and 35 deletions
155
lib/player.js
155
lib/player.js
|
|
@ -41,22 +41,121 @@ var LIBRARY_KEY_PREFIX = "Library.";
|
|||
var LIBRARY_DIR_PREFIX = "LibraryDir.";
|
||||
var PLAYLIST_KEY_PREFIX = "Playlist.";
|
||||
|
||||
// these are the ones we store in the DB, not the ones we send to the web
|
||||
var DB_FILE_PROPS = [
|
||||
'key', 'name', 'artistName', 'albumArtistName',
|
||||
'albumName', 'compilation', 'track', 'trackCount',
|
||||
'disc', 'discCount', 'duration', 'year', 'genre',
|
||||
'file', 'mtime', 'replayGainAlbumGain', 'replayGainAlbumPeak',
|
||||
'replayGainTrackGain', 'replayGainTrackPeak',
|
||||
'composerName', 'performerName', 'lastQueueDate',
|
||||
];
|
||||
|
||||
var EDITABLE_PROPS = [
|
||||
'name', 'artistName', 'albumArtistName',
|
||||
'albumName', 'compilation', 'track', 'trackCount',
|
||||
'disc', 'discCount', 'year', 'genre',
|
||||
'composerName', 'performerName'
|
||||
];
|
||||
// db: store in the DB
|
||||
// read: send to clients
|
||||
// write: accept updates from clients
|
||||
var DB_PROPS = {
|
||||
key: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: false,
|
||||
},
|
||||
name: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
artistName: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
albumArtistName: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
albumName: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
compilation: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
track: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
trackCount: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
disc: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
discCount: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
duration: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: false,
|
||||
},
|
||||
year: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
genre: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
file: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: false,
|
||||
},
|
||||
mtime: {
|
||||
db: true,
|
||||
read: false,
|
||||
write: false,
|
||||
},
|
||||
replayGainAlbumGain: {
|
||||
db: true,
|
||||
read: false,
|
||||
write: false,
|
||||
},
|
||||
replayGainAlbumPeak: {
|
||||
db: true,
|
||||
read: false,
|
||||
write: false,
|
||||
},
|
||||
replayGainTrackGain: {
|
||||
db: true,
|
||||
read: false,
|
||||
write: false,
|
||||
},
|
||||
replayGainTrackPeak: {
|
||||
db: true,
|
||||
read: false,
|
||||
write: false,
|
||||
},
|
||||
composerName: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
performerName: {
|
||||
db: true,
|
||||
read: true,
|
||||
write: true,
|
||||
},
|
||||
lastQueueDate: {
|
||||
db: true,
|
||||
read: false,
|
||||
write: false,
|
||||
},
|
||||
};
|
||||
|
||||
// how many GrooveFiles to keep open, ready to be decoded
|
||||
var OPEN_FILE_COUNT = 8;
|
||||
|
|
@ -873,10 +972,11 @@ Player.prototype.updateTags = function(obj) {
|
|||
if (!track) continue;
|
||||
var props = obj[key];
|
||||
if (!props || typeof props !== 'object') continue;
|
||||
for (var i = 0; i < EDITABLE_PROPS.length; i += 1) {
|
||||
var prop = EDITABLE_PROPS[i];
|
||||
if (! (prop in props)) continue;
|
||||
track[prop] = props[prop];
|
||||
for (var propName in DB_PROPS) {
|
||||
var prop = DB_PROPS[propName];
|
||||
if (! prop.write) continue;
|
||||
if (! (propName in props)) continue;
|
||||
track[propName] = props[propName];
|
||||
}
|
||||
this.persist(track);
|
||||
this.emit('updateDbTrack', track);
|
||||
|
|
@ -1622,18 +1722,21 @@ function serializePlaylistItem(item) {
|
|||
});
|
||||
}
|
||||
|
||||
function trackWithoutIndex(props, dbFile) {
|
||||
function trackWithoutIndex(category, dbFile) {
|
||||
var out = {};
|
||||
props.forEach(function(propName) {
|
||||
var value = dbFile[propName];
|
||||
for (var propName in DB_PROPS) {
|
||||
var prop = DB_PROPS[propName];
|
||||
if (!prop[category]) continue;
|
||||
// save space by leaving out null or undefined values
|
||||
if (value != null) out[propName] = value;
|
||||
});
|
||||
var value = dbFile[propName];
|
||||
if (value == null) continue;
|
||||
out[propName] = value;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function serializeFileData(dbFile) {
|
||||
return JSON.stringify(trackWithoutIndex(DB_FILE_PROPS, dbFile));
|
||||
return JSON.stringify(trackWithoutIndex('db', dbFile));
|
||||
}
|
||||
|
||||
function serializeDirEntry(dirEntry) {
|
||||
|
|
|
|||
|
|
@ -4,14 +4,6 @@ var Player = require('./player');
|
|||
|
||||
module.exports = PlayerServer;
|
||||
|
||||
// these are the ones we send to the web, not the ones we store in the DB
|
||||
var DB_FILE_PROPS = [
|
||||
'key', 'name', 'artistName', 'albumArtistName',
|
||||
'albumName', 'compilation', 'track', 'trackCount',
|
||||
'disc', 'discCount', 'duration', 'year', 'genre',
|
||||
'file'
|
||||
];
|
||||
|
||||
PlayerServer.plugins = [];
|
||||
|
||||
PlayerServer.actions = {
|
||||
|
|
@ -307,7 +299,7 @@ PlayerServer.prototype.initialize = function() {
|
|||
var table = {};
|
||||
for (var key in self.player.libraryIndex.trackTable) {
|
||||
var track = self.player.libraryIndex.trackTable[key];
|
||||
table[key] = Player.trackWithoutIndex(DB_FILE_PROPS, track);
|
||||
table[key] = Player.trackWithoutIndex('read', track);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue