let getTorrentFileName: VideoMethods.GetTorrentFileName
let isOwned: VideoMethods.IsOwned
let toFormattedJSON: VideoMethods.ToFormattedJSON
+let toFormattedDetailsJSON: VideoMethods.ToFormattedDetailsJSON
let toAddRemoteJSON: VideoMethods.ToAddRemoteJSON
let toUpdateRemoteJSON: VideoMethods.ToUpdateRemoteJSON
let optimizeOriginalVideofile: VideoMethods.OptimizeOriginalVideofile
let listOwnedByAuthor: VideoMethods.ListOwnedByAuthor
let load: VideoMethods.Load
let loadByUUID: VideoMethods.LoadByUUID
+let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
let loadAndPopulateAuthor: VideoMethods.LoadAndPopulateAuthor
let loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
let loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
},
{
indexes: [
- {
- fields: [ 'authorId' ]
- },
{
fields: [ 'name' ]
},
},
{
fields: [ 'uuid' ]
+ },
+ {
+ fields: [ 'channelId' ]
}
],
hooks: {
loadAndPopulateAuthorAndPodAndTags,
loadByHostAndUUID,
loadByUUID,
+ loadLocalVideoByUUID,
loadByUUIDAndPopulateAuthorAndPodAndTags,
searchAndPopulateAuthorAndPodAndTags
]
removeTorrent,
toAddRemoteJSON,
toFormattedJSON,
+ toFormattedDetailsJSON,
toUpdateRemoteJSON,
optimizeOriginalVideofile,
transcodeOriginalVideofile,
// ------------------------------ METHODS ------------------------------
function associate (models) {
- Video.belongsTo(models.Author, {
+ Video.belongsTo(models.VideoChannel, {
foreignKey: {
- name: 'authorId',
+ name: 'channelId',
allowNull: false
},
onDelete: 'cascade'
toFormattedJSON = function (this: VideoInstance) {
let podHost
- if (this.Author.Pod) {
- podHost = this.Author.Pod.host
+ if (this.VideoChannel.Author.Pod) {
+ podHost = this.VideoChannel.Author.Pod.host
+ } else {
+ // It means it's our video
+ podHost = CONFIG.WEBSERVER.HOST
+ }
+
+ // Maybe our pod is not up to date and there are new categories since our version
+ let categoryLabel = VIDEO_CATEGORIES[this.category]
+ if (!categoryLabel) categoryLabel = 'Misc'
+
+ // Maybe our pod is not up to date and there are new licences since our version
+ let licenceLabel = VIDEO_LICENCES[this.licence]
+ if (!licenceLabel) licenceLabel = 'Unknown'
+
+ // Language is an optional attribute
+ let languageLabel = VIDEO_LANGUAGES[this.language]
+ if (!languageLabel) languageLabel = 'Unknown'
+
+ const json = {
+ id: this.id,
+ uuid: this.uuid,
+ name: this.name,
+ category: this.category,
+ categoryLabel,
+ licence: this.licence,
+ licenceLabel,
+ language: this.language,
+ languageLabel,
+ nsfw: this.nsfw,
+ description: this.description,
+ podHost,
+ isLocal: this.isOwned(),
+ author: this.VideoChannel.Author.name,
+ duration: this.duration,
+ views: this.views,
+ likes: this.likes,
+ dislikes: this.dislikes,
+ tags: map<TagInstance, string>(this.Tags, 'name'),
+ thumbnailPath: this.getThumbnailPath(),
+ previewPath: this.getPreviewPath(),
+ embedPath: this.getEmbedPath(),
+ createdAt: this.createdAt,
+ updatedAt: this.updatedAt
+ }
+
+ return json
+}
+
+toFormattedDetailsJSON = function (this: VideoInstance) {
+ let podHost
+
+ if (this.VideoChannel.Author.Pod) {
+ podHost = this.VideoChannel.Author.Pod.host
} else {
// It means it's our video
podHost = CONFIG.WEBSERVER.HOST
description: this.description,
podHost,
isLocal: this.isOwned(),
- author: this.Author.name,
+ author: this.VideoChannel.Author.name,
duration: this.duration,
views: this.views,
likes: this.likes,
embedPath: this.getEmbedPath(),
createdAt: this.createdAt,
updatedAt: this.updatedAt,
+ channel: this.VideoChannel.toFormattedJSON(),
files: []
}
language: this.language,
nsfw: this.nsfw,
description: this.description,
- author: this.Author.name,
+ channelUUID: this.VideoChannel.uuid,
duration: this.duration,
thumbnailData: thumbnailData.toString('binary'),
tags: map<TagInstance, string>(this.Tags, 'name'),
language: this.language,
nsfw: this.nsfw,
description: this.description,
- author: this.Author.name,
duration: this.duration,
tags: map<TagInstance, string>(this.Tags, 'name'),
createdAt: this.createdAt,
order: [ getSort(sort), [ Video['sequelize'].models.Tag, 'name', 'ASC' ] ],
include: [
{
- model: Video['sequelize'].models.Author,
- include: [ { model: Video['sequelize'].models.Pod, required: false } ]
+ model: Video['sequelize'].models.VideoChannel,
+ include: [
+ {
+ model: Video['sequelize'].models.Author,
+ include: [
+ {
+ model: Video['sequelize'].models.Pod,
+ required: false
+ }
+ ]
+ }
+ ]
},
Video['sequelize'].models.Tag,
Video['sequelize'].models.VideoFile
})
}
-loadByHostAndUUID = function (fromHost: string, uuid: string) {
- const query = {
+loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Transaction) {
+ const query: Sequelize.FindOptions<VideoAttributes> = {
where: {
uuid
},
model: Video['sequelize'].models.VideoFile
},
{
- model: Video['sequelize'].models.Author,
+ model: Video['sequelize'].models.VideoChannel,
include: [
{
- model: Video['sequelize'].models.Pod,
- required: true,
- where: {
- host: fromHost
- }
+ model: Video['sequelize'].models.Author,
+ include: [
+ {
+ model: Video['sequelize'].models.Pod,
+ required: true,
+ where: {
+ host: fromHost
+ }
+ }
+ ]
}
]
}
]
}
+ if (t !== undefined) query.transaction = t
+
return Video.findOne(query)
}
},
include: [
Video['sequelize'].models.VideoFile,
- Video['sequelize'].models.Author,
+ {
+ model: Video['sequelize'].models.VideoChannel,
+ include: [ Video['sequelize'].models.Author ]
+ },
Video['sequelize'].models.Tag
]
}
model: Video['sequelize'].models.VideoFile
},
{
- model: Video['sequelize'].models.Author,
- where: {
- name: author
- }
+ model: Video['sequelize'].models.VideoChannel,
+ include: [
+ {
+ model: Video['sequelize'].models.Author,
+ where: {
+ name: author
+ }
+ }
+ ]
}
]
}
return Video.findById(id)
}
-loadByUUID = function (uuid: string) {
- const query = {
+loadByUUID = function (uuid: string, t?: Sequelize.Transaction) {
+ const query: Sequelize.FindOptions<VideoAttributes> = {
where: {
uuid
},
include: [ Video['sequelize'].models.VideoFile ]
}
+
+ if (t !== undefined) query.transaction = t
+
+ 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)
}
loadAndPopulateAuthor = function (id: number) {
const options = {
- include: [ Video['sequelize'].models.VideoFile, Video['sequelize'].models.Author ]
+ include: [
+ Video['sequelize'].models.VideoFile,
+ {
+ model: Video['sequelize'].models.VideoChannel,
+ include: [ Video['sequelize'].models.Author ]
+ }
+ ]
}
return Video.findById(id, options)
const options = {
include: [
{
- model: Video['sequelize'].models.Author,
- include: [ { model: Video['sequelize'].models.Pod, required: false } ]
+ model: Video['sequelize'].models.VideoChannel,
+ include: [
+ {
+ model: Video['sequelize'].models.Author,
+ include: [ { model: Video['sequelize'].models.Pod, required: false } ]
+ }
+ ]
},
Video['sequelize'].models.Tag,
Video['sequelize'].models.VideoFile
},
include: [
{
- model: Video['sequelize'].models.Author,
- include: [ { model: Video['sequelize'].models.Pod, required: false } ]
+ model: Video['sequelize'].models.VideoChannel,
+ include: [
+ {
+ model: Video['sequelize'].models.Author,
+ include: [ { model: Video['sequelize'].models.Pod, required: false } ]
+ }
+ ]
},
Video['sequelize'].models.Tag,
Video['sequelize'].models.VideoFile
const authorInclude: Sequelize.IncludeOptions = {
model: Video['sequelize'].models.Author,
- include: [
- podInclude
- ]
+ include: [ podInclude ]
+ }
+
+ const videoChannelInclude: Sequelize.IncludeOptions = {
+ model: Video['sequelize'].models.VideoChannel,
+ include: [ authorInclude ],
+ required: true
}
const tagInclude: Sequelize.IncludeOptions = {
$iLike: '%' + value + '%'
}
}
-
- // authorInclude.or = true
} else {
query.where[field] = {
$iLike: '%' + value + '%'
}
query.include = [
- authorInclude, tagInclude, videoFileInclude
+ videoChannelInclude, tagInclude, videoFileInclude
]
return Video.findAndCountAll(query).then(({ rows, count }) => {
baseUrlHttp = CONFIG.WEBSERVER.URL
baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
} else {
- baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + video.Author.Pod.host
- baseUrlWs = REMOTE_SCHEME.WS + '://' + video.Author.Pod.host
+ baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + video.VideoChannel.Author.Pod.host
+ baseUrlWs = REMOTE_SCHEME.WS + '://' + video.VideoChannel.Author.Pod.host
}
return { baseUrlHttp, baseUrlWs }