mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-10 05:53:08 +02:00
refactor
This commit is contained in:
parent
12678eb1c0
commit
ddc0b37d13
3 changed files with 13 additions and 13 deletions
|
@ -11,18 +11,18 @@ import { fetchMeta } from '@/misc/fetch-meta';
|
|||
import { Users, UserProfiles } from '@/models/index';
|
||||
import { ILocalUser } from '@/models/entities/user';
|
||||
|
||||
function getUserToken(ctx: Koa.Context) {
|
||||
function getUserToken(ctx: Koa.BaseContext): string | null {
|
||||
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
|
||||
}
|
||||
|
||||
function compareOrigin(ctx: Koa.Context) {
|
||||
function normalizeUrl(url: string) {
|
||||
function compareOrigin(ctx: Koa.BaseContext): boolean {
|
||||
function normalizeUrl(url?: string): string {
|
||||
return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : '';
|
||||
}
|
||||
|
||||
const referer = ctx.headers['referer'];
|
||||
|
||||
return (normalizeUrl(referer) == normalizeUrl(config.url));
|
||||
return (normalizeUrl(referer) === normalizeUrl(config.url));
|
||||
}
|
||||
|
||||
// Init router
|
||||
|
|
|
@ -11,18 +11,18 @@ import { fetchMeta } from '@/misc/fetch-meta';
|
|||
import { Users, UserProfiles } from '@/models/index';
|
||||
import { ILocalUser } from '@/models/entities/user';
|
||||
|
||||
function getUserToken(ctx: Koa.Context) {
|
||||
function getUserToken(ctx: Koa.BaseContext): string | null {
|
||||
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
|
||||
}
|
||||
|
||||
function compareOrigin(ctx: Koa.Context) {
|
||||
function normalizeUrl(url: string) {
|
||||
function compareOrigin(ctx: Koa.BaseContext): boolean {
|
||||
function normalizeUrl(url?: string): string {
|
||||
return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : '';
|
||||
}
|
||||
|
||||
const referer = ctx.headers['referer'];
|
||||
|
||||
return (normalizeUrl(referer) == normalizeUrl(config.url));
|
||||
return (normalizeUrl(referer) === normalizeUrl(config.url));
|
||||
}
|
||||
|
||||
// Init router
|
||||
|
|
|
@ -10,18 +10,18 @@ import { fetchMeta } from '@/misc/fetch-meta';
|
|||
import { Users, UserProfiles } from '@/models/index';
|
||||
import { ILocalUser } from '@/models/entities/user';
|
||||
|
||||
function getUserToken(ctx: Koa.Context) {
|
||||
function getUserToken(ctx: Koa.BaseContext): string | null {
|
||||
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
|
||||
}
|
||||
|
||||
function compareOrigin(ctx: Koa.Context) {
|
||||
function normalizeUrl(url: string) {
|
||||
return url.endsWith('/') ? url.substr(0, url.length - 1) : url;
|
||||
function compareOrigin(ctx: Koa.BaseContext): boolean {
|
||||
function normalizeUrl(url?: string): string {
|
||||
return url == null ? '' : url.endsWith('/') ? url.substr(0, url.length - 1) : url;
|
||||
}
|
||||
|
||||
const referer = ctx.headers['referer'];
|
||||
|
||||
return (normalizeUrl(referer) == normalizeUrl(config.url));
|
||||
return (normalizeUrl(referer) === normalizeUrl(config.url));
|
||||
}
|
||||
|
||||
// Init router
|
||||
|
|
Loading…
Reference in a new issue