X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fschedule-video-update.ts;h=b9e9ed9a08692ce87161ea2cb103b3853fafeb06;hb=b876eaf11a1ed9683664d94767ca684ba5b77753;hp=d4e37beb5ce245eaccb95e7a3923baa9257b8a6f;hpb=2baea0c77cc765f7cbca9c9a2f4272268892a35c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts index d4e37beb5..b9e9ed9a0 100644 --- a/server/models/video/schedule-video-update.ts +++ b/server/models/video/schedule-video-update.ts @@ -1,7 +1,7 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Sequelize, Table, UpdatedAt } from 'sequelize-typescript' +import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' import { ScopeNames as VideoScopeNames, VideoModel } from './video' import { VideoPrivacy } from '../../../shared/models/videos' -import { Transaction } from 'sequelize' +import { Op, Transaction } from 'sequelize' @Table({ tableName: 'scheduleVideoUpdate', @@ -25,7 +25,7 @@ export class ScheduleVideoUpdateModel extends Model { @AllowNull(true) @Default(null) @Column - privacy: VideoPrivacy + privacy: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED @CreatedAt createdAt: Date @@ -45,11 +45,26 @@ export class ScheduleVideoUpdateModel extends Model { }) Video: VideoModel + static areVideosToUpdate () { + const query = { + logging: false, + attributes: [ 'id' ], + where: { + updateAt: { + [Op.lte]: new Date() + } + } + } + + return ScheduleVideoUpdateModel.findOne(query) + .then(res => !!res) + } + static listVideosToUpdate (t: Transaction) { const query = { where: { updateAt: { - [Sequelize.Op.lte]: new Date() + [Op.lte]: new Date() } }, include: [ @@ -57,7 +72,8 @@ export class ScheduleVideoUpdateModel extends Model { model: VideoModel.scope( [ VideoScopeNames.WITH_FILES, - VideoScopeNames.WITH_ACCOUNT_DETAILS + VideoScopeNames.WITH_ACCOUNT_DETAILS, + VideoScopeNames.WITH_BLACKLISTED ] ) } @@ -68,4 +84,21 @@ export class ScheduleVideoUpdateModel extends Model { return ScheduleVideoUpdateModel.findAll(query) } + static deleteByVideoId (videoId: number, t: Transaction) { + const query = { + where: { + videoId + }, + transaction: t + } + + return ScheduleVideoUpdateModel.destroy(query) + } + + toFormattedJSON () { + return { + updateAt: this.updateAt, + privacy: this.privacy || undefined + } + } }