2023-07-19 16:02:49 +02:00
|
|
|
import { Transaction } from 'sequelize'
|
2024-02-22 10:12:04 +01:00
|
|
|
import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Table, UpdatedAt } from 'sequelize-typescript'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { VideoSource } from '@peertube/peertube-models'
|
2024-02-22 10:12:04 +01:00
|
|
|
import { SequelizeModel, getSort } from '../shared/index.js'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { VideoModel } from './video.js'
|
2022-06-21 15:31:25 +02:00
|
|
|
|
|
|
|
@Table({
|
|
|
|
tableName: 'videoSource',
|
|
|
|
indexes: [
|
|
|
|
{
|
2023-07-19 16:02:49 +02:00
|
|
|
fields: [ 'videoId' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [ { name: 'createdAt', order: 'DESC' } ]
|
2022-06-21 15:31:25 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2024-02-22 10:12:04 +01:00
|
|
|
export class VideoSourceModel extends SequelizeModel<VideoSourceModel> {
|
2022-06-21 15:31:25 +02:00
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
|
|
|
|
|
|
|
@UpdatedAt
|
|
|
|
updatedAt: Date
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
filename: string
|
|
|
|
|
|
|
|
@ForeignKey(() => VideoModel)
|
|
|
|
@Column
|
|
|
|
videoId: number
|
|
|
|
|
2023-07-19 16:02:49 +02:00
|
|
|
@BelongsTo(() => VideoModel, {
|
|
|
|
foreignKey: {
|
|
|
|
allowNull: false
|
|
|
|
},
|
|
|
|
onDelete: 'cascade'
|
|
|
|
})
|
2023-07-31 14:34:36 +02:00
|
|
|
Video: Awaited<VideoModel>
|
2022-06-21 15:31:25 +02:00
|
|
|
|
2023-07-19 16:02:49 +02:00
|
|
|
static loadLatest (videoId: number, transaction?: Transaction) {
|
|
|
|
return VideoSourceModel.findOne({
|
|
|
|
where: { videoId },
|
|
|
|
order: getSort('-createdAt'),
|
|
|
|
transaction
|
|
|
|
})
|
2022-06-21 15:31:25 +02:00
|
|
|
}
|
|
|
|
|
2023-07-19 16:02:49 +02:00
|
|
|
toFormattedJSON (): VideoSource {
|
2022-06-21 15:31:25 +02:00
|
|
|
return {
|
2023-07-19 16:02:49 +02:00
|
|
|
filename: this.filename,
|
|
|
|
createdAt: this.createdAt.toISOString()
|
2022-06-21 15:31:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|