From 608624252466acf9f1d9ee1c1170bd4fe4d18d18 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Nov 2017 11:00:25 +0100 Subject: Rename Pod -> Server --- server/models/account/account-follow.ts | 4 +- server/models/account/account-interface.ts | 11 +- server/models/account/account.ts | 37 ++-- server/models/index.ts | 2 +- server/models/pod/index.ts | 1 - server/models/pod/pod-interface.ts | 61 ------ server/models/pod/pod.ts | 248 ------------------------- server/models/server/index.ts | 1 + server/models/server/server-interface.ts | 56 ++++++ server/models/server/server.ts | 233 +++++++++++++++++++++++ server/models/video/video-abuse-interface.ts | 4 +- server/models/video/video-abuse.ts | 18 +- server/models/video/video-channel-interface.ts | 2 +- server/models/video/video-channel.ts | 14 +- server/models/video/video-interface.ts | 12 +- server/models/video/video.ts | 58 +++--- 16 files changed, 375 insertions(+), 387 deletions(-) delete mode 100644 server/models/pod/index.ts delete mode 100644 server/models/pod/pod-interface.ts delete mode 100644 server/models/pod/pod.ts create mode 100644 server/models/server/index.ts create mode 100644 server/models/server/server-interface.ts create mode 100644 server/models/server/server.ts (limited to 'server/models') diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts index 6d7592326..c940d7cd4 100644 --- a/server/models/account/account-follow.ts +++ b/server/models/account/account-follow.ts @@ -101,7 +101,7 @@ listFollowingForApi = function (id: number, start: number, count: number, sort: model: AccountFollow['sequelize'].models.Account, as: 'AccountFollowing', required: true, - include: [ AccountFollow['sequelize'].models.Pod ] + include: [ AccountFollow['sequelize'].models.Server ] } ] } @@ -125,7 +125,7 @@ listFollowersForApi = function (id: number, start: number, count: number, sort: model: AccountFollow[ 'sequelize' ].models.Account, required: true, as: 'AccountFollower', - include: [ AccountFollow['sequelize'].models.Pod ] + include: [ AccountFollow['sequelize'].models.Server ] }, { model: AccountFollow['sequelize'].models.Account, diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts index ce1afec02..1a567fb7a 100644 --- a/server/models/account/account-interface.ts +++ b/server/models/account/account-interface.ts @@ -1,8 +1,7 @@ import * as Bluebird from 'bluebird' import * as Sequelize from 'sequelize' import { Account as FormattedAccount, ActivityPubActor } from '../../../shared' -import { ResultList } from '../../../shared/models/result-list.model' -import { PodInstance } from '../pod/pod-interface' +import { ServerInstance } from '../server/server-interface' import { VideoChannelInstance } from '../video/video-channel-interface' export namespace AccountMethods { @@ -11,7 +10,7 @@ export namespace AccountMethods { export type Load = (id: number) => Bluebird export type LoadByUUID = (uuid: string) => Bluebird export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird - export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird + export type LoadAccountByServerAndUUID = (uuid: string, serverId: number, transaction: Sequelize.Transaction) => Bluebird export type LoadLocalByName = (name: string) => Bluebird export type LoadByNameAndHost = (name: string, host: string) => Bluebird export type ListOwned = () => Bluebird @@ -27,7 +26,7 @@ export namespace AccountMethods { export interface AccountClass { loadApplication: AccountMethods.LoadApplication - loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID + loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID load: AccountMethods.Load loadByUUID: AccountMethods.LoadByUUID loadByUrl: AccountMethods.LoadByUrl @@ -51,7 +50,7 @@ export interface AccountAttributes { uuid?: string - podId?: number + serverId?: number userId?: number applicationId?: number } @@ -69,7 +68,7 @@ export interface AccountInstance extends AccountClass, AccountAttributes, Sequel createdAt: Date updatedAt: Date - Pod: PodInstance + Server: ServerInstance VideoChannels: VideoChannelInstance[] } diff --git a/server/models/account/account.ts b/server/models/account/account.ts index e90eaae5e..ee00c5aef 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -26,7 +26,7 @@ import { sendDeleteAccount } from '../../lib/activitypub/send-request' import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' let Account: Sequelize.Model -let loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID +let loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID let load: AccountMethods.Load let loadApplication: AccountMethods.LoadApplication let loadByUUID: AccountMethods.LoadByUUID @@ -170,7 +170,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes fields: [ 'name' ] }, { - fields: [ 'podId' ] + fields: [ 'serverId' ] }, { fields: [ 'userId' ], @@ -181,7 +181,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes unique: true }, { - fields: [ 'name', 'podId', 'applicationId' ], + fields: [ 'name', 'serverId', 'applicationId' ], unique: true } ], @@ -191,7 +191,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes const classMethods = [ associate, - loadAccountByPodAndUUID, + loadAccountByServerAndUUID, loadApplication, load, loadByUUID, @@ -217,9 +217,9 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes // --------------------------------------------------------------------------- function associate (models) { - Account.belongsTo(models.Pod, { + Account.belongsTo(models.Server, { foreignKey: { - name: 'podId', + name: 'serverId', allowNull: true }, onDelete: 'cascade' @@ -278,19 +278,28 @@ function afterDestroy (account: AccountInstance) { } toFormattedJSON = function (this: AccountInstance) { - let host = this.Pod ? this.Pod.host : CONFIG.WEBSERVER.HOST + let host = CONFIG.WEBSERVER.HOST + let score: number + + if (this.Server) { + host = this.Server.host + score = this.Server.score as number + } const json = { id: this.id, host, - name: this.name + score, + name: this.name, + createdAt: this.createdAt, + updatedAt: this.updatedAt } return json } toActivityPubObject = function (this: AccountInstance) { - const type = this.podId ? 'Application' as 'Application' : 'Person' as 'Person' + const type = this.serverId ? 'Application' as 'Application' : 'Person' as 'Person' const json = { type, @@ -317,7 +326,7 @@ toActivityPubObject = function (this: AccountInstance) { } isOwned = function (this: AccountInstance) { - return this.podId === null + return this.serverId === null } getFollowerSharedInboxUrls = function (this: AccountInstance) { @@ -356,7 +365,7 @@ getPublicKeyUrl = function (this: AccountInstance) { listOwned = function () { const query: Sequelize.FindOptions = { where: { - podId: null + serverId: null } } @@ -417,7 +426,7 @@ loadByNameAndHost = function (name: string, host: string) { }, include: [ { - model: Account['sequelize'].models.Pod, + model: Account['sequelize'].models.Server, required: true, where: { host @@ -440,10 +449,10 @@ loadByUrl = function (url: string, transaction?: Sequelize.Transaction) { return Account.findOne(query) } -loadAccountByPodAndUUID = function (uuid: string, podId: number, transaction: Sequelize.Transaction) { +loadAccountByServerAndUUID = function (uuid: string, serverId: number, transaction: Sequelize.Transaction) { const query: Sequelize.FindOptions = { where: { - podId, + serverId, uuid }, transaction diff --git a/server/models/index.ts b/server/models/index.ts index 0aec2d3b1..65faa5294 100644 --- a/server/models/index.ts +++ b/server/models/index.ts @@ -1,6 +1,6 @@ export * from './application' export * from './job' export * from './oauth' -export * from './pod' +export * from './server' export * from './account' export * from './video' diff --git a/server/models/pod/index.ts b/server/models/pod/index.ts deleted file mode 100644 index d2bf50d4d..000000000 --- a/server/models/pod/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './pod-interface' diff --git a/server/models/pod/pod-interface.ts b/server/models/pod/pod-interface.ts deleted file mode 100644 index 6c5aab3fa..000000000 --- a/server/models/pod/pod-interface.ts +++ /dev/null @@ -1,61 +0,0 @@ -import * as Sequelize from 'sequelize' -import * as Promise from 'bluebird' - -// Don't use barrel, import just what we need -import { Pod as FormattedPod } from '../../../shared/models/pods/pod.model' -import { ResultList } from '../../../shared/models/result-list.model' - -export namespace PodMethods { - export type ToFormattedJSON = (this: PodInstance) => FormattedPod - - export type CountAll = () => Promise - - export type IncrementScores = (ids: number[], value: number) => Promise<[ number, PodInstance[] ]> - - export type List = () => Promise - - export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList > - - export type ListAllIds = (transaction: Sequelize.Transaction) => Promise - - export type ListRandomPodIdsWithRequest = (limit: number, tableWithPods: string, tableWithPodsJoins: string) => Promise - - export type ListBadPods = () => Promise - - export type Load = (id: number) => Promise - - export type LoadByHost = (host: string) => Promise - - export type RemoveAll = () => Promise - - export type UpdatePodsScore = (goodPods: number[], badPods: number[]) => void -} - -export interface PodClass { - countAll: PodMethods.CountAll - incrementScores: PodMethods.IncrementScores - list: PodMethods.List - listForApi: PodMethods.ListForApi - listAllIds: PodMethods.ListAllIds - listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest - listBadPods: PodMethods.ListBadPods - load: PodMethods.Load - loadByHost: PodMethods.LoadByHost - removeAll: PodMethods.RemoveAll - updatePodsScore: PodMethods.UpdatePodsScore -} - -export interface PodAttributes { - id?: number - host?: string - score?: number | Sequelize.literal // Sequelize literal for 'score +' + value -} - -export interface PodInstance extends PodClass, PodAttributes, Sequelize.Instance { - createdAt: Date - updatedAt: Date - - toFormattedJSON: PodMethods.ToFormattedJSON, -} - -export interface PodModel extends PodClass, Sequelize.Model {} diff --git a/server/models/pod/pod.ts b/server/models/pod/pod.ts deleted file mode 100644 index 6d270ad7f..000000000 --- a/server/models/pod/pod.ts +++ /dev/null @@ -1,248 +0,0 @@ -import { map } from 'lodash' -import * as Sequelize from 'sequelize' - -import { FRIEND_SCORE, PODS_SCORE } from '../../initializers' -import { logger, isHostValid } from '../../helpers' - -import { addMethodsToModel, getSort } from '../utils' -import { - PodInstance, - PodAttributes, - - PodMethods -} from './pod-interface' - -let Pod: Sequelize.Model -let toFormattedJSON: PodMethods.ToFormattedJSON -let countAll: PodMethods.CountAll -let incrementScores: PodMethods.IncrementScores -let list: PodMethods.List -let listForApi: PodMethods.ListForApi -let listAllIds: PodMethods.ListAllIds -let listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest -let listBadPods: PodMethods.ListBadPods -let load: PodMethods.Load -let loadByHost: PodMethods.LoadByHost -let removeAll: PodMethods.RemoveAll -let updatePodsScore: PodMethods.UpdatePodsScore - -export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { - Pod = sequelize.define('Pod', - { - host: { - type: DataTypes.STRING, - allowNull: false, - validate: { - isHost: value => { - const res = isHostValid(value) - if (res === false) throw new Error('Host not valid.') - } - } - }, - score: { - type: DataTypes.INTEGER, - defaultValue: FRIEND_SCORE.BASE, - allowNull: false, - validate: { - isInt: true, - max: FRIEND_SCORE.MAX - } - } - }, - { - indexes: [ - { - fields: [ 'host' ], - unique: true - }, - { - fields: [ 'score' ] - } - ] - } - ) - - const classMethods = [ - countAll, - incrementScores, - list, - listForApi, - listAllIds, - listRandomPodIdsWithRequest, - listBadPods, - load, - loadByHost, - updatePodsScore, - removeAll - ] - const instanceMethods = [ toFormattedJSON ] - addMethodsToModel(Pod, classMethods, instanceMethods) - - return Pod -} - -// ------------------------------ METHODS ------------------------------ - -toFormattedJSON = function (this: PodInstance) { - const json = { - id: this.id, - host: this.host, - score: this.score as number, - createdAt: this.createdAt - } - - return json -} - -// ------------------------------ Statics ------------------------------ - -countAll = function () { - return Pod.count() -} - -incrementScores = function (ids: number[], value: number) { - const update = { - score: Sequelize.literal('score +' + value) - } - - const options = { - where: { - id: { - [Sequelize.Op.in]: ids - } - }, - // In this case score is a literal and not an integer so we do not validate it - validate: false - } - - return Pod.update(update, options) -} - -list = function () { - return Pod.findAll() -} - -listForApi = function (start: number, count: number, sort: string) { - const query = { - offset: start, - limit: count, - order: [ getSort(sort) ] - } - - return Pod.findAndCountAll(query).then(({ rows, count }) => { - return { - data: rows, - total: count - } - }) -} - -listAllIds = function (transaction: Sequelize.Transaction) { - const query = { - attributes: [ 'id' ], - transaction - } - - return Pod.findAll(query).then(pods => { - return map(pods, 'id') - }) -} - -listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, tableWithPodsJoins: string) { - return Pod.count().then(count => { - // Optimization... - if (count === 0) return [] - - let start = Math.floor(Math.random() * count) - limit - if (start < 0) start = 0 - - const subQuery = `(SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins})` - const query = { - attributes: [ 'id' ], - order: [ - [ 'id', 'ASC' ] - ], - offset: start, - limit: limit, - where: { - id: { - [Sequelize.Op.in]: Sequelize.literal(subQuery) - } - } - } - - return Pod.findAll(query).then(pods => { - return map(pods, 'id') - }) - }) -} - -listBadPods = function () { - const query = { - where: { - score: { - [Sequelize.Op.lte]: 0 - } - } - } - - return Pod.findAll(query) -} - -load = function (id: number) { - return Pod.findById(id) -} - -loadByHost = function (host: string) { - const query = { - where: { - host: host - } - } - - return Pod.findOne(query) -} - -removeAll = function () { - return Pod.destroy() -} - -updatePodsScore = function (goodPods: number[], badPods: number[]) { - logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length) - - if (goodPods.length !== 0) { - incrementScores(goodPods, PODS_SCORE.BONUS).catch(err => { - logger.error('Cannot increment scores of good pods.', err) - }) - } - - if (badPods.length !== 0) { - incrementScores(badPods, PODS_SCORE.PENALTY) - .then(() => removeBadPods()) - .catch(err => { - if (err) logger.error('Cannot decrement scores of bad pods.', err) - }) - } -} - -// --------------------------------------------------------------------------- - -// Remove pods with a score of 0 (too many requests where they were unreachable) -async function removeBadPods () { - try { - const pods = await listBadPods() - - const podsRemovePromises = pods.map(pod => pod.destroy()) - await Promise.all(podsRemovePromises) - - const numberOfPodsRemoved = pods.length - - if (numberOfPodsRemoved) { - logger.info('Removed %d pods.', numberOfPodsRemoved) - } else { - logger.info('No need to remove bad pods.') - } - } catch (err) { - logger.error('Cannot remove bad pods.', err) - } -} diff --git a/server/models/server/index.ts b/server/models/server/index.ts new file mode 100644 index 000000000..4cb2994aa --- /dev/null +++ b/server/models/server/index.ts @@ -0,0 +1 @@ +export * from './server-interface' diff --git a/server/models/server/server-interface.ts b/server/models/server/server-interface.ts new file mode 100644 index 000000000..806d052cb --- /dev/null +++ b/server/models/server/server-interface.ts @@ -0,0 +1,56 @@ +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +// Don't use barrel, import just what we need +import { ResultList } from '../../../shared/models/result-list.model' + +export namespace ServerMethods { + export type CountAll = () => Promise + + export type IncrementScores = (ids: number[], value: number) => Promise<[ number, ServerInstance[] ]> + + export type List = () => Promise + + export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList > + + export type ListAllIds = (transaction: Sequelize.Transaction) => Promise + + export type ListRandomServerIdsWithRequest = (limit: number, tableWithServers: string, tableWithServersJoins: string) => Promise + + export type ListBadServers = () => Promise + + export type Load = (id: number) => Promise + + export type LoadByHost = (host: string) => Promise + + export type RemoveAll = () => Promise + + export type UpdateServersScore = (goodServers: number[], badServers: number[]) => void +} + +export interface ServerClass { + countAll: ServerMethods.CountAll + incrementScores: ServerMethods.IncrementScores + list: ServerMethods.List + listForApi: ServerMethods.ListForApi + listAllIds: ServerMethods.ListAllIds + listRandomServerIdsWithRequest: ServerMethods.ListRandomServerIdsWithRequest + listBadServers: ServerMethods.ListBadServers + load: ServerMethods.Load + loadByHost: ServerMethods.LoadByHost + removeAll: ServerMethods.RemoveAll + updateServersScore: ServerMethods.UpdateServersScore +} + +export interface ServerAttributes { + id?: number + host?: string + score?: number | Sequelize.literal // Sequelize literal for 'score +' + value +} + +export interface ServerInstance extends ServerClass, ServerAttributes, Sequelize.Instance { + createdAt: Date + updatedAt: Date +} + +export interface ServerModel extends ServerClass, Sequelize.Model {} diff --git a/server/models/server/server.ts b/server/models/server/server.ts new file mode 100644 index 000000000..26fa87550 --- /dev/null +++ b/server/models/server/server.ts @@ -0,0 +1,233 @@ +import { map } from 'lodash' +import * as Sequelize from 'sequelize' + +import { FRIEND_SCORE, SERVERS_SCORE } from '../../initializers' +import { logger, isHostValid } from '../../helpers' + +import { addMethodsToModel, getSort } from '../utils' +import { + ServerInstance, + ServerAttributes, + + ServerMethods +} from './server-interface' + +let Server: Sequelize.Model +let countAll: ServerMethods.CountAll +let incrementScores: ServerMethods.IncrementScores +let list: ServerMethods.List +let listForApi: ServerMethods.ListForApi +let listAllIds: ServerMethods.ListAllIds +let listRandomServerIdsWithRequest: ServerMethods.ListRandomServerIdsWithRequest +let listBadServers: ServerMethods.ListBadServers +let load: ServerMethods.Load +let loadByHost: ServerMethods.LoadByHost +let removeAll: ServerMethods.RemoveAll +let updateServersScore: ServerMethods.UpdateServersScore + +export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { + Server = sequelize.define('Server', + { + host: { + type: DataTypes.STRING, + allowNull: false, + validate: { + isHost: value => { + const res = isHostValid(value) + if (res === false) throw new Error('Host not valid.') + } + } + }, + score: { + type: DataTypes.INTEGER, + defaultValue: FRIEND_SCORE.BASE, + allowNull: false, + validate: { + isInt: true, + max: FRIEND_SCORE.MAX + } + } + }, + { + indexes: [ + { + fields: [ 'host' ], + unique: true + }, + { + fields: [ 'score' ] + } + ] + } + ) + + const classMethods = [ + countAll, + incrementScores, + list, + listForApi, + listAllIds, + listRandomServerIdsWithRequest, + listBadServers, + load, + loadByHost, + updateServersScore, + removeAll + ] + addMethodsToModel(Server, classMethods) + + return Server +} + +// ------------------------------ Statics ------------------------------ + +countAll = function () { + return Server.count() +} + +incrementScores = function (ids: number[], value: number) { + const update = { + score: Sequelize.literal('score +' + value) + } + + const options = { + where: { + id: { + [Sequelize.Op.in]: ids + } + }, + // In this case score is a literal and not an integer so we do not validate it + validate: false + } + + return Server.update(update, options) +} + +list = function () { + return Server.findAll() +} + +listForApi = function (start: number, count: number, sort: string) { + const query = { + offset: start, + limit: count, + order: [ getSort(sort) ] + } + + return Server.findAndCountAll(query).then(({ rows, count }) => { + return { + data: rows, + total: count + } + }) +} + +listAllIds = function (transaction: Sequelize.Transaction) { + const query = { + attributes: [ 'id' ], + transaction + } + + return Server.findAll(query).then(servers => { + return map(servers, 'id') + }) +} + +listRandomServerIdsWithRequest = function (limit: number, tableWithServers: string, tableWithServersJoins: string) { + return Server.count().then(count => { + // Optimization... + if (count === 0) return [] + + let start = Math.floor(Math.random() * count) - limit + if (start < 0) start = 0 + + const subQuery = `(SELECT DISTINCT "${tableWithServers}"."serverId" FROM "${tableWithServers}" ${tableWithServersJoins})` + const query = { + attributes: [ 'id' ], + order: [ + [ 'id', 'ASC' ] + ], + offset: start, + limit: limit, + where: { + id: { + [Sequelize.Op.in]: Sequelize.literal(subQuery) + } + } + } + + return Server.findAll(query).then(servers => { + return map(servers, 'id') + }) + }) +} + +listBadServers = function () { + const query = { + where: { + score: { + [Sequelize.Op.lte]: 0 + } + } + } + + return Server.findAll(query) +} + +load = function (id: number) { + return Server.findById(id) +} + +loadByHost = function (host: string) { + const query = { + where: { + host: host + } + } + + return Server.findOne(query) +} + +removeAll = function () { + return Server.destroy() +} + +updateServersScore = function (goodServers: number[], badServers: number[]) { + logger.info('Updating %d good servers and %d bad servers scores.', goodServers.length, badServers.length) + + if (goodServers.length !== 0) { + incrementScores(goodServers, SERVERS_SCORE.BONUS).catch(err => { + logger.error('Cannot increment scores of good servers.', err) + }) + } + + if (badServers.length !== 0) { + incrementScores(badServers, SERVERS_SCORE.PENALTY) + .then(() => removeBadServers()) + .catch(err => { + if (err) logger.error('Cannot decrement scores of bad servers.', err) + }) + } +} + +// --------------------------------------------------------------------------- + +// Remove servers with a score of 0 (too many requests where they were unreachable) +async function removeBadServers () { + try { + const servers = await listBadServers() + + const serversRemovePromises = servers.map(server => server.destroy()) + await Promise.all(serversRemovePromises) + + const numberOfServersRemoved = servers.length + + if (numberOfServersRemoved) { + logger.info('Removed %d servers.', numberOfServersRemoved) + } else { + logger.info('No need to remove bad servers.') + } + } catch (err) { + logger.error('Cannot remove bad servers.', err) + } +} diff --git a/server/models/video/video-abuse-interface.ts b/server/models/video/video-abuse-interface.ts index 978268926..16806cae2 100644 --- a/server/models/video/video-abuse-interface.ts +++ b/server/models/video/video-abuse-interface.ts @@ -1,7 +1,7 @@ import * as Sequelize from 'sequelize' import * as Promise from 'bluebird' -import { PodInstance } from '../pod/pod-interface' +import { ServerInstance } from '../server/server-interface' import { ResultList } from '../../../shared' // Don't use barrel, import just what we need @@ -28,7 +28,7 @@ export interface VideoAbuseInstance extends VideoAbuseClass, VideoAbuseAttribute createdAt: Date updatedAt: Date - Pod: PodInstance + Server: ServerInstance toFormattedJSON: VideoAbuseMethods.ToFormattedJSON } diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index ebc63e7a0..c1d070ec0 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -45,7 +45,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da fields: [ 'videoId' ] }, { - fields: [ 'reporterPodId' ] + fields: [ 'reporterServerId' ] } ] } @@ -67,18 +67,18 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da // ------------------------------ METHODS ------------------------------ toFormattedJSON = function (this: VideoAbuseInstance) { - let reporterPodHost + let reporterServerHost - if (this.Pod) { - reporterPodHost = this.Pod.host + if (this.Server) { + reporterServerHost = this.Server.host } else { // It means it's our video - reporterPodHost = CONFIG.WEBSERVER.HOST + reporterServerHost = CONFIG.WEBSERVER.HOST } const json = { id: this.id, - reporterPodHost, + reporterServerHost, reason: this.reason, reporterUsername: this.reporterUsername, videoId: this.videoId, @@ -91,9 +91,9 @@ toFormattedJSON = function (this: VideoAbuseInstance) { // ------------------------------ STATICS ------------------------------ function associate (models) { - VideoAbuse.belongsTo(models.Pod, { + VideoAbuse.belongsTo(models.Server, { foreignKey: { - name: 'reporterPodId', + name: 'reporterServerId', allowNull: true }, onDelete: 'CASCADE' @@ -115,7 +115,7 @@ listForApi = function (start: number, count: number, sort: string) { order: [ getSort(sort) ], include: [ { - model: VideoAbuse['sequelize'].models.Pod, + model: VideoAbuse['sequelize'].models.Server, required: false } ] diff --git a/server/models/video/video-channel-interface.ts b/server/models/video/video-channel-interface.ts index 55e772063..8ad3e5cb7 100644 --- a/server/models/video/video-channel-interface.ts +++ b/server/models/video/video-channel-interface.ts @@ -22,7 +22,7 @@ export namespace VideoChannelMethods { export type LoadAndPopulateAccount = (id: number) => Promise export type LoadByUUIDAndPopulateAccount = (uuid: string) => Promise export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise - export type LoadByHostAndUUID = (uuid: string, podHost: string, t?: Sequelize.Transaction) => Promise + export type LoadByHostAndUUID = (uuid: string, serverHost: string, t?: Sequelize.Transaction) => Promise export type LoadAndPopulateAccountAndVideos = (id: number) => Promise export type LoadByUrl = (uuid: string, t?: Sequelize.Transaction) => Promise export type LoadByUUIDOrUrl = (uuid: string, url: string, t?: Sequelize.Transaction) => Promise diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 6d70f2aa2..3cb4a33b9 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -218,7 +218,7 @@ listForApi = function (start: number, count: number, sort: string) { { model: VideoChannel['sequelize'].models.Account, required: true, - include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] + include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ] } ] } @@ -238,7 +238,7 @@ listByAccount = function (accountId: number) { id: accountId }, required: true, - include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] + include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ] } ] } @@ -297,7 +297,7 @@ loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Tran model: VideoChannel['sequelize'].models.Account, include: [ { - model: VideoChannel['sequelize'].models.Pod, + model: VideoChannel['sequelize'].models.Server, required: true, where: { host: fromHost @@ -322,7 +322,7 @@ loadByIdAndAccount = function (id: number, accountId: number) { include: [ { model: VideoChannel['sequelize'].models.Account, - include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] + include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ] } ] } @@ -335,7 +335,7 @@ loadAndPopulateAccount = function (id: number) { include: [ { model: VideoChannel['sequelize'].models.Account, - include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] + include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ] } ] } @@ -351,7 +351,7 @@ loadByUUIDAndPopulateAccount = function (uuid: string) { include: [ { model: VideoChannel['sequelize'].models.Account, - include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] + include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ] } ] } @@ -364,7 +364,7 @@ loadAndPopulateAccountAndVideos = function (id: number) { include: [ { model: VideoChannel['sequelize'].models.Account, - include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] + include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ] }, VideoChannel['sequelize'].models.Video ] diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts index 7243756d2..4df33f801 100644 --- a/server/models/video/video-interface.ts +++ b/server/models/video/video-interface.ts @@ -46,7 +46,7 @@ export namespace VideoMethods { export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList > export type ListUserVideosForApi = (userId: number, start: number, count: number, sort: string) => Bluebird< ResultList > - export type SearchAndPopulateAccountAndPodAndTags = ( + export type SearchAndPopulateAccountAndServerAndTags = ( value: string, field: string, start: number, @@ -60,8 +60,8 @@ export namespace VideoMethods { export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Bluebird export type LoadAndPopulateAccount = (id: number) => Bluebird - export type LoadAndPopulateAccountAndPodAndTags = (id: number) => Bluebird - export type LoadByUUIDAndPopulateAccountAndPodAndTags = (uuid: string) => Bluebird + export type LoadAndPopulateAccountAndServerAndTags = (id: number) => Bluebird + export type LoadByUUIDAndPopulateAccountAndServerAndTags = (uuid: string) => Bluebird export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird export type RemoveThumbnail = (this: VideoInstance) => Promise @@ -79,14 +79,14 @@ export interface VideoClass { listOwnedByAccount: VideoMethods.ListOwnedByAccount load: VideoMethods.Load loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount - loadAndPopulateAccountAndPodAndTags: VideoMethods.LoadAndPopulateAccountAndPodAndTags + loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags loadByHostAndUUID: VideoMethods.LoadByHostAndUUID loadByUUID: VideoMethods.LoadByUUID loadByUrl: VideoMethods.LoadByUrl loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID - loadByUUIDAndPopulateAccountAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndPodAndTags - searchAndPopulateAccountAndPodAndTags: VideoMethods.SearchAndPopulateAccountAndPodAndTags + loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags + searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags } export interface VideoAttributes { diff --git a/server/models/video/video.ts b/server/models/video/video.ts index dd73dd7ca..86800fb88 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -88,9 +88,9 @@ let loadByUUID: VideoMethods.LoadByUUID let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount -let loadAndPopulateAccountAndPodAndTags: VideoMethods.LoadAndPopulateAccountAndPodAndTags -let loadByUUIDAndPopulateAccountAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndPodAndTags -let searchAndPopulateAccountAndPodAndTags: VideoMethods.SearchAndPopulateAccountAndPodAndTags +let loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags +let loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags +let searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags let removeThumbnail: VideoMethods.RemoveThumbnail let removePreview: VideoMethods.RemovePreview let removeFile: VideoMethods.RemoveFile @@ -275,13 +275,13 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da listOwnedByAccount, load, loadAndPopulateAccount, - loadAndPopulateAccountAndPodAndTags, + loadAndPopulateAccountAndServerAndTags, loadByHostAndUUID, loadByUUIDOrURL, loadByUUID, loadLocalVideoByUUID, - loadByUUIDAndPopulateAccountAndPodAndTags, - searchAndPopulateAccountAndPodAndTags + loadByUUIDAndPopulateAccountAndServerAndTags, + searchAndPopulateAccountAndServerAndTags ] const instanceMethods = [ createPreview, @@ -477,13 +477,13 @@ getPreviewPath = function (this: VideoInstance) { } toFormattedJSON = function (this: VideoInstance) { - let podHost + let serverHost - if (this.VideoChannel.Account.Pod) { - podHost = this.VideoChannel.Account.Pod.host + if (this.VideoChannel.Account.Server) { + serverHost = this.VideoChannel.Account.Server.host } else { // It means it's our video - podHost = CONFIG.WEBSERVER.HOST + serverHost = CONFIG.WEBSERVER.HOST } const json = { @@ -498,7 +498,7 @@ toFormattedJSON = function (this: VideoInstance) { languageLabel: this.getLanguageLabel(), nsfw: this.nsfw, description: this.getTruncatedDescription(), - podHost, + serverHost, isLocal: this.isOwned(), account: this.VideoChannel.Account.name, duration: this.duration, @@ -519,7 +519,7 @@ toFormattedJSON = function (this: VideoInstance) { toFormattedDetailsJSON = function (this: VideoInstance) { const formattedJson = this.toFormattedJSON() - // Maybe our pod is not up to date and there are new privacy settings since our version + // Maybe our server is not up to date and there are new privacy settings since our version let privacyLabel = VIDEO_PRIVACIES[this.privacy] if (!privacyLabel) privacyLabel = 'Unknown' @@ -721,7 +721,7 @@ getDescriptionPath = function (this: VideoInstance) { getCategoryLabel = function (this: VideoInstance) { let categoryLabel = VIDEO_CATEGORIES[this.category] - // Maybe our pod is not up to date and there are new categories since our version + // Maybe our server is not up to date and there are new categories since our version if (!categoryLabel) categoryLabel = 'Misc' return categoryLabel @@ -730,7 +730,7 @@ getCategoryLabel = function (this: VideoInstance) { getLicenceLabel = function (this: VideoInstance) { let licenceLabel = VIDEO_LICENCES[this.licence] - // Maybe our pod is not up to date and there are new licences since our version + // Maybe our server is not up to date and there are new licences since our version if (!licenceLabel) licenceLabel = 'Unknown' return licenceLabel @@ -830,7 +830,7 @@ listForApi = function (start: number, count: number, sort: string) { model: Video['sequelize'].models.Account, include: [ { - model: Video['sequelize'].models.Pod, + model: Video['sequelize'].models.Server, required: false } ] @@ -866,7 +866,7 @@ loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Tran model: Video['sequelize'].models.Account, include: [ { - model: Video['sequelize'].models.Pod, + model: Video['sequelize'].models.Server, required: true, where: { host: fromHost @@ -989,7 +989,7 @@ loadAndPopulateAccount = function (id: number) { return Video.findById(id, options) } -loadAndPopulateAccountAndPodAndTags = function (id: number) { +loadAndPopulateAccountAndServerAndTags = function (id: number) { const options = { include: [ { @@ -997,7 +997,7 @@ loadAndPopulateAccountAndPodAndTags = function (id: number) { include: [ { model: Video['sequelize'].models.Account, - include: [ { model: Video['sequelize'].models.Pod, required: false } ] + include: [ { model: Video['sequelize'].models.Server, required: false } ] } ] }, @@ -1009,7 +1009,7 @@ loadAndPopulateAccountAndPodAndTags = function (id: number) { return Video.findById(id, options) } -loadByUUIDAndPopulateAccountAndPodAndTags = function (uuid: string) { +loadByUUIDAndPopulateAccountAndServerAndTags = function (uuid: string) { const options = { where: { uuid @@ -1020,7 +1020,7 @@ loadByUUIDAndPopulateAccountAndPodAndTags = function (uuid: string) { include: [ { model: Video['sequelize'].models.Account, - include: [ { model: Video['sequelize'].models.Pod, required: false } ] + include: [ { model: Video['sequelize'].models.Server, required: false } ] } ] }, @@ -1032,15 +1032,15 @@ loadByUUIDAndPopulateAccountAndPodAndTags = function (uuid: string) { return Video.findOne(options) } -searchAndPopulateAccountAndPodAndTags = function (value: string, field: string, start: number, count: number, sort: string) { - const podInclude: Sequelize.IncludeOptions = { - model: Video['sequelize'].models.Pod, +searchAndPopulateAccountAndServerAndTags = function (value: string, field: string, start: number, count: number, sort: string) { + const serverInclude: Sequelize.IncludeOptions = { + model: Video['sequelize'].models.Server, required: false } const accountInclude: Sequelize.IncludeOptions = { model: Video['sequelize'].models.Account, - include: [ podInclude ] + include: [ serverInclude ] } const videoChannelInclude: Sequelize.IncludeOptions = { @@ -1071,13 +1071,13 @@ searchAndPopulateAccountAndPodAndTags = function (value: string, field: string, )` ) } else if (field === 'host') { - // FIXME: Include our pod? (not stored in the database) - podInclude.where = { + // FIXME: Include our server? (not stored in the database) + serverInclude.where = { host: { [Sequelize.Op.iLike]: '%' + value + '%' } } - podInclude.required = true + serverInclude.required = true } else if (field === 'account') { accountInclude.where = { name: { @@ -1123,8 +1123,8 @@ function getBaseUrls (video: VideoInstance) { baseUrlHttp = CONFIG.WEBSERVER.URL baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT } else { - baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + video.VideoChannel.Account.Pod.host - baseUrlWs = REMOTE_SCHEME.WS + '://' + video.VideoChannel.Account.Pod.host + baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + video.VideoChannel.Account.Server.host + baseUrlWs = REMOTE_SCHEME.WS + '://' + video.VideoChannel.Account.Server.host } return { baseUrlHttp, baseUrlWs } -- cgit v1.2.3