diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-16 09:54:59 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-16 09:54:59 +0200 |
commit | 70c065d64c330196d371941d9294a55da6e3aa37 (patch) | |
tree | 4532a9611502135bedb1cc6009c706e31f1f9be4 /server/models/video | |
parent | 74889a71fe687dda74f2a687653122327807af36 (diff) | |
download | PeerTube-70c065d64c330196d371941d9294a55da6e3aa37.tar.gz PeerTube-70c065d64c330196d371941d9294a55da6e3aa37.tar.zst PeerTube-70c065d64c330196d371941d9294a55da6e3aa37.zip |
Add this context to instance model functions
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-abuse-interface.ts | 5 | ||||
-rw-r--r-- | server/models/video/video-abuse.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-blacklist-interface.ts | 3 | ||||
-rw-r--r-- | server/models/video/video-blacklist.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-interface.ts | 20 | ||||
-rw-r--r-- | server/models/video/video.ts | 22 |
6 files changed, 30 insertions, 24 deletions
diff --git a/server/models/video/video-abuse-interface.ts b/server/models/video/video-abuse-interface.ts index 4b7f2a2ec..f3e32f79c 100644 --- a/server/models/video/video-abuse-interface.ts +++ b/server/models/video/video-abuse-interface.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | 2 | ||
3 | import { PodInstance } from '../pod' | ||
4 | |||
3 | // Don't use barrel, import just what we need | 5 | // Don't use barrel, import just what we need |
4 | import { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/video-abuse.model' | 6 | import { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/video-abuse.model' |
5 | 7 | ||
@@ -17,12 +19,15 @@ export interface VideoAbuseClass { | |||
17 | export interface VideoAbuseAttributes { | 19 | export interface VideoAbuseAttributes { |
18 | reporterUsername: string | 20 | reporterUsername: string |
19 | reason: string | 21 | reason: string |
22 | videoId: string | ||
20 | } | 23 | } |
21 | 24 | ||
22 | export interface VideoAbuseInstance extends VideoAbuseClass, VideoAbuseAttributes, Sequelize.Instance<VideoAbuseAttributes> { | 25 | export interface VideoAbuseInstance extends VideoAbuseClass, VideoAbuseAttributes, Sequelize.Instance<VideoAbuseAttributes> { |
23 | id: number | 26 | id: number |
24 | createdAt: Date | 27 | createdAt: Date |
25 | updatedAt: Date | 28 | updatedAt: Date |
29 | |||
30 | Pod: PodInstance | ||
26 | } | 31 | } |
27 | 32 | ||
28 | export interface VideoAbuseModel extends VideoAbuseClass, Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> {} | 33 | export interface VideoAbuseModel extends VideoAbuseClass, Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> {} |
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index e0e0bcfe6..f5b4debe6 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 | |||
66 | 66 | ||
67 | // ------------------------------ METHODS ------------------------------ | 67 | // ------------------------------ METHODS ------------------------------ |
68 | 68 | ||
69 | function toFormatedJSON () { | 69 | function toFormatedJSON (this: VideoAbuseInstance) { |
70 | let reporterPodHost | 70 | let reporterPodHost |
71 | 71 | ||
72 | if (this.Pod) { | 72 | if (this.Pod) { |
diff --git a/server/models/video/video-blacklist-interface.ts b/server/models/video/video-blacklist-interface.ts index 37f579422..c34e7fb09 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' | |||
4 | import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../../shared/models/video-blacklist.model' | 4 | import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../../shared/models/video-blacklist.model' |
5 | 5 | ||
6 | export namespace BlacklistedVideoMethods { | 6 | export namespace BlacklistedVideoMethods { |
7 | export type ToFormatedJSON = () => FormatedBlacklistedVideo | 7 | export type ToFormatedJSON = (this: BlacklistedVideoInstance) => FormatedBlacklistedVideo |
8 | 8 | ||
9 | export type CountTotalCallback = (err: Error, total: number) => void | 9 | export type CountTotalCallback = (err: Error, total: number) => void |
10 | export type CountTotal = (callback: CountTotalCallback) => void | 10 | export type CountTotal = (callback: CountTotalCallback) => void |
@@ -32,6 +32,7 @@ export interface BlacklistedVideoClass { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | export interface BlacklistedVideoAttributes { | 34 | export interface BlacklistedVideoAttributes { |
35 | videoId: string | ||
35 | } | 36 | } |
36 | 37 | ||
37 | export interface BlacklistedVideoInstance extends BlacklistedVideoClass, BlacklistedVideoAttributes, Sequelize.Instance<BlacklistedVideoAttributes> { | 38 | export interface BlacklistedVideoInstance extends BlacklistedVideoClass, BlacklistedVideoAttributes, Sequelize.Instance<BlacklistedVideoAttributes> { |
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index f4479986c..3576c96f6 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 | |||
49 | 49 | ||
50 | // ------------------------------ METHODS ------------------------------ | 50 | // ------------------------------ METHODS ------------------------------ |
51 | 51 | ||
52 | toFormatedJSON = function () { | 52 | toFormatedJSON = function (this: BlacklistedVideoInstance) { |
53 | return { | 53 | return { |
54 | id: this.id, | 54 | id: this.id, |
55 | videoId: this.videoId, | 55 | videoId: this.videoId, |
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts index 71b9b0a69..5fefc2bb1 100644 --- a/server/models/video/video-interface.ts +++ b/server/models/video/video-interface.ts | |||
@@ -48,21 +48,21 @@ export type FormatedUpdateRemoteVideo = { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | export namespace VideoMethods { | 50 | export namespace VideoMethods { |
51 | export type GenerateMagnetUri = () => string | 51 | export type GenerateMagnetUri = (this: VideoInstance) => string |
52 | export type GetVideoFilename = () => string | 52 | export type GetVideoFilename = (this: VideoInstance) => string |
53 | export type GetThumbnailName = () => string | 53 | export type GetThumbnailName = (this: VideoInstance) => string |
54 | export type GetPreviewName = () => string | 54 | export type GetPreviewName = (this: VideoInstance) => string |
55 | export type GetTorrentName = () => string | 55 | export type GetTorrentName = (this: VideoInstance) => string |
56 | export type IsOwned = () => boolean | 56 | export type IsOwned = (this: VideoInstance) => boolean |
57 | export type ToFormatedJSON = () => FormatedVideo | 57 | export type ToFormatedJSON = (this: VideoInstance) => FormatedVideo |
58 | 58 | ||
59 | export type ToAddRemoteJSONCallback = (err: Error, videoFormated?: FormatedAddRemoteVideo) => void | 59 | export type ToAddRemoteJSONCallback = (err: Error, videoFormated?: FormatedAddRemoteVideo) => void |
60 | export type ToAddRemoteJSON = (callback: ToAddRemoteJSONCallback) => void | 60 | export type ToAddRemoteJSON = (this: VideoInstance, callback: ToAddRemoteJSONCallback) => void |
61 | 61 | ||
62 | export type ToUpdateRemoteJSON = () => FormatedUpdateRemoteVideo | 62 | export type ToUpdateRemoteJSON = (this: VideoInstance) => FormatedUpdateRemoteVideo |
63 | 63 | ||
64 | export type TranscodeVideofileCallback = (err: Error) => void | 64 | export type TranscodeVideofileCallback = (err: Error) => void |
65 | export type TranscodeVideofile = (callback: TranscodeVideofileCallback) => void | 65 | export type TranscodeVideofile = (this: VideoInstance, callback: TranscodeVideofileCallback) => void |
66 | 66 | ||
67 | export type GenerateThumbnailFromDataCallback = (err: Error, thumbnailName?: string) => void | 67 | export type GenerateThumbnailFromDataCallback = (err: Error, thumbnailName?: string) => void |
68 | export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string, callback: GenerateThumbnailFromDataCallback) => void | 68 | export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string, callback: GenerateThumbnailFromDataCallback) => void |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 866b380cc..e66ebee2d 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.Da | |||
247 | loadByHostAndRemoteId, | 247 | loadByHostAndRemoteId, |
248 | loadAndPopulateAuthor, | 248 | loadAndPopulateAuthor, |
249 | loadAndPopulateAuthorAndPodAndTags, | 249 | loadAndPopulateAuthorAndPodAndTags, |
250 | searchAndPopulateAuthorAndPodAndTags | 250 | searchAndPopulateAuthorAndPodAndTags, |
251 | removeFromBlacklist | ||
251 | ] | 252 | ] |
252 | const instanceMethods = [ | 253 | const instanceMethods = [ |
253 | generateMagnetUri, | 254 | generateMagnetUri, |
@@ -260,7 +261,6 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
260 | toAddRemoteJSON, | 261 | toAddRemoteJSON, |
261 | toUpdateRemoteJSON, | 262 | toUpdateRemoteJSON, |
262 | transcodeVideofile, | 263 | transcodeVideofile, |
263 | removeFromBlacklist | ||
264 | ] | 264 | ] |
265 | addMethodsToModel(Video, classMethods, instanceMethods) | 265 | addMethodsToModel(Video, classMethods, instanceMethods) |
266 | 266 | ||
@@ -389,7 +389,7 @@ function associate (models) { | |||
389 | }) | 389 | }) |
390 | } | 390 | } |
391 | 391 | ||
392 | generateMagnetUri = function () { | 392 | generateMagnetUri = function (this: VideoInstance) { |
393 | let baseUrlHttp | 393 | let baseUrlHttp |
394 | let baseUrlWs | 394 | let baseUrlWs |
395 | 395 | ||
@@ -416,18 +416,18 @@ generateMagnetUri = function () { | |||
416 | return magnetUtil.encode(magnetHash) | 416 | return magnetUtil.encode(magnetHash) |
417 | } | 417 | } |
418 | 418 | ||
419 | getVideoFilename = function () { | 419 | getVideoFilename = function (this: VideoInstance) { |
420 | if (this.isOwned()) return this.id + this.extname | 420 | if (this.isOwned()) return this.id + this.extname |
421 | 421 | ||
422 | return this.remoteId + this.extname | 422 | return this.remoteId + this.extname |
423 | } | 423 | } |
424 | 424 | ||
425 | getThumbnailName = function () { | 425 | getThumbnailName = function (this: VideoInstance) { |
426 | // We always have a copy of the thumbnail | 426 | // We always have a copy of the thumbnail |
427 | return this.id + '.jpg' | 427 | return this.id + '.jpg' |
428 | } | 428 | } |
429 | 429 | ||
430 | getPreviewName = function () { | 430 | getPreviewName = function (this: VideoInstance) { |
431 | const extension = '.jpg' | 431 | const extension = '.jpg' |
432 | 432 | ||
433 | if (this.isOwned()) return this.id + extension | 433 | if (this.isOwned()) return this.id + extension |
@@ -435,7 +435,7 @@ getPreviewName = function () { | |||
435 | return this.remoteId + extension | 435 | return this.remoteId + extension |
436 | } | 436 | } |
437 | 437 | ||
438 | getTorrentName = function () { | 438 | getTorrentName = function (this: VideoInstance) { |
439 | const extension = '.torrent' | 439 | const extension = '.torrent' |
440 | 440 | ||
441 | if (this.isOwned()) return this.id + extension | 441 | if (this.isOwned()) return this.id + extension |
@@ -443,7 +443,7 @@ getTorrentName = function () { | |||
443 | return this.remoteId + extension | 443 | return this.remoteId + extension |
444 | } | 444 | } |
445 | 445 | ||
446 | isOwned = function () { | 446 | isOwned = function (this: VideoInstance) { |
447 | return this.remoteId === null | 447 | return this.remoteId === null |
448 | } | 448 | } |
449 | 449 | ||
@@ -497,7 +497,7 @@ toFormatedJSON = function (this: VideoInstance) { | |||
497 | return json | 497 | return json |
498 | } | 498 | } |
499 | 499 | ||
500 | toAddRemoteJSON = function (callback: VideoMethods.ToAddRemoteJSONCallback) { | 500 | toAddRemoteJSON = function (this: VideoInstance, callback: VideoMethods.ToAddRemoteJSONCallback) { |
501 | // Get thumbnail data to send to the other pod | 501 | // Get thumbnail data to send to the other pod |
502 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) | 502 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) |
503 | fs.readFile(thumbnailPath, (err, thumbnailData) => { | 503 | fs.readFile(thumbnailPath, (err, thumbnailData) => { |
@@ -531,7 +531,7 @@ toAddRemoteJSON = function (callback: VideoMethods.ToAddRemoteJSONCallback) { | |||
531 | }) | 531 | }) |
532 | } | 532 | } |
533 | 533 | ||
534 | toUpdateRemoteJSON = function () { | 534 | toUpdateRemoteJSON = function (this: VideoInstance) { |
535 | const json = { | 535 | const json = { |
536 | name: this.name, | 536 | name: this.name, |
537 | category: this.category, | 537 | category: this.category, |
@@ -555,7 +555,7 @@ toUpdateRemoteJSON = function () { | |||
555 | return json | 555 | return json |
556 | } | 556 | } |
557 | 557 | ||
558 | transcodeVideofile = function (finalCallback: VideoMethods.TranscodeVideofileCallback) { | 558 | transcodeVideofile = function (this: VideoInstance, finalCallback: VideoMethods.TranscodeVideofileCallback) { |
559 | const video = this | 559 | const video = this |
560 | 560 | ||
561 | const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR | 561 | const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR |