mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-12-01 12:59:15 -06:00
b211106695
* Add "currentTime" and "event" body params to view endpoint * Merge watching and view endpoints * Introduce WatchAction AP activity * Add tables to store viewer information of local videos * Add endpoints to fetch video views/viewers stats of local videos * Refactor views/viewers handlers * Support "views" and "viewers" counters for both VOD and live videos
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { Transaction } from 'sequelize'
|
|
import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table } from 'sequelize-typescript'
|
|
import { MLocalVideoViewerWatchSection } from '@server/types/models'
|
|
import { AttributesOnly } from '@shared/typescript-utils'
|
|
import { LocalVideoViewerModel } from './local-video-viewer'
|
|
|
|
@Table({
|
|
tableName: 'localVideoViewerWatchSection',
|
|
updatedAt: false,
|
|
indexes: [
|
|
{
|
|
fields: [ 'localVideoViewerId' ]
|
|
}
|
|
]
|
|
})
|
|
export class LocalVideoViewerWatchSectionModel extends Model<Partial<AttributesOnly<LocalVideoViewerWatchSectionModel>>> {
|
|
@CreatedAt
|
|
createdAt: Date
|
|
|
|
@AllowNull(false)
|
|
@Column
|
|
watchStart: number
|
|
|
|
@AllowNull(false)
|
|
@Column
|
|
watchEnd: number
|
|
|
|
@ForeignKey(() => LocalVideoViewerModel)
|
|
@Column
|
|
localVideoViewerId: number
|
|
|
|
@BelongsTo(() => LocalVideoViewerModel, {
|
|
foreignKey: {
|
|
allowNull: false
|
|
},
|
|
onDelete: 'CASCADE'
|
|
})
|
|
LocalVideoViewer: LocalVideoViewerModel
|
|
|
|
static async bulkCreateSections (options: {
|
|
localVideoViewerId: number
|
|
watchSections: {
|
|
start: number
|
|
end: number
|
|
}[]
|
|
transaction?: Transaction
|
|
}) {
|
|
const { localVideoViewerId, watchSections, transaction } = options
|
|
const models: MLocalVideoViewerWatchSection[] = []
|
|
|
|
for (const section of watchSections) {
|
|
const model = await this.create({
|
|
watchStart: section.start,
|
|
watchEnd: section.end,
|
|
localVideoViewerId
|
|
}, { transaction })
|
|
|
|
models.push(model)
|
|
}
|
|
|
|
return models
|
|
}
|
|
}
|