From a6ddebbec3f4d24e9f70ab502b983f1001aa7fdd Mon Sep 17 00:00:00 2001 From: calzoneman Date: Mon, 6 Jul 2015 12:29:40 -0700 Subject: [PATCH] Fix custom embeds in user_playlists; add NEWS.md Server administrators should check NEWS.md before updating for information about important changes or required administrator intervention. --- NEWS.md | 20 ++++++++++++++ lib/customembed.js | 12 +++++--- lib/database.js | 3 +- lib/database/update.js | 62 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 NEWS.md diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 00000000..5831fa93 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,20 @@ +2015-07-06 +========== + + * As part of the video player rewrite, Google Drive and Google+ metadata + lookups are now offloaded to CyTube/mediaquery. After pulling the new + changes, run `npm install` or `npm update` to update the mediaquery + dependency. + + * `www/js/player.js` is now built from the CoffeeScript source files in the + `player/` directory. Instead of modifying it directly, modify the relevant + player implementations in `player/` and run `npm run build-player` (or `node + build-player.js`) to generate `www/js/player.js`. + + * Also as part of the video player rewrite, the schema for custom embeds + changed so any custom embeds stored in the `channel_libraries` table need to + be updated. The automatic upgrade script will convert any custom embeds + that are parseable (i.e., not truncated by the width of the `id` field using + the old format) and will delete the rest (you may see a lot of WARNING: + unable to convert xxx messages-- this is normal). Custom embeds in channel + playlists in the chandumps will be converted when the channel is loaded. diff --git a/lib/customembed.js b/lib/customembed.js index c2923f16..b9814109 100644 --- a/lib/customembed.js +++ b/lib/customembed.js @@ -9,7 +9,11 @@ function sha256(input) { } function filter(input) { - var $ = cheerio.load(input, { xmlMode: true }); + var $ = cheerio.load(input, { + lowerCaseTags: true, + lowerCaseAttributeNames: true, + xmlMode: true + }); var meta = getMeta($); var id = "cu:" + sha256(input); @@ -36,7 +40,7 @@ function getMeta($) { const ALLOWED_PARAMS = /^(flashvars|bgcolor|movie)$/i; function filterEmbed(tag) { - if (tag.attribs.type !== "application/x-shockwave-flash") { + if (tag.attribs.type && tag.attribs.type !== "application/x-shockwave-flash") { throw new Error("Invalid embed. Only type 'application/x-shockwave-flash' " + "is allowed for tags."); } @@ -59,9 +63,9 @@ function filterEmbed(tag) { } function filterObject(tag) { - if (tag.attribs.type !== "application/x-shockwave-flash") { + if (tag.attribs.type && tag.attribs.type !== "application/x-shockwave-flash") { throw new Error("Invalid embed. Only type 'application/x-shockwave-flash' " + - "is allowed for tags."); + "is allowed for tags."); } var meta = { diff --git a/lib/database.js b/lib/database.js index f71386fd..f2b2e366 100644 --- a/lib/database.js +++ b/lib/database.js @@ -411,7 +411,8 @@ module.exports.saveUserPlaylist = function (pl, username, plname, callback) { meta: { codec: pl[i].media.meta.codec, bitrate: pl[i].media.meta.bitrate, - scuri: pl[i].media.meta.scuri + scuri: pl[i].media.meta.scuri, + embed: pl[i].media.meta.embed } }; time += pl[i].media.seconds || 0; diff --git a/lib/database/update.js b/lib/database/update.js index 92b479bc..340f2c60 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 = 6; +const DB_VERSION = 7; var hasUpdates = []; module.exports.checkVersion = function () { @@ -56,6 +56,8 @@ function update(version, cb) { fixUtf8mb4(cb); } else if (version < 6) { fixCustomEmbeds(cb); + } else if (version < 7) { + fixCustomEmbedsInUserPlaylists(cb); } } @@ -270,3 +272,61 @@ function fixCustomEmbeds(cb) { }); }); } + +function fixCustomEmbedsInUserPlaylists(cb) { + var CustomEmbedFilter = require("../customembed").filter; + Q.nfcall(db.query, "SELECT * FROM `user_playlists` WHERE `contents` LIKE '%\"type\":\"cu\"%'") + .then(function (rows) { + var all = []; + rows.forEach(function (row) { + var data; + try { + data = JSON.parse(row.contents); + } catch (e) { + return; + } + + var updated = []; + var item; + while ((item = data.shift()) !== undefined) { + if (item.type !== "cu") { + updated.push(item); + continue; + } + + if (/^cu:/.test(item.id)) { + updated.push(item); + continue; + } + + var media; + try { + media = CustomEmbedFilter(item.id); + } catch (e) { + Logger.syslog.log("WARNING: Unable to convert " + item.id); + continue; + } + + updated.push({ + id: media.id, + title: item.title, + seconds: media.seconds, + type: media.type, + meta: { + embed: media.meta.embed + } + }); + + all.push(Q.nfcall(db.query, "UPDATE `user_playlists` SET `contents`=?, `count`=? WHERE `user`=? AND `name`=?", + [JSON.stringify(updated), updated.length, row.user, row.name])); + } + }); + + Q.allSettled(all).then(function () { + Logger.syslog.log('Fixed custom embeds in user_playlists'); + cb(); + }); + }).catch(function (err) { + Logger.errlog.log(err.stack); + }); +}