]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/account.ts
Improve channel and account SEO
[github/Chocobozzz/PeerTube.git] / server / models / account / account.ts
index 84ef0b30d7a96aacd2b21b275e6aada2038858ea..747b51afbb5e58fbe5a146193c370f5fdc3b2641 100644 (file)
@@ -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<AccountModel> {
     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: {