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.
This commit is contained in:
calzoneman 2015-07-06 12:29:40 -07:00
parent 83e3c44a6d
commit a6ddebbec3
4 changed files with 91 additions and 6 deletions

20
NEWS.md Normal file
View File

@ -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.

View File

@ -9,7 +9,11 @@ function sha256(input) {
} }
function filter(input) { function filter(input) {
var $ = cheerio.load(input, { xmlMode: true }); var $ = cheerio.load(input, {
lowerCaseTags: true,
lowerCaseAttributeNames: true,
xmlMode: true
});
var meta = getMeta($); var meta = getMeta($);
var id = "cu:" + sha256(input); var id = "cu:" + sha256(input);
@ -36,7 +40,7 @@ function getMeta($) {
const ALLOWED_PARAMS = /^(flashvars|bgcolor|movie)$/i; const ALLOWED_PARAMS = /^(flashvars|bgcolor|movie)$/i;
function filterEmbed(tag) { 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' " + throw new Error("Invalid embed. Only type 'application/x-shockwave-flash' " +
"is allowed for <embed> tags."); "is allowed for <embed> tags.");
} }
@ -59,9 +63,9 @@ function filterEmbed(tag) {
} }
function filterObject(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' " + throw new Error("Invalid embed. Only type 'application/x-shockwave-flash' " +
"is allowed for <embed> tags."); "is allowed for <object> tags.");
} }
var meta = { var meta = {

View File

@ -411,7 +411,8 @@ module.exports.saveUserPlaylist = function (pl, username, plname, callback) {
meta: { meta: {
codec: pl[i].media.meta.codec, codec: pl[i].media.meta.codec,
bitrate: pl[i].media.meta.bitrate, 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; time += pl[i].media.seconds || 0;

View File

@ -2,7 +2,7 @@ var db = require("../database");
var Logger = require("../logger"); var Logger = require("../logger");
var Q = require("q"); var Q = require("q");
const DB_VERSION = 6; const DB_VERSION = 7;
var hasUpdates = []; var hasUpdates = [];
module.exports.checkVersion = function () { module.exports.checkVersion = function () {
@ -56,6 +56,8 @@ function update(version, cb) {
fixUtf8mb4(cb); fixUtf8mb4(cb);
} else if (version < 6) { } else if (version < 6) {
fixCustomEmbeds(cb); 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);
});
}