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'
return 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
}
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) => ActivityPubActor
export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount
export interface AccountClass {
loadApplication: AccountMethods.LoadApplication
- loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID
load: AccountMethods.Load
loadByUUID: AccountMethods.LoadByUUID
loadByUrl: AccountMethods.LoadByUrl
loadLocalByName: AccountMethods.LoadLocalByName
loadByNameAndHost: AccountMethods.LoadByNameAndHost
- listOwned: AccountMethods.ListOwned
}
export interface AccountAttributes {
import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface'
let Account: Sequelize.Model<AccountInstance, AccountAttributes>
-let loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID
let load: AccountMethods.Load
let loadApplication: AccountMethods.LoadApplication
let loadByUUID: AccountMethods.LoadByUUID
let loadByUrl: AccountMethods.LoadByUrl
let loadLocalByName: AccountMethods.LoadLocalByName
let loadByNameAndHost: AccountMethods.LoadByNameAndHost
-let listOwned: AccountMethods.ListOwned
let isOwned: AccountMethods.IsOwned
let toActivityPubObject: AccountMethods.ToActivityPubObject
let toFormattedJSON: AccountMethods.ToFormattedJSON
const classMethods = [
associate,
- loadAccountByServerAndUUID,
loadApplication,
load,
loadByUUID,
loadByUrl,
loadLocalByName,
- loadByNameAndHost,
- listOwned
+ loadByNameAndHost
]
const instanceMethods = [
isOwned,
// ------------------------------ STATICS ------------------------------
-listOwned = function () {
- const query: Sequelize.FindOptions<AccountAttributes> = {
- where: {
- serverId: null
- }
- }
-
- return Account.findAll(query)
-}
-
loadApplication = function () {
return Account.findOne({
include: [
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)
-}
-import * as Sequelize from 'sequelize'
import * as Promise from 'bluebird'
+import * as Sequelize from 'sequelize'
import { UserModel } from '../account/user-interface'
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.GetByRefreshTokenAndPopulateClient
getByTokenAndPopulateUser: OAuthTokenMethods.GetByTokenAndPopulateUser
getByRefreshTokenAndPopulateUser: OAuthTokenMethods.GetByRefreshTokenAndPopulateUser
- removeByUserId: OAuthTokenMethods.RemoveByUserId
}
export interface OAuthTokenAttributes {
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.GetByRefreshTokenAndPopulateClient
let getByTokenAndPopulateUser: OAuthTokenMethods.GetByTokenAndPopulateUser
let getByRefreshTokenAndPopulateUser: OAuthTokenMethods.GetByRefreshTokenAndPopulateUser
-let removeByUserId: OAuthTokenMethods.RemoveByUserId
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
OAuthToken = sequelize.define<OAuthTokenInstance, OAuthTokenAttributes>('OAuthToken',
getByRefreshTokenAndPopulateClient,
getByTokenAndPopulateUser,
- getByRefreshTokenAndPopulateUser,
- removeByUserId
+ getByRefreshTokenAndPopulateUser
]
addMethodsToModel(OAuthToken, classMethods)
return token
})
}
-
-removeByUserId = function (userId: number) {
- const query = {
- where: {
- userId: userId
- }
- }
-
- return OAuthToken.destroy(query)
-}
-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 {
-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.UpdateServersScoreAndRemoveBadOnes
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
Server = sequelize.define<ServerInstance, ServerAttributes>('Server',
)
const classMethods = [
- countAll,
- incrementScores,
- list,
- listForApi,
- listAllIds,
- listRandomServerIdsWithRequest,
- listBadServers,
- load,
- loadByHost,
- updateServersScore,
- removeAll
+ listBadServers
]
addMethodsToModel(Server, classMethods)
// ------------------------------ 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) {
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)
+}
export 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.List
listForApi: BlacklistedVideoMethods.ListForApi
- loadById: BlacklistedVideoMethods.LoadById
loadByVideoId: BlacklistedVideoMethods.LoadByVideoId
}
let BlacklistedVideo: Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes>
let toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON
-let countTotal: BlacklistedVideoMethods.CountTotal
-let list: BlacklistedVideoMethods.List
let listForApi: BlacklistedVideoMethods.ListForApi
-let loadById: BlacklistedVideoMethods.LoadById
let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
const classMethods = [
associate,
- countTotal,
- list,
listForApi,
- loadById,
loadByVideoId
]
const instanceMethods = [
})
}
-countTotal = function () {
- return BlacklistedVideo.count()
-}
-
-list = function () {
- return BlacklistedVideo.findAll()
-}
-
listForApi = function (start: number, count: number, sort: SortType) {
const query = {
offset: start,
})
}
-loadById = function (id: number) {
- return BlacklistedVideo.findById(id)
-}
-
loadByVideoId = function (id: number) {
const query = {
where: {
-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
export type IsOwned = (this: VideoChannelInstance) => boolean
export 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> >
countByAccount: VideoChannelMethods.CountByAccount
listForApi: VideoChannelMethods.ListForApi
listByAccount: VideoChannelMethods.ListByAccount
- listOwned: VideoChannelMethods.ListOwned
loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount
- loadByUUID: VideoChannelMethods.LoadByUUID
- loadByHostAndUUID: VideoChannelMethods.LoadByHostAndUUID
loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount
loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount
loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos
let toActivityPubObject: VideoChannelMethods.ToActivityPubObject
let isOwned: VideoChannelMethods.IsOwned
let countByAccount: VideoChannelMethods.CountByAccount
-let listOwned: VideoChannelMethods.ListOwned
let listForApi: VideoChannelMethods.ListForApi
let listByAccount: VideoChannelMethods.ListByAccount
let loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount
listForApi,
listByAccount,
- listOwned,
loadByIdAndAccount,
loadAndPopulateAccount,
loadByUUIDAndPopulateAccount,
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,
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
export type GetLicenceLabel = (this: VideoInstance) => string
export 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,
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>
}
export interface VideoClass {
- generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
list: VideoMethods.List
listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
listForApi: VideoMethods.ListForApi
listUserVideosForApi: VideoMethods.ListUserVideosForApi
- listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
- listOwnedByAccount: VideoMethods.ListOwnedByAccount
load: VideoMethods.Load
- loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount
loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags
- loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
loadByUUID: VideoMethods.LoadByUUID
loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount
loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
- loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags
searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags
}
+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'
unlinkPromise,
writeFilePromise
} from '../../helpers'
+import { activityPubCollection } from '../../helpers/activitypub'
import { isVideoUrlValid } from '../../helpers/custom-validators/videos'
import {
API_VERSION,
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.Buffer
let Video: Sequelize.Model<VideoInstance, VideoAttributes>
let getOriginalFile: VideoMethods.GetOriginalFile
let getLicenceLabel: VideoMethods.GetLicenceLabel
let getLanguageLabel: VideoMethods.GetLanguageLabel
-let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
let list: VideoMethods.List
let listForApi: VideoMethods.ListForApi
let listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
let listUserVideosForApi: VideoMethods.ListUserVideosForApi
-let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
-let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
-let listOwnedByAccount: VideoMethods.ListOwnedByAccount
let load: VideoMethods.Load
let loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount
let loadByUUID: VideoMethods.LoadByUUID
let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
-let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
-let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount
let loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags
let loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags
let searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags
const classMethods = [
associate,
- generateThumbnailFromData,
list,
listAllAndSharedByAccountForOutbox,
listForApi,
listUserVideosForApi,
- listOwnedAndPopulateAccountAndTags,
- listOwnedByAccount,
load,
loadByUrlAndPopulateAccount,
- loadAndPopulateAccount,
loadAndPopulateAccountAndServerAndTags,
- loadByHostAndUUID,
loadByUUIDOrURL,
loadByUUID,
- loadLocalVideoByUUID,
loadByUUIDAndPopulateAccountAndServerAndTags,
searchAndPopulateAccountAndServerAndTags
]
// ------------------------------ 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 ]
})
}
-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)
}
return 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: [