REFACTOR: merges redirectTo implementation into one function (#10919)

This commit is contained in:
Joffrey JAFFEUX 2020-10-15 19:26:05 +02:00 committed by GitHub
parent 51d10db7f2
commit e062b94e7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,11 +12,6 @@ import { setOwner } from "@ember/application";
const rewrites = [];
const TOPIC_REGEXP = /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/;
function redirectTo(url) {
document.location = url;
return true;
}
// We can add links here that have server side responses but not client side.
const SERVER_SIDE_ONLY = [
/^\/assets\//,
@ -228,22 +223,18 @@ const DiscourseURL = EmberObject.extend({
}
if (Session.currentProp("requiresRefresh")) {
return redirectTo(getURL(path));
return this.redirectTo(getURL(path));
}
const pathname = path.replace(/(https?\:)?\/\/[^\/]+/, "");
if (!this.isInternal(path)) {
return redirectTo(path);
return this.redirectTo(path);
}
const serverSide = SERVER_SIDE_ONLY.some((r) => {
if (pathname.match(r)) {
return redirectTo(path);
}
});
const serverSide = SERVER_SIDE_ONLY.some((r) => pathname.match(r));
if (serverSide) {
this.redirectTo(path);
return;
}
@ -268,7 +259,7 @@ const DiscourseURL = EmberObject.extend({
userPath(currentUser.get("username_lower"))
);
} else {
return redirectTo("/login-preferences");
return this.redirectTo("/login-preferences");
}
}
@ -316,6 +307,7 @@ const DiscourseURL = EmberObject.extend({
redirectTo(url) {
window.location = getURL(url);
return true;
},
/**