ニジカ投稿局 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.

local-video-viewer-watch-section.ts 1.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { MLocalVideoViewerWatchSection } from '@server/types/models/index.js'
  2. import { Transaction } from 'sequelize'
  3. import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Table } from 'sequelize-typescript'
  4. import { SequelizeModel } from '../shared/index.js'
  5. import { LocalVideoViewerModel } from './local-video-viewer.js'
  6. @Table({
  7. tableName: 'localVideoViewerWatchSection',
  8. updatedAt: false,
  9. indexes: [
  10. {
  11. fields: [ 'localVideoViewerId' ]
  12. }
  13. ]
  14. })
  15. export class LocalVideoViewerWatchSectionModel extends SequelizeModel<LocalVideoViewerWatchSectionModel> {
  16. @CreatedAt
  17. createdAt: Date
  18. @AllowNull(false)
  19. @Column
  20. watchStart: number
  21. @AllowNull(false)
  22. @Column
  23. watchEnd: number
  24. @ForeignKey(() => LocalVideoViewerModel)
  25. @Column
  26. localVideoViewerId: number
  27. @BelongsTo(() => LocalVideoViewerModel, {
  28. foreignKey: {
  29. allowNull: false
  30. },
  31. onDelete: 'CASCADE'
  32. })
  33. LocalVideoViewer: Awaited<LocalVideoViewerModel>
  34. static async bulkCreateSections (options: {
  35. localVideoViewerId: number
  36. watchSections: {
  37. start: number
  38. end: number
  39. }[]
  40. transaction?: Transaction
  41. }) {
  42. const { localVideoViewerId, watchSections, transaction } = options
  43. const models: MLocalVideoViewerWatchSection[] = []
  44. for (const section of watchSections) {
  45. const watchStart = section.start || 0
  46. const watchEnd = section.end || 0
  47. if (watchStart === watchEnd) continue
  48. const model = await this.create({
  49. watchStart,
  50. watchEnd,
  51. localVideoViewerId
  52. }, { transaction })
  53. models.push(model)
  54. }
  55. return models
  56. }
  57. }