Update FileTag for multi-field
We are separating an identifier (uuid) from the human-readable label.
This commit is contained in:
parent
e23f994894
commit
232929a47a
@ -22,13 +22,13 @@ class Library extends EventEmitter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.backend.find(tag, path => {
|
this.backend.find(tag, track => {
|
||||||
if (!path) {
|
if (!track) {
|
||||||
this.emit('action', new tags.NotFoundTag(tag));
|
this.emit('action', new tags.NotFoundTag(tag));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('action', new tags.FileTag(tag, path));
|
this.emit('action', new tags.FileTag(tag, track));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const Track = require('./track');
|
||||||
|
|
||||||
class SqliteBackend {
|
class SqliteBackend {
|
||||||
constructor(config, db) {
|
constructor(config, db) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@ -7,11 +9,11 @@ class SqliteBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
find(tag, callback) {
|
find(tag, callback) {
|
||||||
this.db.get("SELECT uuid FROM tags WHERE tag = ? AND _ROWID_ >= (abs(random()) % (SELECT max(_ROWID_) FROM tags)) LIMIT 1", tag, (err, row) => {
|
this.db.get("SELECT uuid, tag, label FROM tags WHERE tag = ? AND _ROWID_ >= (abs(random()) % (SELECT max(_ROWID_) FROM tags)) LIMIT 1", tag, (err, row) => {
|
||||||
if (typeof row === 'undefined') {
|
if (typeof row === 'undefined') {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
callback(row['uuid']);
|
callback(new Track(row['tag'], row['uuid'], row['label']));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,13 @@ class NotFoundTag extends Tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class FileTag extends Tag {
|
class FileTag extends Tag {
|
||||||
constructor(tag, path) {
|
constructor(tag, track) {
|
||||||
super(tag);
|
super(tag);
|
||||||
this.path = path;
|
this.track = track;
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return basename(this.path);
|
return this.track.label;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
jukebox/library/track.js
Normal file
11
jukebox/library/track.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
class Track {
|
||||||
|
constructor(tag, uuid, label) {
|
||||||
|
this.tag = tag;
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Track;
|
@ -52,7 +52,7 @@ class MediaPlayer extends ChildProcessEmitter {
|
|||||||
|
|
||||||
_playFile(tag) {
|
_playFile(tag) {
|
||||||
this.emit('command', tag);
|
this.emit('command', tag);
|
||||||
this.send("LOAD " + tag.path);
|
this.send("LOAD " + tag.track.uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
_unknown(tag) {
|
_unknown(tag) {
|
||||||
|
Loading…
Reference in New Issue
Block a user