]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/video/video-view.ts
Fix audio transcoding with video only file
[github/Chocobozzz/PeerTube.git] / server / models / video / video-view.ts
CommitLineData
41fb13c3
C
1import { literal, Op } from 'sequelize'
2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table } from 'sequelize-typescript'
6b5f72be 3import { AttributesOnly } from '@shared/typescript-utils'
6b616860 4import { VideoModel } from './video'
6b616860
C
5
6@Table({
7 tableName: 'videoView',
4f0f2ab2 8 updatedAt: false,
6b616860
C
9 indexes: [
10 {
11 fields: [ 'videoId' ]
0926af7a
C
12 },
13 {
14 fields: [ 'startDate' ]
6b616860
C
15 }
16 ]
17})
16c016e8 18export class VideoViewModel extends Model<Partial<AttributesOnly<VideoViewModel>>> {
6b616860
C
19 @CreatedAt
20 createdAt: Date
21
22 @AllowNull(false)
41fb13c3 23 @Column(DataType.DATE)
6b616860
C
24 startDate: Date
25
26 @AllowNull(false)
41fb13c3 27 @Column(DataType.DATE)
6b616860
C
28 endDate: Date
29
30 @AllowNull(false)
31 @Column
32 views: number
33
34 @ForeignKey(() => VideoModel)
35 @Column
36 videoId: number
37
38 @BelongsTo(() => VideoModel, {
39 foreignKey: {
40 allowNull: false
41 },
42 onDelete: 'CASCADE'
43 })
44 Video: VideoModel
45
cda03765
C
46 static removeOldRemoteViewsHistory (beforeDate: string) {
47 const query = {
48 where: {
49 startDate: {
41fb13c3 50 [Op.lt]: beforeDate
cda03765
C
51 },
52 videoId: {
41fb13c3 53 [Op.in]: literal('(SELECT "id" FROM "video" WHERE "remote" IS TRUE)')
cda03765
C
54 }
55 }
56 }
57
58 return VideoViewModel.destroy(query)
59 }
6b616860 60}