diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-15 15:18:54 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-06-15 15:18:54 +0200 |
commit | fd261a8de933779480d631891efd2ac289045f2f (patch) | |
tree | 620e4e3ba1b750098973dfe9976e6d9492134770 /server/models/video/video-view.ts | |
parent | c1466c52fb6b7193a5d242bab21f263d4e3ca6d7 (diff) | |
download | PeerTube-fd261a8de933779480d631891efd2ac289045f2f.tar.gz PeerTube-fd261a8de933779480d631891efd2ac289045f2f.tar.zst PeerTube-fd261a8de933779480d631891efd2ac289045f2f.zip |
Fix video view filename
Diffstat (limited to 'server/models/video/video-view.ts')
-rw-r--r-- | server/models/video/video-view.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/server/models/video/video-view.ts b/server/models/video/video-view.ts new file mode 100644 index 000000000..40db5effd --- /dev/null +++ b/server/models/video/video-view.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table } from 'sequelize-typescript' | ||
2 | import { VideoModel } from './video' | ||
3 | import * as Sequelize from 'sequelize' | ||
4 | |||
5 | @Table({ | ||
6 | tableName: 'videoView', | ||
7 | updatedAt: false, | ||
8 | indexes: [ | ||
9 | { | ||
10 | fields: [ 'videoId' ] | ||
11 | }, | ||
12 | { | ||
13 | fields: [ 'startDate' ] | ||
14 | } | ||
15 | ] | ||
16 | }) | ||
17 | export class VideoViewModel extends Model<VideoViewModel> { | ||
18 | @CreatedAt | ||
19 | createdAt: Date | ||
20 | |||
21 | @AllowNull(false) | ||
22 | @Column(Sequelize.DATE) | ||
23 | startDate: Date | ||
24 | |||
25 | @AllowNull(false) | ||
26 | @Column(Sequelize.DATE) | ||
27 | endDate: Date | ||
28 | |||
29 | @AllowNull(false) | ||
30 | @Column | ||
31 | views: number | ||
32 | |||
33 | @ForeignKey(() => VideoModel) | ||
34 | @Column | ||
35 | videoId: number | ||
36 | |||
37 | @BelongsTo(() => VideoModel, { | ||
38 | foreignKey: { | ||
39 | allowNull: false | ||
40 | }, | ||
41 | onDelete: 'CASCADE' | ||
42 | }) | ||
43 | Video: VideoModel | ||
44 | |||
45 | static removeOldRemoteViewsHistory (beforeDate: string) { | ||
46 | const query = { | ||
47 | where: { | ||
48 | startDate: { | ||
49 | [Sequelize.Op.lt]: beforeDate | ||
50 | }, | ||
51 | videoId: { | ||
52 | [Sequelize.Op.in]: Sequelize.literal('(SELECT "id" FROM "video" WHERE "remote" IS TRUE)') | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | |||
57 | return VideoViewModel.destroy(query) | ||
58 | } | ||
59 | } | ||