ActivityPub-federated video streaming platform using P2P directly in your web browser
Add this context to instance model functions
Chocobozzz70c065d64c33
diff --git a/server/models/pod/pod-interface.ts b/server/models/pod/pod-interface.tsindex 01ccda64cc..d88847c459 100644--- a/server/models/pod/pod-interface.ts+++ b/server/models/pod/pod-interface.ts@@ -4,7 +4,7 @@ import * as Sequelize from 'sequelize'import { Pod as FormatedPod } from '../../../shared/models/pod.model'export namespace PodMethods {- export type ToFormatedJSON = () => FormatedPod+ export type ToFormatedJSON = (this: PodInstance) => FormatedPodexport type CountAllCallback = (err: Error, total: number) => voidexport type CountAll = (callback) => voiddiff --git a/server/models/pod/pod.ts b/server/models/pod/pod.tsindex 4c6e630249..4fe7fda1c2 100644--- a/server/models/pod/pod.ts+++ b/server/models/pod/pod.ts@@ -96,12 +96,12 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da// ------------------------------ METHODS -------------------------------toFormatedJSON = function () {+toFormatedJSON = function (this: PodInstance) {const json = {id: this.id,host: this.host,email: this.email,- score: this.score,+ score: this.score as number,createdAt: this.createdAt}diff --git a/server/models/user/user-interface.ts b/server/models/user/user-interface.tsindex 1ba4bd800d..6726e8ab5f 100644--- a/server/models/user/user-interface.ts+++ b/server/models/user/user-interface.ts@@ -6,10 +6,10 @@ import { User as FormatedUser } from '../../../shared/models/user.model'export namespace UserMethods {export type IsPasswordMatchCallback = (err: Error, same: boolean) => void- export type IsPasswordMatch = (password: string, callback: IsPasswordMatchCallback) => void+ export type IsPasswordMatch = (this: UserInstance, password: string, callback: IsPasswordMatchCallback) => void- export type ToFormatedJSON = () => FormatedUser- export type IsAdmin = () => boolean+ export type ToFormatedJSON = (this: UserInstance) => FormatedUser+ export type IsAdmin = (this: UserInstance) => booleanexport type CountTotalCallback = (err: Error, total: number) => voidexport type CountTotal = (callback: CountTotalCallback) => voiddiff --git a/server/models/user/user.ts b/server/models/user/user.tsindex d78f5f8450..6b2410259c 100644--- a/server/models/user/user.ts+++ b/server/models/user/user.ts@@ -131,7 +131,7 @@ function beforeCreateOrUpdate (user: UserInstance) {// ------------------------------ METHODS -------------------------------isPasswordMatch = function (password: string, callback: UserMethods.IsPasswordMatchCallback) {+isPasswordMatch = function (this: UserInstance, password: string, callback: UserMethods.IsPasswordMatchCallback) {return comparePassword(password, this.password, callback)}@@ -146,7 +146,7 @@ toFormatedJSON = function (this: UserInstance) {}}-isAdmin = function () {+isAdmin = function (this: UserInstance) {return this.role === USER_ROLES.ADMIN}diff --git a/server/models/video/video-abuse-interface.ts b/server/models/video/video-abuse-interface.tsindex 4b7f2a2ec2..f3e32f79c5 100644--- a/server/models/video/video-abuse-interface.ts+++ b/server/models/video/video-abuse-interface.ts@@ -1,5 +1,7 @@import * as Sequelize from 'sequelize'+import { PodInstance } from '../pod'+// Don't use barrel, import just what we needimport { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/video-abuse.model'@@ -17,12 +19,15 @@ export interface VideoAbuseClass {export interface VideoAbuseAttributes {reporterUsername: stringreason: string+ videoId: string}export interface VideoAbuseInstance extends VideoAbuseClass, VideoAbuseAttributes, Sequelize.Instance<VideoAbuseAttributes> {id: numbercreatedAt: DateupdatedAt: Date++ Pod: PodInstance}export interface VideoAbuseModel extends VideoAbuseClass, Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> {}diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.tsindex e0e0bcfe6d..f5b4debe69 100644--- a/server/models/video/video-abuse.ts+++ b/server/models/video/video-abuse.ts@@ -66,7 +66,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da// ------------------------------ METHODS -------------------------------function toFormatedJSON () {+function toFormatedJSON (this: VideoAbuseInstance) {let reporterPodHostif (this.Pod) {diff --git a/server/models/video/video-blacklist-interface.ts b/server/models/video/video-blacklist-interface.tsindex 37f579422f..c34e7fb092 100644--- a/server/models/video/video-blacklist-interface.ts+++ b/server/models/video/video-blacklist-interface.ts@@ -4,7 +4,7 @@ import * as Sequelize from 'sequelize'import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../../shared/models/video-blacklist.model'export namespace BlacklistedVideoMethods {- export type ToFormatedJSON = () => FormatedBlacklistedVideo+ export type ToFormatedJSON = (this: BlacklistedVideoInstance) => FormatedBlacklistedVideoexport type CountTotalCallback = (err: Error, total: number) => voidexport type CountTotal = (callback: CountTotalCallback) => void@@ -32,6 +32,7 @@ export interface BlacklistedVideoClass {}export interface BlacklistedVideoAttributes {+ videoId: string}export interface BlacklistedVideoInstance extends BlacklistedVideoClass, BlacklistedVideoAttributes, Sequelize.Instance<BlacklistedVideoAttributes> {diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.tsindex f4479986cf..3576c96f6c 100644--- a/server/models/video/video-blacklist.ts+++ b/server/models/video/video-blacklist.ts@@ -49,7 +49,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da// ------------------------------ METHODS -------------------------------toFormatedJSON = function () {+toFormatedJSON = function (this: BlacklistedVideoInstance) {return {id: this.id,videoId: this.videoId,diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.tsindex 71b9b0a696..5fefc2bb16 100644--- a/server/models/video/video-interface.ts+++ b/server/models/video/video-interface.ts@@ -48,21 +48,21 @@ export type FormatedUpdateRemoteVideo = {}export namespace VideoMethods {- export type GenerateMagnetUri = () => string- export type GetVideoFilename = () => string- export type GetThumbnailName = () => string- export type GetPreviewName = () => string- export type GetTorrentName = () => string- export type IsOwned = () => boolean- export type ToFormatedJSON = () => FormatedVideo+ export type GenerateMagnetUri = (this: VideoInstance) => string+ export type GetVideoFilename = (this: VideoInstance) => string+ export type GetThumbnailName = (this: VideoInstance) => string+ export type GetPreviewName = (this: VideoInstance) => string+ export type GetTorrentName = (this: VideoInstance) => string+ export type IsOwned = (this: VideoInstance) => boolean+ export type ToFormatedJSON = (this: VideoInstance) => FormatedVideoexport type ToAddRemoteJSONCallback = (err: Error, videoFormated?: FormatedAddRemoteVideo) => void- export type ToAddRemoteJSON = (callback: ToAddRemoteJSONCallback) => void+ export type ToAddRemoteJSON = (this: VideoInstance, callback: ToAddRemoteJSONCallback) => void- export type ToUpdateRemoteJSON = () => FormatedUpdateRemoteVideo+ export type ToUpdateRemoteJSON = (this: VideoInstance) => FormatedUpdateRemoteVideoexport type TranscodeVideofileCallback = (err: Error) => void- export type TranscodeVideofile = (callback: TranscodeVideofileCallback) => void+ export type TranscodeVideofile = (this: VideoInstance, callback: TranscodeVideofileCallback) => voidexport type GenerateThumbnailFromDataCallback = (err: Error, thumbnailName?: string) => voidexport type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string, callback: GenerateThumbnailFromDataCallback) => voiddiff --git a/server/models/video/video.ts b/server/models/video/video.tsindex 866b380cc3..e66ebee2dd 100644--- a/server/models/video/video.ts+++ b/server/models/video/video.ts@@ -247,7 +247,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DaloadByHostAndRemoteId,loadAndPopulateAuthor,loadAndPopulateAuthorAndPodAndTags,- searchAndPopulateAuthorAndPodAndTags+ searchAndPopulateAuthorAndPodAndTags,+ removeFromBlacklist]const instanceMethods = [generateMagnetUri,@@ -260,7 +261,6 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DatoAddRemoteJSON,toUpdateRemoteJSON,transcodeVideofile,- removeFromBlacklist]addMethodsToModel(Video, classMethods, instanceMethods)@@ -389,7 +389,7 @@ function associate (models) {})}-generateMagnetUri = function () {+generateMagnetUri = function (this: VideoInstance) {let baseUrlHttplet baseUrlWs@@ -416,18 +416,18 @@ generateMagnetUri = function () {return magnetUtil.encode(magnetHash)}-getVideoFilename = function () {+getVideoFilename = function (this: VideoInstance) {if (this.isOwned()) return this.id + this.extnamereturn this.remoteId + this.extname}-getThumbnailName = function () {+getThumbnailName = function (this: VideoInstance) {// We always have a copy of the thumbnailreturn this.id + '.jpg'}-getPreviewName = function () {+getPreviewName = function (this: VideoInstance) {const extension = '.jpg'if (this.isOwned()) return this.id + extension@@ -435,7 +435,7 @@ getPreviewName = function () {return this.remoteId + extension}-getTorrentName = function () {+getTorrentName = function (this: VideoInstance) {const extension = '.torrent'if (this.isOwned()) return this.id + extension@@ -443,7 +443,7 @@ getTorrentName = function () {return this.remoteId + extension}-isOwned = function () {+isOwned = function (this: VideoInstance) {return this.remoteId === null}@@ -497,7 +497,7 @@ toFormatedJSON = function (this: VideoInstance) {return json}-toAddRemoteJSON = function (callback: VideoMethods.ToAddRemoteJSONCallback) {+toAddRemoteJSON = function (this: VideoInstance, callback: VideoMethods.ToAddRemoteJSONCallback) {// Get thumbnail data to send to the other podconst thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())fs.readFile(thumbnailPath, (err, thumbnailData) => {@@ -531,7 +531,7 @@ toAddRemoteJSON = function (callback: VideoMethods.ToAddRemoteJSONCallback) {})}-toUpdateRemoteJSON = function () {+toUpdateRemoteJSON = function (this: VideoInstance) {const json = {name: this.name,category: this.category,@@ -555,7 +555,7 @@ toUpdateRemoteJSON = function () {return json}-transcodeVideofile = function (finalCallback: VideoMethods.TranscodeVideofileCallback) {+transcodeVideofile = function (this: VideoInstance, finalCallback: VideoMethods.TranscodeVideofileCallback) {const video = thisconst videosDirectory = CONFIG.STORAGE.VIDEOS_DIRdiff --git a/shared/models/video-blacklist.model.ts b/shared/models/video-blacklist.model.tsindex 6086250ac3..f894bb0652 100644--- a/shared/models/video-blacklist.model.ts+++ b/shared/models/video-blacklist.model.ts@@ -1,5 +1,5 @@export interface BlacklistedVideo {id: number- videoId: number+ videoId: stringcreatedAt: Date}