ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

schedule-video-update.ts 2.0 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { Op, Transaction } from 'sequelize'
  2. import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Table, UpdatedAt } from 'sequelize-typescript'
  3. import { VideoPrivacy } from '@peertube/peertube-models'
  4. import { MScheduleVideoUpdate, MScheduleVideoUpdateFormattable } from '@server/types/models/index.js'
  5. import { VideoModel } from './video.js'
  6. import { SequelizeModel } from '../shared/index.js'
  7. @Table({
  8. tableName: 'scheduleVideoUpdate',
  9. indexes: [
  10. {
  11. fields: [ 'videoId' ],
  12. unique: true
  13. },
  14. {
  15. fields: [ 'updateAt' ]
  16. }
  17. ]
  18. })
  19. export class ScheduleVideoUpdateModel extends SequelizeModel<ScheduleVideoUpdateModel> {
  20. @AllowNull(false)
  21. @Default(null)
  22. @Column
  23. updateAt: Date
  24. @AllowNull(true)
  25. @Default(null)
  26. @Column(DataType.INTEGER)
  27. privacy: typeof VideoPrivacy.PUBLIC | typeof VideoPrivacy.UNLISTED | typeof VideoPrivacy.INTERNAL
  28. @CreatedAt
  29. createdAt: Date
  30. @UpdatedAt
  31. updatedAt: Date
  32. @ForeignKey(() => VideoModel)
  33. @Column
  34. videoId: number
  35. @BelongsTo(() => VideoModel, {
  36. foreignKey: {
  37. allowNull: false
  38. },
  39. onDelete: 'cascade'
  40. })
  41. Video: Awaited<VideoModel>
  42. static areVideosToUpdate () {
  43. const query = {
  44. logging: false,
  45. attributes: [ 'id' ],
  46. where: {
  47. updateAt: {
  48. [Op.lte]: new Date()
  49. }
  50. }
  51. }
  52. return ScheduleVideoUpdateModel.findOne(query)
  53. .then(res => !!res)
  54. }
  55. static listVideosToUpdate (transaction?: Transaction) {
  56. const query = {
  57. where: {
  58. updateAt: {
  59. [Op.lte]: new Date()
  60. }
  61. },
  62. transaction
  63. }
  64. return ScheduleVideoUpdateModel.findAll<MScheduleVideoUpdate>(query)
  65. }
  66. static deleteByVideoId (videoId: number, t: Transaction) {
  67. const query = {
  68. where: {
  69. videoId
  70. },
  71. transaction: t
  72. }
  73. return ScheduleVideoUpdateModel.destroy(query)
  74. }
  75. toFormattedJSON (this: MScheduleVideoUpdateFormattable) {
  76. return {
  77. updateAt: this.updateAt,
  78. privacy: this.privacy || undefined
  79. }
  80. }
  81. }