diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-15 16:52:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-15 18:20:56 +0200 |
commit | bbe0f0645ca958d33a3f409b15166609733b663f (patch) | |
tree | edcd5d702c73cda74a2177c4bdc08c616334337d /server/models | |
parent | 2baea0c77cc765f7cbca9c9a2f4272268892a35c (diff) | |
download | PeerTube-bbe0f0645ca958d33a3f409b15166609733b663f.tar.gz PeerTube-bbe0f0645ca958d33a3f409b15166609733b663f.tar.zst PeerTube-bbe0f0645ca958d33a3f409b15166609733b663f.zip |
Add ability to schedule video publication
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/schedule-video-update.ts | 23 | ||||
-rw-r--r-- | server/models/video/video.ts | 33 |
2 files changed, 45 insertions, 11 deletions
diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts index d4e37beb5..3cf5f6c99 100644 --- a/server/models/video/schedule-video-update.ts +++ b/server/models/video/schedule-video-update.ts | |||
@@ -25,7 +25,7 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> { | |||
25 | @AllowNull(true) | 25 | @AllowNull(true) |
26 | @Default(null) | 26 | @Default(null) |
27 | @Column | 27 | @Column |
28 | privacy: VideoPrivacy | 28 | privacy: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED |
29 | 29 | ||
30 | @CreatedAt | 30 | @CreatedAt |
31 | createdAt: Date | 31 | createdAt: Date |
@@ -45,6 +45,21 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> { | |||
45 | }) | 45 | }) |
46 | Video: VideoModel | 46 | Video: VideoModel |
47 | 47 | ||
48 | static areVideosToUpdate () { | ||
49 | const query = { | ||
50 | logging: false, | ||
51 | attributes: [ 'id' ], | ||
52 | where: { | ||
53 | updateAt: { | ||
54 | [Sequelize.Op.lte]: new Date() | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | |||
59 | return ScheduleVideoUpdateModel.findOne(query) | ||
60 | .then(res => !!res) | ||
61 | } | ||
62 | |||
48 | static listVideosToUpdate (t: Transaction) { | 63 | static listVideosToUpdate (t: Transaction) { |
49 | const query = { | 64 | const query = { |
50 | where: { | 65 | where: { |
@@ -68,4 +83,10 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> { | |||
68 | return ScheduleVideoUpdateModel.findAll(query) | 83 | return ScheduleVideoUpdateModel.findAll(query) |
69 | } | 84 | } |
70 | 85 | ||
86 | toFormattedJSON () { | ||
87 | return { | ||
88 | updateAt: this.updateAt, | ||
89 | privacy: this.privacy || undefined | ||
90 | } | ||
91 | } | ||
71 | } | 92 | } |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 440f4d171..0041e4d38 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -97,7 +97,8 @@ export enum ScopeNames { | |||
97 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', | 97 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', |
98 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', | 98 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', |
99 | WITH_TAGS = 'WITH_TAGS', | 99 | WITH_TAGS = 'WITH_TAGS', |
100 | WITH_FILES = 'WITH_FILES' | 100 | WITH_FILES = 'WITH_FILES', |
101 | WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE' | ||
101 | } | 102 | } |
102 | 103 | ||
103 | @Scopes({ | 104 | @Scopes({ |
@@ -286,6 +287,14 @@ export enum ScopeNames { | |||
286 | required: true | 287 | required: true |
287 | } | 288 | } |
288 | ] | 289 | ] |
290 | }, | ||
291 | [ScopeNames.WITH_SCHEDULED_UPDATE]: { | ||
292 | include: [ | ||
293 | { | ||
294 | model: () => ScheduleVideoUpdateModel.unscoped(), | ||
295 | required: false | ||
296 | } | ||
297 | ] | ||
289 | } | 298 | } |
290 | }) | 299 | }) |
291 | @Table({ | 300 | @Table({ |
@@ -843,7 +852,7 @@ export class VideoModel extends Model<VideoModel> { | |||
843 | } | 852 | } |
844 | 853 | ||
845 | return VideoModel | 854 | return VideoModel |
846 | .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS ]) | 855 | .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_SCHEDULED_UPDATE ]) |
847 | .findById(id, options) | 856 | .findById(id, options) |
848 | } | 857 | } |
849 | 858 | ||
@@ -869,7 +878,7 @@ export class VideoModel extends Model<VideoModel> { | |||
869 | } | 878 | } |
870 | 879 | ||
871 | return VideoModel | 880 | return VideoModel |
872 | .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS ]) | 881 | .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_SCHEDULED_UPDATE ]) |
873 | .findOne(options) | 882 | .findOne(options) |
874 | } | 883 | } |
875 | 884 | ||
@@ -1022,9 +1031,9 @@ export class VideoModel extends Model<VideoModel> { | |||
1022 | 1031 | ||
1023 | toFormattedJSON (options?: { | 1032 | toFormattedJSON (options?: { |
1024 | additionalAttributes: { | 1033 | additionalAttributes: { |
1025 | state: boolean, | 1034 | state?: boolean, |
1026 | waitTranscoding: boolean, | 1035 | waitTranscoding?: boolean, |
1027 | scheduledUpdate: boolean | 1036 | scheduledUpdate?: boolean |
1028 | } | 1037 | } |
1029 | }): Video { | 1038 | }): Video { |
1030 | const formattedAccount = this.VideoChannel.Account.toFormattedJSON() | 1039 | const formattedAccount = this.VideoChannel.Account.toFormattedJSON() |
@@ -1084,18 +1093,18 @@ export class VideoModel extends Model<VideoModel> { | |||
1084 | } | 1093 | } |
1085 | 1094 | ||
1086 | if (options) { | 1095 | if (options) { |
1087 | if (options.additionalAttributes.state) { | 1096 | if (options.additionalAttributes.state === true) { |
1088 | videoObject.state = { | 1097 | videoObject.state = { |
1089 | id: this.state, | 1098 | id: this.state, |
1090 | label: VideoModel.getStateLabel(this.state) | 1099 | label: VideoModel.getStateLabel(this.state) |
1091 | } | 1100 | } |
1092 | } | 1101 | } |
1093 | 1102 | ||
1094 | if (options.additionalAttributes.waitTranscoding) { | 1103 | if (options.additionalAttributes.waitTranscoding === true) { |
1095 | videoObject.waitTranscoding = this.waitTranscoding | 1104 | videoObject.waitTranscoding = this.waitTranscoding |
1096 | } | 1105 | } |
1097 | 1106 | ||
1098 | if (options.additionalAttributes.scheduledUpdate && this.ScheduleVideoUpdate) { | 1107 | if (options.additionalAttributes.scheduledUpdate === true && this.ScheduleVideoUpdate) { |
1099 | videoObject.scheduledUpdate = { | 1108 | videoObject.scheduledUpdate = { |
1100 | updateAt: this.ScheduleVideoUpdate.updateAt, | 1109 | updateAt: this.ScheduleVideoUpdate.updateAt, |
1101 | privacy: this.ScheduleVideoUpdate.privacy || undefined | 1110 | privacy: this.ScheduleVideoUpdate.privacy || undefined |
@@ -1107,7 +1116,11 @@ export class VideoModel extends Model<VideoModel> { | |||
1107 | } | 1116 | } |
1108 | 1117 | ||
1109 | toFormattedDetailsJSON (): VideoDetails { | 1118 | toFormattedDetailsJSON (): VideoDetails { |
1110 | const formattedJson = this.toFormattedJSON() | 1119 | const formattedJson = this.toFormattedJSON({ |
1120 | additionalAttributes: { | ||
1121 | scheduledUpdate: true | ||
1122 | } | ||
1123 | }) | ||
1111 | 1124 | ||
1112 | const detailsJson = { | 1125 | const detailsJson = { |
1113 | support: this.support, | 1126 | support: this.support, |