Add a better error message for google drive 1hr

This commit is contained in:
calzoneman 2014-11-13 20:08:01 -06:00
parent 7708cf1aca
commit 4514151ad2
3 changed files with 143 additions and 0 deletions

49
lib/filter-master.js Normal file
View File

@ -0,0 +1,49 @@
function FilterMaster(worker) {
this.waiting = {};
this.worker = worker;
this.id = 0;
this.worker.on("message", this.handleMessage.bind(this));
}
FilterMaster.prototype.filterMessage = function (channel, message, cb) {
var req = {
cmd: "filter",
channel: channel.name,
message: message,
id: this.id++
};
var resdata = {
cb: cb,
channel: channel,
message: message,
time: Date.now()
};
this.waiting[req.id] = resdata;
this.worker.send(req);
};
FilterMaster.prototype.handleMessage = function (data) {
if (data.cmd === "filterResult") {
var res = this.waiting[data.id];
if (!res) return;
delete this.waiting[data.id];
if (data.error) {
// TODO log error
return;
}
res.cb(data.message);
} else if (data.cmd === "needFilterData") {
var res = this.waiting[data.id];
if (!res) return;
var data = {
filters: res.channel.modules.filters.filters.pack(),
channel: res.channel.name,
}
};

84
lib/filter-worker.js Normal file
View File

@ -0,0 +1,84 @@
var FilterList = require("./channel/filters").FilterList;
function FilterWorker() {
this.cache = {};
}
FilterWorker.prototype.cacheData = function (channel, filters, convertLinks) {
this.cache[channel] = {
filters: new FilterList(filters),
convertLinks: convertLinks
};
};
FilterWorker.prototype.removeData = function (channel) {
if (this.cache.hasOwnProperty(channel)) {
delete this.cache[channel];
}
};
FilterWorker.prototype.hasData = function (channel) {
return this.cache.hasOwnProperty(channel);
};
const link = /(\w+:\/\/(?:[^:\/\[\]\s]+|\[[0-9a-f:]+\])(?::\d+)?(?:\/[^\/\s]*)*)/ig;
FilterWorker.prototype.filterMessage = function (channel, msg) {
if (!this.hasData(channel)) {
throw new Error("Missing channel data");
}
var parts = msg.split(link);
var filters = this.cache[channel].filters;
var convertLinks = this.cache[channel].convertLinks;
for (var j = 0; j < parts.length; j++) {
/* substring is a URL */
if (convertLinks && parts[j].match(link)) {
var original = parts[j];
parts[j] = filters.exec(parts[j], { filterlinks: true });
/* no filters changed the URL, apply link filter */
if (parts[j] === original) {
parts[j] = url.format(url.parse(parts[j]));
parts[j] = parts[j].replace(link, "<a href=\"$1\" target=\"_blank\">$1</a>");
}
} else {
/* substring is not a URL */
parts[j] = filters.exec(parts[j], { filterlinks: false });
}
}
msg = parts.join("");
};
var procWorker = new FilterWorker();
process.on("message", function (data) {
if (data.cmd === "addChannel") {
procWorker.cacheData(data.channel.toLowerCase(), data.filters, data.convertLinks);
} else if (data.cmd === "delChannel") {
procWorker.removeData(data.channel.toLowerCase());
} else if (data.cmd === "filter") {
try {
var filtered = procWorker.filterMessage(data.channel.toLowerCase(), data.message);
process.send({
cmd: "filterResult",
id: data.id,
message: filtered
});
} catch (err) {
if (err.message === "Missing channel data") {
process.send({
cmd: "needFilterData",
id: data.id
});
} else {
process.send({
cmd: "filterResult",
id: data.id,
error: err
});
}
}
}
});

View File

@ -726,6 +726,16 @@ var Getters = {
data[kv[0]] = kv[1]; data[kv[0]] = kv[1];
}); });
if (data.hasOwnProperty("reason")) {
var reason = data.reason;
if (reason.indexOf("Unable to play this video at this time.") === 0) {
reason = "There is currently a bug with Google Drive which prevents playback " +
"of videos 1 hour long or longer.";
}
return callback(reason);
}
if (!data.hasOwnProperty("title")) { if (!data.hasOwnProperty("title")) {
return callback("Returned HTML is missing the video title. Are you " + return callback("Returned HTML is missing the video title. Are you " +
"sure the video is done processing?"); "sure the video is done processing?");