Development #287

Merged
bones7242 merged 58 commits from development into master 2017-12-11 20:53:02 +01:00
2 changed files with 15 additions and 8 deletions
Showing only changes of commit 4f8cdc06b0 - Show all commits

View file

@ -92,7 +92,7 @@ module.exports = (app) => {
if (result === true) {
res.status(200).json(true);
} else {
logger.debug(`Rejecting '${params.name}' because that name has already been claimed on spee.ch`);
// logger.debug(`Rejecting '${params.name}' because that name has already been claimed on spee.ch`);
res.status(200).json(false);
}
})
@ -107,12 +107,11 @@ module.exports = (app) => {
if (result === true) {
res.status(200).json(true);
} else {
logger.debug(`Rejecting '${params.name}' because that channel has already been claimed on spee.ch`);
// logger.debug(`Rejecting '${params.name}' because that channel has already been claimed on spee.ch`);
res.status(200).json(false);
}
})
.catch(error => {
logger.debug('api/channel-is-available/ error', error);
res.status(500).json(error);
});
});

View file

@ -143,16 +143,24 @@ function showChannelPageToClient (uri, originalUrl, ip, query, res) {
});
}
function characterExistsInString (character, string) {
return (string.indexOf(character) !== -1);
}
function clientAcceptsHtml (headers) {
return headers['accept'] && headers['accept'].split(',').includes('text/html');
}
function determineResponseType (uri, headers) {
let responseType;
if (uri.indexOf('.') !== -1) {
if (characterExistsInString('.', uri)) {
responseType = SERVE;
if (headers['accept'] && headers['accept'].split(',').includes('text/html')) {
if (clientAcceptsHtml(headers)) { // this is in case a serve request comes from a browser
responseType = SHOWLITE;
}
} else {
responseType = SHOW;
if (!headers['accept'] || !headers['accept'].split(',').includes('text/html')) {
if (!clientAcceptsHtml(headers)) { // this is in case someone embeds a show url
responseType = SERVE;
}
}
@ -161,11 +169,11 @@ function determineResponseType (uri, headers) {
function determineName (uri) {
/* patch because twitter player preview adds '>' before file extension. */
if (uri.indexOf('>') !== -1) {
if (characterExistsInString('>', uri)) {
return uri.substring(0, uri.indexOf('>'));
}
/* end patch */
if (uri.indexOf('.') !== -1) {
if (characterExistsInString('.', uri)) {
return uri.substring(0, uri.indexOf('.'));
}
return uri;