let getDurationFromFile: VideoMethods.GetDurationFromFile
let list: VideoMethods.List
let listForApi: VideoMethods.ListForApi
-let loadByHostAndRemoteId: VideoMethods.LoadByHostAndRemoteId
+let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
let listOwnedAndPopulateAuthorAndTags: VideoMethods.ListOwnedAndPopulateAuthorAndTags
let listOwnedByAuthor: VideoMethods.ListOwnedByAuthor
let load: VideoMethods.Load
+let loadByUUID: VideoMethods.LoadByUUID
let loadAndPopulateAuthor: VideoMethods.LoadAndPopulateAuthor
let loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
+let loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
let searchAndPopulateAuthorAndPodAndTags: VideoMethods.SearchAndPopulateAuthorAndPodAndTags
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
Video = sequelize.define<VideoInstance, VideoAttributes>('Video',
{
- id: {
+ uuid: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
- primaryKey: true,
+ allowNull: false,
validate: {
isUUID: 4
}
type: DataTypes.ENUM(values(CONSTRAINTS_FIELDS.VIDEOS.EXTNAME)),
allowNull: false
},
- remoteId: {
- type: DataTypes.UUID,
- allowNull: true,
- validate: {
- isUUID: 4
- }
- },
category: {
type: DataTypes.INTEGER,
allowNull: false,
min: 0,
isInt: true
}
+ },
+ remote: {
+ type: DataTypes.BOOLEAN,
+ allowNull: false,
+ defaultValue: false
}
},
{
{
fields: [ 'authorId' ]
},
- {
- fields: [ 'remoteId' ]
- },
{
fields: [ 'name' ]
},
},
{
fields: [ 'likes' ]
+ },
+ {
+ fields: [ 'uuid' ]
}
],
hooks: {
listOwnedAndPopulateAuthorAndTags,
listOwnedByAuthor,
load,
- loadByHostAndRemoteId,
+ loadByUUID,
+ loadByHostAndUUID,
loadAndPopulateAuthor,
loadAndPopulateAuthorAndPodAndTags,
+ loadByUUIDAndPopulateAuthorAndPodAndTags,
searchAndPopulateAuthorAndPodAndTags,
removeFromBlacklist
]
)
if (CONFIG.TRANSCODING.ENABLED === true) {
+ // Put uuid because we don't have id auto incremented for now
const dataInput = {
- id: video.id
+ videoUUID: video.uuid
}
tasks.push(
if (video.isOwned()) {
const removeVideoToFriendsParams = {
- remoteId: video.id
+ uuid: video.uuid
}
tasks.push(
}
getVideoFilename = function (this: VideoInstance) {
- if (this.isOwned()) return this.id + this.extname
-
- return this.remoteId + this.extname
+ return this.uuid + this.extname
}
getThumbnailName = function (this: VideoInstance) {
// We always have a copy of the thumbnail
- return this.id + '.jpg'
+ const extension = '.jpg'
+ return this.uuid + extension
}
getPreviewName = function (this: VideoInstance) {
const extension = '.jpg'
-
- if (this.isOwned()) return this.id + extension
-
- return this.remoteId + extension
+ return this.uuid + extension
}
getTorrentName = function (this: VideoInstance) {
const extension = '.torrent'
-
- if (this.isOwned()) return this.id + extension
-
- return this.remoteId + extension
+ return this.uuid + extension
}
isOwned = function (this: VideoInstance) {
- return this.remoteId === null
+ return this.remote === false
}
toFormatedJSON = function (this: VideoInstance) {
const json = {
id: this.id,
+ uuid: this.uuid,
name: this.name,
category: this.category,
categoryLabel,
return readFileBufferPromise(thumbnailPath).then(thumbnailData => {
const remoteVideo = {
+ uuid: this.uuid,
name: this.name,
category: this.category,
licence: this.licence,
nsfw: this.nsfw,
description: this.description,
infoHash: this.infoHash,
- remoteId: this.id,
author: this.Author.name,
duration: this.duration,
thumbnailData: thumbnailData.toString('binary'),
toUpdateRemoteJSON = function (this: VideoInstance) {
const json = {
+ uuid: this.uuid,
name: this.name,
category: this.category,
licence: this.licence,
nsfw: this.nsfw,
description: this.description,
infoHash: this.infoHash,
- remoteId: this.id,
author: this.Author.name,
duration: this.duration,
tags: map<TagInstance, string>(this.Tags, 'name'),
})
}
-loadByHostAndRemoteId = function (fromHost: string, remoteId: string) {
+loadByHostAndUUID = function (fromHost: string, uuid: string) {
const query = {
where: {
- remoteId: remoteId
+ uuid
},
include: [
{
}
listOwnedAndPopulateAuthorAndTags = function () {
- // If remoteId is null this is *our* video
const query = {
where: {
- remoteId: null
+ remote: false
},
include: [ Video['sequelize'].models.Author, Video['sequelize'].models.Tag ]
}
listOwnedByAuthor = function (author: string) {
const query = {
where: {
- remoteId: null
+ remote: false
},
include: [
{
return Video.findAll(query)
}
-load = function (id: string) {
+load = function (id: number) {
return Video.findById(id)
}
-loadAndPopulateAuthor = function (id: string) {
+loadByUUID = function (uuid: string) {
+ const query = {
+ where: {
+ uuid
+ }
+ }
+ return Video.findOne(query)
+}
+
+loadAndPopulateAuthor = function (id: number) {
const options = {
include: [ Video['sequelize'].models.Author ]
}
return Video.findById(id, options)
}
-loadAndPopulateAuthorAndPodAndTags = function (id: string) {
+loadAndPopulateAuthorAndPodAndTags = function (id: number) {
const options = {
include: [
{
return Video.findById(id, options)
}
+loadByUUIDAndPopulateAuthorAndPodAndTags = function (uuid: string) {
+ const options = {
+ where: {
+ uuid
+ },
+ include: [
+ {
+ model: Video['sequelize'].models.Author,
+ include: [ { model: Video['sequelize'].models.Pod, required: false } ]
+ },
+ Video['sequelize'].models.Tag
+ ]
+ }
+
+ return Video.findOne(options)
+}
+
searchAndPopulateAuthorAndPodAndTags = function (value: string, field: string, start: number, count: number, sort: string) {
const podInclude: Sequelize.IncludeOptions = {
model: Video['sequelize'].models.Pod,