ActivityPub-federated video streaming platform using P2P directly in your web browser
Cleanup models
Chocobozzz39445ead45aa
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.tsindex a939a23d58..beb01da9b7 100644--- a/server/lib/video-channel.ts+++ b/server/lib/video-channel.ts@@ -1,6 +1,5 @@import * as Sequelize from 'sequelize'import { VideoChannelCreate } from '../../shared/models'-import { logger } from '../helpers'import { database as db } from '../initializers'import { AccountInstance } from '../models'import { getVideoChannelActivityPubUrl } from './activitypub/url'@@ -27,21 +26,8 @@ async function createVideoChannel (videoChannelInfo: VideoChannelCreate, accountreturn videoChannelCreated}-async function fetchVideoChannelByHostAndUUID (serverHost: string, uuid: string, t: Sequelize.Transaction) {- try {- const videoChannel = await db.VideoChannel.loadByHostAndUUID(serverHost, uuid, t)- if (!videoChannel) throw new Error('Video channel not found')-- return videoChannel- } catch (err) {- logger.error('Cannot load video channel from host and uuid.', { error: err.stack, serverHost, uuid })- throw err- }-}-// ---------------------------------------------------------------------------export {- createVideoChannel,- fetchVideoChannelByHostAndUUID+ createVideoChannel}diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.tsindex e30260f761..2e4b0382d1 100644--- a/server/models/account/account-interface.ts+++ b/server/models/account/account-interface.ts@@ -10,10 +10,8 @@ export namespace AccountMethods {export type Load = (id: number) => Bluebird<AccountInstance>export type LoadByUUID = (uuid: string) => Bluebird<AccountInstance>export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance>- export type LoadAccountByServerAndUUID = (uuid: string, serverId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance>export type LoadLocalByName = (name: string) => Bluebird<AccountInstance>export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance>- export type ListOwned = () => Bluebird<AccountInstance[]>export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActorexport type ToFormattedJSON = (this: AccountInstance) => FormattedAccount@@ -26,13 +24,11 @@ export namespace AccountMethods {export interface AccountClass {loadApplication: AccountMethods.LoadApplication- loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUIDload: AccountMethods.LoadloadByUUID: AccountMethods.LoadByUUIDloadByUrl: AccountMethods.LoadByUrlloadLocalByName: AccountMethods.LoadLocalByNameloadByNameAndHost: AccountMethods.LoadByNameAndHost- listOwned: AccountMethods.ListOwned}export interface AccountAttributes {diff --git a/server/models/account/account.ts b/server/models/account/account.tsindex 9a29215018..f2bd325f39 100644--- a/server/models/account/account.ts+++ b/server/models/account/account.ts@@ -20,14 +20,12 @@ import { addMethodsToModel } from '../utils'import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface'let Account: Sequelize.Model<AccountInstance, AccountAttributes>-let loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUIDlet load: AccountMethods.Loadlet loadApplication: AccountMethods.LoadApplicationlet loadByUUID: AccountMethods.LoadByUUIDlet loadByUrl: AccountMethods.LoadByUrllet loadLocalByName: AccountMethods.LoadLocalByNamelet loadByNameAndHost: AccountMethods.LoadByNameAndHost-let listOwned: AccountMethods.ListOwnedlet isOwned: AccountMethods.IsOwnedlet toActivityPubObject: AccountMethods.ToActivityPubObjectlet toFormattedJSON: AccountMethods.ToFormattedJSON@@ -185,14 +183,12 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypesconst classMethods = [associate,- loadAccountByServerAndUUID,loadApplication,load,loadByUUID,loadByUrl,loadLocalByName,- loadByNameAndHost,- listOwned+ loadByNameAndHost]const instanceMethods = [isOwned,@@ -355,16 +351,6 @@ getPublicKeyUrl = function (this: AccountInstance) {// ------------------------------ STATICS -------------------------------listOwned = function () {- const query: Sequelize.FindOptions<AccountAttributes> = {- where: {- serverId: null- }- }-- return Account.findAll(query)-}-loadApplication = function () {return Account.findOne({include: [@@ -441,15 +427,3 @@ loadByUrl = function (url: string, transaction?: Sequelize.Transaction) {return Account.findOne(query)}--loadAccountByServerAndUUID = function (uuid: string, serverId: number, transaction: Sequelize.Transaction) {- const query: Sequelize.FindOptions<AccountAttributes> = {- where: {- serverId,- uuid- },- transaction- }-- return Account.find(query)-}diff --git a/server/models/oauth/oauth-token-interface.ts b/server/models/oauth/oauth-token-interface.tsindex ef97893c40..47d95d5fc5 100644--- a/server/models/oauth/oauth-token-interface.ts+++ b/server/models/oauth/oauth-token-interface.ts@@ -1,5 +1,5 @@-import * as Sequelize from 'sequelize'import * as Promise from 'bluebird'+import * as Sequelize from 'sequelize'import { UserModel } from '../account/user-interface'@@ -18,15 +18,12 @@ export namespace OAuthTokenMethods {export type GetByRefreshTokenAndPopulateClient = (refreshToken: string) => Promise<OAuthTokenInfo>export type GetByTokenAndPopulateUser = (bearerToken: string) => Promise<OAuthTokenInstance>export type GetByRefreshTokenAndPopulateUser = (refreshToken: string) => Promise<OAuthTokenInstance>-- export type RemoveByUserId = (userId) => Promise<number>}export interface OAuthTokenClass {getByRefreshTokenAndPopulateClient: OAuthTokenMethods.GetByRefreshTokenAndPopulateClientgetByTokenAndPopulateUser: OAuthTokenMethods.GetByTokenAndPopulateUsergetByRefreshTokenAndPopulateUser: OAuthTokenMethods.GetByRefreshTokenAndPopulateUser- removeByUserId: OAuthTokenMethods.RemoveByUserId}export interface OAuthTokenAttributes {diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.tsindex c7afcc38cd..a82bff130a 100644--- a/server/models/oauth/oauth-token.ts+++ b/server/models/oauth/oauth-token.ts@@ -3,19 +3,12 @@ import * as Sequelize from 'sequelize'import { logger } from '../../helpers'import { addMethodsToModel } from '../utils'-import {- OAuthTokenInstance,- OAuthTokenAttributes,-- OAuthTokenMethods,- OAuthTokenInfo-} from './oauth-token-interface'+import { OAuthTokenAttributes, OAuthTokenInfo, OAuthTokenInstance, OAuthTokenMethods } from './oauth-token-interface'let OAuthToken: Sequelize.Model<OAuthTokenInstance, OAuthTokenAttributes>let getByRefreshTokenAndPopulateClient: OAuthTokenMethods.GetByRefreshTokenAndPopulateClientlet getByTokenAndPopulateUser: OAuthTokenMethods.GetByTokenAndPopulateUserlet getByRefreshTokenAndPopulateUser: OAuthTokenMethods.GetByRefreshTokenAndPopulateUser-let removeByUserId: OAuthTokenMethods.RemoveByUserIdexport default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {OAuthToken = sequelize.define<OAuthTokenInstance, OAuthTokenAttributes>('OAuthToken',@@ -62,8 +55,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DagetByRefreshTokenAndPopulateClient,getByTokenAndPopulateUser,- getByRefreshTokenAndPopulateUser,- removeByUserId+ getByRefreshTokenAndPopulateUser]addMethodsToModel(OAuthToken, classMethods)@@ -170,13 +162,3 @@ getByRefreshTokenAndPopulateUser = function (refreshToken: string) {return token})}--removeByUserId = function (userId: number) {- const query = {- where: {- userId: userId- }- }-- return OAuthToken.destroy(query)-}diff --git a/server/models/server/server-interface.ts b/server/models/server/server-interface.tsindex 806d052cb3..be1a4917e0 100644--- a/server/models/server/server-interface.ts+++ b/server/models/server/server-interface.ts@@ -1,45 +1,13 @@-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'+import * as Sequelize from 'sequelize'export namespace ServerMethods {- export type CountAll = () => Promise<number>-- export type IncrementScores = (ids: number[], value: number) => Promise<[ number, ServerInstance[] ]>-- export type List = () => Promise<ServerInstance[]>-- export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<ServerInstance> >-- export type ListAllIds = (transaction: Sequelize.Transaction) => Promise<number[]>-- export type ListRandomServerIdsWithRequest = (limit: number, tableWithServers: string, tableWithServersJoins: string) => Promise<number[]>-export type ListBadServers = () => Promise<ServerInstance[]>-- export type Load = (id: number) => Promise<ServerInstance>-- export type LoadByHost = (host: string) => Promise<ServerInstance>-- export type RemoveAll = () => Promise<number>-- export type UpdateServersScore = (goodServers: number[], badServers: number[]) => void+ export type UpdateServersScoreAndRemoveBadOnes = (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+ updateServersScoreAndRemoveBadOnes: ServerMethods.UpdateServersScoreAndRemoveBadOnes}export interface ServerAttributes {diff --git a/server/models/server/server.ts b/server/models/server/server.tsindex 26fa875509..75cd5f929b 100644--- a/server/models/server/server.ts+++ b/server/models/server/server.ts@@ -1,29 +1,11 @@-import { map } from 'lodash'import * as Sequelize from 'sequelize'-+import { isHostValid, logger } from '../../helpers'import { FRIEND_SCORE, SERVERS_SCORE } from '../../initializers'-import { logger, isHostValid } from '../../helpers'--import { addMethodsToModel, getSort } from '../utils'-import {- ServerInstance,- ServerAttributes,-- ServerMethods-} from './server-interface'+import { addMethodsToModel } from '../utils'+import { ServerAttributes, ServerInstance, ServerMethods } from './server-interface'let Server: Sequelize.Model<ServerInstance, ServerAttributes>-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+let updateServersScoreAndRemoveBadOnes: ServerMethods.UpdateServersScoreAndRemoveBadOnesexport default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {Server = sequelize.define<ServerInstance, ServerAttributes>('Server',@@ -62,17 +44,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da)const classMethods = [- countAll,- incrementScores,- list,- listForApi,- listAllIds,- listRandomServerIdsWithRequest,- listBadServers,- load,- loadByHost,- updateServersScore,- removeAll+ listBadServers]addMethodsToModel(Server, classMethods)@@ -81,118 +53,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da// ------------------------------ 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[]) {+updateServersScoreAndRemoveBadOnes = function (goodServers: number[], badServers: number[]) {logger.info('Updating %d good servers and %d bad servers scores.', goodServers.length, badServers.length)if (goodServers.length !== 0) {@@ -231,3 +92,33 @@ async function removeBadServers () {logger.error('Cannot remove bad servers.', err)}}++function incrementScores (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)+}++function listBadServers () {+ const query = {+ where: {+ score: {+ [Sequelize.Op.lte]: 0+ }+ }+ }++ return Server.findAll(query)+}diff --git a/server/models/video/video-blacklist-interface.ts b/server/models/video/video-blacklist-interface.tsindex 9d167c0374..be2483d4c0 100644--- a/server/models/video/video-blacklist-interface.ts+++ b/server/models/video/video-blacklist-interface.ts@@ -10,24 +10,13 @@ import { BlacklistedVideo as FormattedBlacklistedVideo } from '../../../shared/mexport namespace BlacklistedVideoMethods {export type ToFormattedJSON = (this: BlacklistedVideoInstance) => FormattedBlacklistedVideo-- export type CountTotal = () => Promise<number>-- export type List = () => Promise<BlacklistedVideoInstance[]>-export type ListForApi = (start: number, count: number, sort: SortType) => Promise< ResultList<BlacklistedVideoInstance> >-- export type LoadById = (id: number) => Promise<BlacklistedVideoInstance>-export type LoadByVideoId = (id: number) => Promise<BlacklistedVideoInstance>}export interface BlacklistedVideoClass {toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON- countTotal: BlacklistedVideoMethods.CountTotal- list: BlacklistedVideoMethods.ListlistForApi: BlacklistedVideoMethods.ListForApi- loadById: BlacklistedVideoMethods.LoadByIdloadByVideoId: BlacklistedVideoMethods.LoadByVideoId}diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.tsindex 1c279b1bae..ae8286285c 100644--- a/server/models/video/video-blacklist.ts+++ b/server/models/video/video-blacklist.ts@@ -12,10 +12,7 @@ import {let BlacklistedVideo: Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes>let toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON-let countTotal: BlacklistedVideoMethods.CountTotal-let list: BlacklistedVideoMethods.Listlet listForApi: BlacklistedVideoMethods.ListForApi-let loadById: BlacklistedVideoMethods.LoadByIdlet loadByVideoId: BlacklistedVideoMethods.LoadByVideoIdexport default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {@@ -34,10 +31,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Daconst classMethods = [associate,- countTotal,- list,listForApi,- loadById,loadByVideoId]const instanceMethods = [@@ -83,14 +77,6 @@ function associate (models) {})}-countTotal = function () {- return BlacklistedVideo.count()-}--list = function () {- return BlacklistedVideo.findAll()-}-listForApi = function (start: number, count: number, sort: SortType) {const query = {offset: start,@@ -107,10 +93,6 @@ listForApi = function (start: number, count: number, sort: SortType) {})}-loadById = function (id: number) {- return BlacklistedVideo.findById(id)-}-loadByVideoId = function (id: number) {const query = {where: {diff --git a/server/models/video/video-channel-interface.ts b/server/models/video/video-channel-interface.tsindex 8ad3e5cb7a..b409d1db3d 100644--- a/server/models/video/video-channel-interface.ts+++ b/server/models/video/video-channel-interface.ts@@ -1,13 +1,11 @@-import * as Sequelize from 'sequelize'import * as Promise from 'bluebird'+import * as Sequelize from 'sequelize'import { ResultList } from '../../../shared'--// Don't use barrel, import just what we need+import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object'import { VideoChannel as FormattedVideoChannel } from '../../../shared/models/videos/video-channel.model'-import { VideoInstance } from './video-interface'import { AccountInstance } from '../account/account-interface'-import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object'+import { VideoInstance } from './video-interface'export namespace VideoChannelMethods {export type ToFormattedJSON = (this: VideoChannelInstance) => FormattedVideoChannel@@ -15,7 +13,6 @@ export namespace VideoChannelMethods {export type IsOwned = (this: VideoChannelInstance) => booleanexport type CountByAccount = (accountId: number) => Promise<number>- export type ListOwned = () => Promise<VideoChannelInstance[]>export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoChannelInstance> >export type LoadByIdAndAccount = (id: number, accountId: number) => Promise<VideoChannelInstance>export type ListByAccount = (accountId: number) => Promise< ResultList<VideoChannelInstance> >@@ -32,10 +29,7 @@ export interface VideoChannelClass {countByAccount: VideoChannelMethods.CountByAccountlistForApi: VideoChannelMethods.ListForApilistByAccount: VideoChannelMethods.ListByAccount- listOwned: VideoChannelMethods.ListOwnedloadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount- loadByUUID: VideoChannelMethods.LoadByUUID- loadByHostAndUUID: VideoChannelMethods.LoadByHostAndUUIDloadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccountloadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccountloadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideosdiff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.tsindex 93566a5c64..64130310d4 100644--- a/server/models/video/video-channel.ts+++ b/server/models/video/video-channel.ts@@ -12,7 +12,6 @@ let toFormattedJSON: VideoChannelMethods.ToFormattedJSONlet toActivityPubObject: VideoChannelMethods.ToActivityPubObjectlet isOwned: VideoChannelMethods.IsOwnedlet countByAccount: VideoChannelMethods.CountByAccount-let listOwned: VideoChannelMethods.ListOwnedlet listForApi: VideoChannelMethods.ListForApilet listByAccount: VideoChannelMethods.ListByAccountlet loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount@@ -88,7 +87,6 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DalistForApi,listByAccount,- listOwned,loadByIdAndAccount,loadAndPopulateAccount,loadByUUIDAndPopulateAccount,@@ -192,17 +190,6 @@ countByAccount = function (accountId: number) {return VideoChannel.count(query)}-listOwned = function () {- const query = {- where: {- remote: false- },- include: [ VideoChannel['sequelize'].models.Account ]- }-- return VideoChannel.findAll(query)-}-listForApi = function (start: number, count: number, sort: string) {const query = {offset: start,diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.tsindex 89e528acf2..be140de86a 100644--- a/server/models/video/video-interface.ts+++ b/server/models/video/video-interface.ts@@ -3,13 +3,12 @@ import * as Sequelize from 'sequelize'import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'import { ResultList } from '../../../shared/models/result-list.model'import { Video as FormattedVideo, VideoDetails as FormattedDetailsVideo } from '../../../shared/models/videos/video.model'+import { AccountVideoRateInstance } from '../account/account-video-rate-interface'import { TagAttributes, TagInstance } from './tag-interface'import { VideoChannelInstance } from './video-channel-interface'import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'import { VideoShareInstance } from './video-share-interface'-import { UserVideoRate } from '../../../shared/models/videos/user-video-rate.model'-import { AccountVideoRateInstance } from '../account/account-video-rate-interface'export namespace VideoMethods {export type GetThumbnailName = (this: VideoInstance) => string@@ -40,12 +39,7 @@ export namespace VideoMethods {export type GetLicenceLabel = (this: VideoInstance) => stringexport type GetLanguageLabel = (this: VideoInstance) => string- // Return thumbnail name- export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string) => Promise<string>-export type List = () => Bluebird<VideoInstance[]>- export type ListOwnedAndPopulateAccountAndTags = () => Bluebird<VideoInstance[]>- export type ListOwnedByAccount = (account: string) => Bluebird<VideoInstance[]>export type ListAllAndSharedByAccountForOutbox = (accountId: number,@@ -65,9 +59,6 @@ export namespace VideoMethods {export type Load = (id: number) => Bluebird<VideoInstance>export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>export type LoadByUrlAndPopulateAccount = (url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>- export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>- export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>- export type LoadAndPopulateAccount = (id: number) => Bluebird<VideoInstance>export type LoadAndPopulateAccountAndServerAndTags = (id: number) => Bluebird<VideoInstance>export type LoadByUUIDAndPopulateAccountAndServerAndTags = (uuid: string) => Bluebird<VideoInstance>export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>@@ -79,21 +70,15 @@ export namespace VideoMethods {}export interface VideoClass {- generateThumbnailFromData: VideoMethods.GenerateThumbnailFromDatalist: VideoMethods.ListlistAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutboxlistForApi: VideoMethods.ListForApilistUserVideosForApi: VideoMethods.ListUserVideosForApi- listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags- listOwnedByAccount: VideoMethods.ListOwnedByAccountload: VideoMethods.Load- loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccountloadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags- loadByHostAndUUID: VideoMethods.LoadByHostAndUUIDloadByUUID: VideoMethods.LoadByUUIDloadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccountloadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL- loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUIDloadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTagssearchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags}diff --git a/server/models/video/video.ts b/server/models/video/video.tsindex 592fc2d595..e5fd925490 100644--- a/server/models/video/video.ts+++ b/server/models/video/video.ts@@ -1,8 +1,8 @@+import * as Bluebird from 'bluebird'import { map, maxBy, truncate } from 'lodash'import * as magnetUtil from 'magnet-uri'import * as parseTorrent from 'parse-torrent'import { join } from 'path'-import * as safeBuffer from 'safe-buffer'import * as Sequelize from 'sequelize'import { VideoPrivacy, VideoResolution } from '../../../shared'import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'@@ -25,6 +25,7 @@ import {unlinkPromise,writeFilePromise} from '../../helpers'+import { activityPubCollection } from '../../helpers/activitypub'import { isVideoUrlValid } from '../../helpers/custom-validators/videos'import {API_VERSION,@@ -39,17 +40,13 @@ import {VIDEO_LICENCES,VIDEO_PRIVACIES} from '../../initializers'+import { sendDeleteVideo } from '../../lib/index'import { addMethodsToModel, getSort } from '../utils'import { TagInstance } from './tag-interface'import { VideoFileInstance, VideoFileModel } from './video-file-interface'import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface'-import { sendDeleteVideo } from '../../lib/index'-import * as Bluebird from 'bluebird'-import { activityPubCollection } from '../../helpers/activitypub'--const Buffer = safeBuffer.Bufferlet Video: Sequelize.Model<VideoInstance, VideoAttributes>let getOriginalFile: VideoMethods.GetOriginalFile@@ -77,20 +74,14 @@ let getCategoryLabel: VideoMethods.GetCategoryLabellet getLicenceLabel: VideoMethods.GetLicenceLabellet getLanguageLabel: VideoMethods.GetLanguageLabel-let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromDatalet list: VideoMethods.Listlet listForApi: VideoMethods.ListForApilet listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutboxlet listUserVideosForApi: VideoMethods.ListUserVideosForApi-let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID-let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags-let listOwnedByAccount: VideoMethods.ListOwnedByAccountlet load: VideoMethods.Loadlet loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccountlet loadByUUID: VideoMethods.LoadByUUIDlet loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL-let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID-let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccountlet loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTagslet loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTagslet searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags@@ -267,21 +258,15 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Daconst classMethods = [associate,- generateThumbnailFromData,list,listAllAndSharedByAccountForOutbox,listForApi,listUserVideosForApi,- listOwnedAndPopulateAccountAndTags,- listOwnedByAccount,load,loadByUrlAndPopulateAccount,- loadAndPopulateAccount,loadAndPopulateAccountAndServerAndTags,- loadByHostAndUUID,loadByUUIDOrURL,loadByUUID,- loadLocalVideoByUUID,loadByUUIDAndPopulateAccountAndServerAndTags,searchAndPopulateAccountAndServerAndTags]@@ -803,16 +788,6 @@ removeTorrent = function (this: VideoInstance, videoFile: VideoFileInstance) {// ------------------------------ STATICS -------------------------------generateThumbnailFromData = function (video: VideoInstance, thumbnailData: string) {- // Creating the thumbnail for a remote video-- const thumbnailName = video.getThumbnailName()- const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName)- return writeFilePromise(thumbnailPath, Buffer.from(thumbnailData, 'binary')).then(() => {- return thumbnailName- })-}-list = function () {const query = {include: [ Video['sequelize'].models.VideoFile ]@@ -970,84 +945,6 @@ listForApi = function (start: number, count: number, sort: string) {})}-loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Transaction) {- const query: Sequelize.FindOptions<VideoAttributes> = {- where: {- uuid- },- include: [- {- model: Video['sequelize'].models.VideoFile- },- {- model: Video['sequelize'].models.VideoChannel,- include: [- {- model: Video['sequelize'].models.Account,- include: [- {- model: Video['sequelize'].models.Server,- required: true,- where: {- host: fromHost- }- }- ]- }- ]- }- ]- }-- if (t !== undefined) query.transaction = t-- return Video.findOne(query)-}--listOwnedAndPopulateAccountAndTags = function () {- const query = {- where: {- remote: false- },- include: [- Video['sequelize'].models.VideoFile,- {- model: Video['sequelize'].models.VideoChannel,- include: [ Video['sequelize'].models.Account ]- },- Video['sequelize'].models.Tag- ]- }-- return Video.findAll(query)-}--listOwnedByAccount = function (account: string) {- const query = {- where: {- remote: false- },- include: [- {- model: Video['sequelize'].models.VideoFile- },- {- model: Video['sequelize'].models.VideoChannel,- include: [- {- model: Video['sequelize'].models.Account,- where: {- name: account- }- }- ]- }- ]- }-- return Video.findAll(query)-}-load = function (id: number) {return Video.findById(id)}@@ -1100,34 +997,6 @@ loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transactionreturn Video.findOne(query)}-loadLocalVideoByUUID = function (uuid: string, t?: Sequelize.Transaction) {- const query: Sequelize.FindOptions<VideoAttributes> = {- where: {- uuid,- remote: false- },- include: [ Video['sequelize'].models.VideoFile ]- }-- if (t !== undefined) query.transaction = t-- return Video.findOne(query)-}--loadAndPopulateAccount = function (id: number) {- const options = {- include: [- Video['sequelize'].models.VideoFile,- {- model: Video['sequelize'].models.VideoChannel,- include: [ Video['sequelize'].models.Account ]- }- ]- }-- return Video.findById(id, options)-}-loadAndPopulateAccountAndServerAndTags = function (id: number) {const options = {include: [