diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-24 13:36:47 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | b211106695bb82f6c32e53306081b5262c3d109d (patch) | |
tree | fa187de1c33b0956665f5362e29af6b0f6d8bb57 /server/models/video/video-view.ts | |
parent | 69d48ee30c9d47cddf0c3c047dc99a99dcb6e894 (diff) | |
download | PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.gz PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.zst PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.zip |
Support video views/viewers stats in server
* 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
Diffstat (limited to 'server/models/video/video-view.ts')
-rw-r--r-- | server/models/video/video-view.ts | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/server/models/video/video-view.ts b/server/models/video/video-view.ts deleted file mode 100644 index d72df100f..000000000 --- a/server/models/video/video-view.ts +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | import { literal, Op } from 'sequelize' | ||
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table } from 'sequelize-typescript' | ||
3 | import { AttributesOnly } from '@shared/typescript-utils' | ||
4 | import { VideoModel } from './video' | ||
5 | |||
6 | @Table({ | ||
7 | tableName: 'videoView', | ||
8 | updatedAt: false, | ||
9 | indexes: [ | ||
10 | { | ||
11 | fields: [ 'videoId' ] | ||
12 | }, | ||
13 | { | ||
14 | fields: [ 'startDate' ] | ||
15 | } | ||
16 | ] | ||
17 | }) | ||
18 | export class VideoViewModel extends Model<Partial<AttributesOnly<VideoViewModel>>> { | ||
19 | @CreatedAt | ||
20 | createdAt: Date | ||
21 | |||
22 | @AllowNull(false) | ||
23 | @Column(DataType.DATE) | ||
24 | startDate: Date | ||
25 | |||
26 | @AllowNull(false) | ||
27 | @Column(DataType.DATE) | ||
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 | |||
46 | static removeOldRemoteViewsHistory (beforeDate: string) { | ||
47 | const query = { | ||
48 | where: { | ||
49 | startDate: { | ||
50 | [Op.lt]: beforeDate | ||
51 | }, | ||
52 | videoId: { | ||
53 | [Op.in]: literal('(SELECT "id" FROM "video" WHERE "remote" IS TRUE)') | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | return VideoViewModel.destroy(query) | ||
59 | } | ||
60 | } | ||