diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-14 18:06:56 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-14 18:06:56 +0200 |
commit | 2baea0c77cc765f7cbca9c9a2f4272268892a35c (patch) | |
tree | 47b1be5535439409a97eb80c0222c9c821b83dae /server/models/video | |
parent | bf079b7bfd7f0fb75ceb28e333bb4b74d8840dd4 (diff) | |
download | PeerTube-2baea0c77cc765f7cbca9c9a2f4272268892a35c.tar.gz PeerTube-2baea0c77cc765f7cbca9c9a2f4272268892a35c.tar.zst PeerTube-2baea0c77cc765f7cbca9c9a2f4272268892a35c.zip |
Add ability for uploaders to schedule video update
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/schedule-video-update.ts | 71 | ||||
-rw-r--r-- | server/models/video/video.ts | 37 |
2 files changed, 103 insertions, 5 deletions
diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts new file mode 100644 index 000000000..d4e37beb5 --- /dev/null +++ b/server/models/video/schedule-video-update.ts | |||
@@ -0,0 +1,71 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Sequelize, Table, UpdatedAt } from 'sequelize-typescript' | ||
2 | import { ScopeNames as VideoScopeNames, VideoModel } from './video' | ||
3 | import { VideoPrivacy } from '../../../shared/models/videos' | ||
4 | import { Transaction } from 'sequelize' | ||
5 | |||
6 | @Table({ | ||
7 | tableName: 'scheduleVideoUpdate', | ||
8 | indexes: [ | ||
9 | { | ||
10 | fields: [ 'videoId' ], | ||
11 | unique: true | ||
12 | }, | ||
13 | { | ||
14 | fields: [ 'updateAt' ] | ||
15 | } | ||
16 | ] | ||
17 | }) | ||
18 | export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> { | ||
19 | |||
20 | @AllowNull(false) | ||
21 | @Default(null) | ||
22 | @Column | ||
23 | updateAt: Date | ||
24 | |||
25 | @AllowNull(true) | ||
26 | @Default(null) | ||
27 | @Column | ||
28 | privacy: VideoPrivacy | ||
29 | |||
30 | @CreatedAt | ||
31 | createdAt: Date | ||
32 | |||
33 | @UpdatedAt | ||
34 | updatedAt: Date | ||
35 | |||
36 | @ForeignKey(() => VideoModel) | ||
37 | @Column | ||
38 | videoId: number | ||
39 | |||
40 | @BelongsTo(() => VideoModel, { | ||
41 | foreignKey: { | ||
42 | allowNull: false | ||
43 | }, | ||
44 | onDelete: 'cascade' | ||
45 | }) | ||
46 | Video: VideoModel | ||
47 | |||
48 | static listVideosToUpdate (t: Transaction) { | ||
49 | const query = { | ||
50 | where: { | ||
51 | updateAt: { | ||
52 | [Sequelize.Op.lte]: new Date() | ||
53 | } | ||
54 | }, | ||
55 | include: [ | ||
56 | { | ||
57 | model: VideoModel.scope( | ||
58 | [ | ||
59 | VideoScopeNames.WITH_FILES, | ||
60 | VideoScopeNames.WITH_ACCOUNT_DETAILS | ||
61 | ] | ||
62 | ) | ||
63 | } | ||
64 | ], | ||
65 | transaction: t | ||
66 | } | ||
67 | |||
68 | return ScheduleVideoUpdateModel.findAll(query) | ||
69 | } | ||
70 | |||
71 | } | ||
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 59c378efa..440f4d171 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -15,6 +15,7 @@ import { | |||
15 | Default, | 15 | Default, |
16 | ForeignKey, | 16 | ForeignKey, |
17 | HasMany, | 17 | HasMany, |
18 | HasOne, | ||
18 | IFindOptions, | 19 | IFindOptions, |
19 | Is, | 20 | Is, |
20 | IsInt, | 21 | IsInt, |
@@ -47,7 +48,8 @@ import { | |||
47 | isVideoLanguageValid, | 48 | isVideoLanguageValid, |
48 | isVideoLicenceValid, | 49 | isVideoLicenceValid, |
49 | isVideoNameValid, | 50 | isVideoNameValid, |
50 | isVideoPrivacyValid, isVideoStateValid, | 51 | isVideoPrivacyValid, |
52 | isVideoStateValid, | ||
51 | isVideoSupportValid | 53 | isVideoSupportValid |
52 | } from '../../helpers/custom-validators/videos' | 54 | } from '../../helpers/custom-validators/videos' |
53 | import { generateImageFromVideoFile, getVideoFileResolution, transcode } from '../../helpers/ffmpeg-utils' | 55 | import { generateImageFromVideoFile, getVideoFileResolution, transcode } from '../../helpers/ffmpeg-utils' |
@@ -66,7 +68,8 @@ import { | |||
66 | VIDEO_EXT_MIMETYPE, | 68 | VIDEO_EXT_MIMETYPE, |
67 | VIDEO_LANGUAGES, | 69 | VIDEO_LANGUAGES, |
68 | VIDEO_LICENCES, | 70 | VIDEO_LICENCES, |
69 | VIDEO_PRIVACIES, VIDEO_STATES | 71 | VIDEO_PRIVACIES, |
72 | VIDEO_STATES | ||
70 | } from '../../initializers' | 73 | } from '../../initializers' |
71 | import { | 74 | import { |
72 | getVideoCommentsActivityPubUrl, | 75 | getVideoCommentsActivityPubUrl, |
@@ -88,8 +91,9 @@ import { VideoCommentModel } from './video-comment' | |||
88 | import { VideoFileModel } from './video-file' | 91 | import { VideoFileModel } from './video-file' |
89 | import { VideoShareModel } from './video-share' | 92 | import { VideoShareModel } from './video-share' |
90 | import { VideoTagModel } from './video-tag' | 93 | import { VideoTagModel } from './video-tag' |
94 | import { ScheduleVideoUpdateModel } from './schedule-video-update' | ||
91 | 95 | ||
92 | enum ScopeNames { | 96 | export enum ScopeNames { |
93 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', | 97 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', |
94 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', | 98 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', |
95 | WITH_TAGS = 'WITH_TAGS', | 99 | WITH_TAGS = 'WITH_TAGS', |
@@ -495,6 +499,15 @@ export class VideoModel extends Model<VideoModel> { | |||
495 | }) | 499 | }) |
496 | VideoComments: VideoCommentModel[] | 500 | VideoComments: VideoCommentModel[] |
497 | 501 | ||
502 | @HasOne(() => ScheduleVideoUpdateModel, { | ||
503 | foreignKey: { | ||
504 | name: 'videoId', | ||
505 | allowNull: false | ||
506 | }, | ||
507 | onDelete: 'cascade' | ||
508 | }) | ||
509 | ScheduleVideoUpdate: ScheduleVideoUpdateModel | ||
510 | |||
498 | @BeforeDestroy | 511 | @BeforeDestroy |
499 | static async sendDelete (instance: VideoModel, options) { | 512 | static async sendDelete (instance: VideoModel, options) { |
500 | if (instance.isOwned()) { | 513 | if (instance.isOwned()) { |
@@ -673,6 +686,10 @@ export class VideoModel extends Model<VideoModel> { | |||
673 | required: true | 686 | required: true |
674 | } | 687 | } |
675 | ] | 688 | ] |
689 | }, | ||
690 | { | ||
691 | model: ScheduleVideoUpdateModel, | ||
692 | required: false | ||
676 | } | 693 | } |
677 | ] | 694 | ] |
678 | } | 695 | } |
@@ -1006,7 +1023,8 @@ export class VideoModel extends Model<VideoModel> { | |||
1006 | toFormattedJSON (options?: { | 1023 | toFormattedJSON (options?: { |
1007 | additionalAttributes: { | 1024 | additionalAttributes: { |
1008 | state: boolean, | 1025 | state: boolean, |
1009 | waitTranscoding: boolean | 1026 | waitTranscoding: boolean, |
1027 | scheduledUpdate: boolean | ||
1010 | } | 1028 | } |
1011 | }): Video { | 1029 | }): Video { |
1012 | const formattedAccount = this.VideoChannel.Account.toFormattedJSON() | 1030 | const formattedAccount = this.VideoChannel.Account.toFormattedJSON() |
@@ -1073,7 +1091,16 @@ export class VideoModel extends Model<VideoModel> { | |||
1073 | } | 1091 | } |
1074 | } | 1092 | } |
1075 | 1093 | ||
1076 | if (options.additionalAttributes.waitTranscoding) videoObject.waitTranscoding = this.waitTranscoding | 1094 | if (options.additionalAttributes.waitTranscoding) { |
1095 | videoObject.waitTranscoding = this.waitTranscoding | ||
1096 | } | ||
1097 | |||
1098 | if (options.additionalAttributes.scheduledUpdate && this.ScheduleVideoUpdate) { | ||
1099 | videoObject.scheduledUpdate = { | ||
1100 | updateAt: this.ScheduleVideoUpdate.updateAt, | ||
1101 | privacy: this.ScheduleVideoUpdate.privacy || undefined | ||
1102 | } | ||
1103 | } | ||
1077 | } | 1104 | } |
1078 | 1105 | ||
1079 | return videoObject | 1106 | return videoObject |