Skip to content
Snippets Groups Projects
Commit ddc0b37d authored by syuilo's avatar syuilo
Browse files

refactor

parent 12678eb1
No related branches found
No related tags found
No related merge requests found
...@@ -11,18 +11,18 @@ import { fetchMeta } from '@/misc/fetch-meta'; ...@@ -11,18 +11,18 @@ import { fetchMeta } from '@/misc/fetch-meta';
import { Users, UserProfiles } from '@/models/index'; import { Users, UserProfiles } from '@/models/index';
import { ILocalUser } from '@/models/entities/user'; 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]; return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
} }
function compareOrigin(ctx: Koa.Context) { function compareOrigin(ctx: Koa.BaseContext): boolean {
function normalizeUrl(url: string) { function normalizeUrl(url?: string): string {
return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : ''; return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : '';
} }
const referer = ctx.headers['referer']; const referer = ctx.headers['referer'];
return (normalizeUrl(referer) == normalizeUrl(config.url)); return (normalizeUrl(referer) === normalizeUrl(config.url));
} }
// Init router // Init router
......
...@@ -11,18 +11,18 @@ import { fetchMeta } from '@/misc/fetch-meta'; ...@@ -11,18 +11,18 @@ import { fetchMeta } from '@/misc/fetch-meta';
import { Users, UserProfiles } from '@/models/index'; import { Users, UserProfiles } from '@/models/index';
import { ILocalUser } from '@/models/entities/user'; 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]; return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
} }
function compareOrigin(ctx: Koa.Context) { function compareOrigin(ctx: Koa.BaseContext): boolean {
function normalizeUrl(url: string) { function normalizeUrl(url?: string): string {
return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : ''; return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : '';
} }
const referer = ctx.headers['referer']; const referer = ctx.headers['referer'];
return (normalizeUrl(referer) == normalizeUrl(config.url)); return (normalizeUrl(referer) === normalizeUrl(config.url));
} }
// Init router // Init router
......
...@@ -10,18 +10,18 @@ import { fetchMeta } from '@/misc/fetch-meta'; ...@@ -10,18 +10,18 @@ import { fetchMeta } from '@/misc/fetch-meta';
import { Users, UserProfiles } from '@/models/index'; import { Users, UserProfiles } from '@/models/index';
import { ILocalUser } from '@/models/entities/user'; 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]; return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
} }
function compareOrigin(ctx: Koa.Context) { function compareOrigin(ctx: Koa.BaseContext): boolean {
function normalizeUrl(url: string) { function normalizeUrl(url?: string): string {
return url.endsWith('/') ? url.substr(0, url.length - 1) : url; return url == null ? '' : url.endsWith('/') ? url.substr(0, url.length - 1) : url;
} }
const referer = ctx.headers['referer']; const referer = ctx.headers['referer'];
return (normalizeUrl(referer) == normalizeUrl(config.url)); return (normalizeUrl(referer) === normalizeUrl(config.url));
} }
// Init router // Init router
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment