0
0
This commit is contained in:
syuilo 2022-02-03 17:12:51 +09:00
parent 12678eb1c0
commit ddc0b37d13
3 changed files with 13 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -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