|
|
@@ -6,19 +6,19 @@ const config = require("../../config.js"),
|
|
|
sessionManager = require("../session.js").SessionManager,
|
|
|
accountConfigManager = require("../models/accountConfig.js").accountConfigManager;
|
|
|
|
|
|
-function recursiveGet(url, cb, redirectLoop) {
|
|
|
+function recursiveGet(url, cb, headers, redirectLoop) {
|
|
|
var getFnc = http.get;
|
|
|
|
|
|
if (url.substr(0, 8) === "https://")
|
|
|
getFnc = https.get;
|
|
|
- getFnc(url, (d) => {
|
|
|
+ getFnc(url, headers ? { headers: headers } : {}, (d) => {
|
|
|
if (d.statusCode >= 300 && d.statusCode < 400 && d.headers["location"]) {
|
|
|
if (!redirectLoop)
|
|
|
redirectLoop = [];
|
|
|
|
|
|
if (redirectLoop.indexOf(d.headers["location"]) === -1 && redirectLoop.length < 5) {
|
|
|
redirectLoop.push(d.headers["location"]);
|
|
|
- recursiveGet(d.headers["location"], cb, redirectLoop);
|
|
|
+ recursiveGet(d.headers["location"], cb, headers, redirectLoop);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
@@ -398,6 +398,31 @@ module.exports.ApiController = {
|
|
|
res.writeHeader("400", "Bad Request");
|
|
|
res.end();
|
|
|
}
|
|
|
+ } else if (req.urlObj.match(["api", "serviceImage"])) {
|
|
|
+ if (req.urlObj.queryTokens.team && req.urlObj.queryTokens.path) {
|
|
|
+ var ctx = res.chatContext.getChatSystem(req.urlObj.queryTokens.team[0]);
|
|
|
+
|
|
|
+ if (!ctx) {
|
|
|
+ res.writeHeader("404", "Not Found");
|
|
|
+ res.end();
|
|
|
+ } else if (req.method !== 'GET') {
|
|
|
+ res.writeHeader("400", "Bad Request");
|
|
|
+ res.end();
|
|
|
+ } else {
|
|
|
+ let url = ctx.getImage(req.urlObj.queryTokens.path[0]);
|
|
|
+ if (!url) {
|
|
|
+ res.writeHeader("400", "Bad Request");
|
|
|
+ res.end();
|
|
|
+ } else {
|
|
|
+ recursiveGet(url.url, (d) => {
|
|
|
+ d.pipe(res, { end: true });
|
|
|
+ }, url.headers);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ res.writeHeader("400", "Bad Request");
|
|
|
+ res.end();
|
|
|
+ }
|
|
|
} else if (req.urlObj.match(["api"])) {
|
|
|
let knownVersion = (req.urlObj.queryTokens.v ? parseInt(req.urlObj.queryTokens.v[0], 10) : 0) || 0;
|
|
|
res.chatContext.poll(knownVersion, req.reqT,
|