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/schedule-video-update.ts | |
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/schedule-video-update.ts')
-rw-r--r-- | server/models/video/schedule-video-update.ts | 71 |
1 files changed, 71 insertions, 0 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 | } | ||