From 92d53759505b86f55611409ac16b5a3b1f65b9db Mon Sep 17 00:00:00 2001 From: calzoneman Date: Mon, 29 Jun 2015 17:43:57 -0700 Subject: [PATCH] database: update for new custom embed format --- lib/database/channels.js | 3 ++- lib/database/update.js | 32 +++++++++++++++++++++++++++++++- lib/media.js | 1 - 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/database/channels.js b/lib/database/channels.js index 30e99b31..228322eb 100644 --- a/lib/database/channels.js +++ b/lib/database/channels.js @@ -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` " + diff --git a/lib/database/update.js b/lib/database/update.js index e3574be0..92b479bc 100644 --- a/lib/database/update.js +++ b/lib/database/update.js @@ -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(); + }); + }); +} diff --git a/lib/media.js b/lib/media.js index 8aa3d56e..4b3ebc30 100644 --- a/lib/media.js +++ b/lib/media.js @@ -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,