From 92bf2f62995bbaa0402cb4657473ad8d5b6fcf8d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 21 Feb 2019 14:06:10 +0100 Subject: Improve channel and account SEO --- server/models/account/account.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'server/models/account') diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 84ef0b30d..747b51afb 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -24,6 +24,8 @@ import { getSort, throwIfNotValid } from '../utils' import { VideoChannelModel } from '../video/video-channel' import { VideoCommentModel } from '../video/video-comment' import { UserModel } from './user' +import * as Bluebird from '../../helpers/custom-validators/accounts' +import { CONFIG } from '../../initializers' @DefaultScope({ include: [ @@ -153,6 +155,14 @@ export class AccountModel extends Model { return AccountModel.findOne(query) } + static loadByNameWithHost (nameWithHost: string) { + const [ accountName, host ] = nameWithHost.split('@') + + if (!host || host === CONFIG.WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName) + + return AccountModel.loadByNameAndHost(accountName, host) + } + static loadLocalByName (name: string) { const query = { where: { -- cgit v1.2.3