database: update for new custom embed format

This commit is contained in:
calzoneman 2015-06-29 17:43:57 -07:00
parent 7fee1414e2
commit 92d5375950
3 changed files with 33 additions and 3 deletions

View File

@ -427,7 +427,8 @@ module.exports = {
var meta = JSON.stringify({
bitrate: media.meta.bitrate,
codec: media.meta.codec,
scuri: media.meta.scuri
scuri: media.meta.scuri,
embed: media.meta.embed
});
db.query("INSERT INTO `channel_libraries` " +

View File

@ -2,7 +2,7 @@ var db = require("../database");
var Logger = require("../logger");
var Q = require("q");
const DB_VERSION = 5;
const DB_VERSION = 6;
var hasUpdates = [];
module.exports.checkVersion = function () {
@ -54,6 +54,8 @@ function update(version, cb) {
})
} else if (version < 5) {
fixUtf8mb4(cb);
} else if (version < 6) {
fixCustomEmbeds(cb);
}
}
@ -240,3 +242,31 @@ function fixUtf8mb4(cb) {
Logger.errlog.log("Failed to fix utf8mb4: " + e);
});
};
function fixCustomEmbeds(cb) {
var CustomEmbedFilter = require("../customembed").filter;
Q.nfcall(db.query, "SELECT * FROM `channel_libraries` WHERE type='cu'")
.then(function (rows) {
var all = [];
rows.forEach(function (row) {
if (row.id.indexOf("cu:") === 0) return;
all.push(Q.nfcall(db.query, "DELETE FROM `channel_libraries` WHERE `id`=? AND `channel`=?",
[row.id, row.channel]));
try {
var media = CustomEmbedFilter(row.id);
all.push(Q.nfcall(db.channels.addToLibrary, row.channel, media));
} catch(e) {
console.error("WARNING: Unable to convert " + row.id);
}
});
Q.allSettled(all).then(function () {
Logger.syslog.log("Converted custom embeds.");
cb();
});
});
}

View File

@ -33,7 +33,6 @@ Media.prototype = {
type: this.type,
meta: {
direct: this.meta.direct,
gpdirect: this.meta.gpdirect,
restricted: this.meta.restricted,
codec: this.meta.codec,
bitrate: this.meta.bitrate,