From ddc0b37d137db2ab35d6427d1d1d76c68ebcb866 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 3 Feb 2022 17:12:51 +0900 Subject: [PATCH] refactor --- packages/backend/src/server/api/service/discord.ts | 8 ++++---- packages/backend/src/server/api/service/github.ts | 8 ++++---- packages/backend/src/server/api/service/twitter.ts | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/backend/src/server/api/service/discord.ts b/packages/backend/src/server/api/service/discord.ts index f574fe3878..dd731c422e 100644 --- a/packages/backend/src/server/api/service/discord.ts +++ b/packages/backend/src/server/api/service/discord.ts @@ -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 diff --git a/packages/backend/src/server/api/service/github.ts b/packages/backend/src/server/api/service/github.ts index 5e0839df93..b23219986a 100644 --- a/packages/backend/src/server/api/service/github.ts +++ b/packages/backend/src/server/api/service/github.ts @@ -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 diff --git a/packages/backend/src/server/api/service/twitter.ts b/packages/backend/src/server/api/service/twitter.ts index 8659b82cbe..bca00b7924 100644 --- a/packages/backend/src/server/api/service/twitter.ts +++ b/packages/backend/src/server/api/service/twitter.ts @@ -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