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 ++++++++++ server/models/video/video-channel.ts | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'server/models') 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: { diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 5598d80f6..91dd0440c 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -28,7 +28,7 @@ import { AccountModel } from '../account/account' import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' import { buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' -import { CONSTRAINTS_FIELDS } from '../../initializers' +import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' import { ServerModel } from '../server/server' import { DefineIndexesOptions } from 'sequelize' @@ -378,6 +378,14 @@ export class VideoChannelModel extends Model { .findOne(query) } + static loadByNameWithHostAndPopulateAccount (nameWithHost: string) { + const [ name, host ] = nameWithHost.split('@') + + if (!host || host === CONFIG.WEBSERVER.HOST) return VideoChannelModel.loadLocalByNameAndPopulateAccount(name) + + return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) + } + static loadLocalByNameAndPopulateAccount (name: string) { const query = { include: [ -- cgit v1.2.3