aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-21 14:06:10 +0100
committerChocobozzz <me@florianbigard.com>2019-02-21 14:06:10 +0100
commit92bf2f62995bbaa0402cb4657473ad8d5b6fcf8d (patch)
tree7f3f34b1503fd21db7f0b913c3b908f004015011 /server/models
parent84c7cde6e81426a42e7aa29187b473bc89f1c8f6 (diff)
downloadPeerTube-92bf2f62995bbaa0402cb4657473ad8d5b6fcf8d.tar.gz
PeerTube-92bf2f62995bbaa0402cb4657473ad8d5b6fcf8d.tar.zst
PeerTube-92bf2f62995bbaa0402cb4657473ad8d5b6fcf8d.zip
Improve channel and account SEO
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account.ts10
-rw-r--r--server/models/video/video-channel.ts10
2 files changed, 19 insertions, 1 deletions
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'
24import { VideoChannelModel } from '../video/video-channel' 24import { VideoChannelModel } from '../video/video-channel'
25import { VideoCommentModel } from '../video/video-comment' 25import { VideoCommentModel } from '../video/video-comment'
26import { UserModel } from './user' 26import { UserModel } from './user'
27import * as Bluebird from '../../helpers/custom-validators/accounts'
28import { CONFIG } from '../../initializers'
27 29
28@DefaultScope({ 30@DefaultScope({
29 include: [ 31 include: [
@@ -153,6 +155,14 @@ export class AccountModel extends Model<AccountModel> {
153 return AccountModel.findOne(query) 155 return AccountModel.findOne(query)
154 } 156 }
155 157
158 static loadByNameWithHost (nameWithHost: string) {
159 const [ accountName, host ] = nameWithHost.split('@')
160
161 if (!host || host === CONFIG.WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName)
162
163 return AccountModel.loadByNameAndHost(accountName, host)
164 }
165
156 static loadLocalByName (name: string) { 166 static loadLocalByName (name: string) {
157 const query = { 167 const query = {
158 where: { 168 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'
28import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' 28import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor'
29import { buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' 29import { buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils'
30import { VideoModel } from './video' 30import { VideoModel } from './video'
31import { CONSTRAINTS_FIELDS } from '../../initializers' 31import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
32import { ServerModel } from '../server/server' 32import { ServerModel } from '../server/server'
33import { DefineIndexesOptions } from 'sequelize' 33import { DefineIndexesOptions } from 'sequelize'
34 34
@@ -378,6 +378,14 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
378 .findOne(query) 378 .findOne(query)
379 } 379 }
380 380
381 static loadByNameWithHostAndPopulateAccount (nameWithHost: string) {
382 const [ name, host ] = nameWithHost.split('@')
383
384 if (!host || host === CONFIG.WEBSERVER.HOST) return VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
385
386 return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host)
387 }
388
381 static loadLocalByNameAndPopulateAccount (name: string) { 389 static loadLocalByNameAndPopulateAccount (name: string) {
382 const query = { 390 const query = {
383 include: [ 391 include: [