aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/user-video-history.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account/user-video-history.ts')
-rw-r--r--server/models/account/user-video-history.ts100
1 files changed, 0 insertions, 100 deletions
diff --git a/server/models/account/user-video-history.ts b/server/models/account/user-video-history.ts
deleted file mode 100644
index 6be1d65ea..000000000
--- a/server/models/account/user-video-history.ts
+++ /dev/null
@@ -1,100 +0,0 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { VideoModel } from '../video/video'
3import { UserModel } from './user'
4import { DestroyOptions, Op, Transaction } from 'sequelize'
5import { MUserAccountId, MUserId } from '@server/types/models'
6
7@Table({
8 tableName: 'userVideoHistory',
9 indexes: [
10 {
11 fields: [ 'userId', 'videoId' ],
12 unique: true
13 },
14 {
15 fields: [ 'userId' ]
16 },
17 {
18 fields: [ 'videoId' ]
19 }
20 ]
21})
22export class UserVideoHistoryModel extends Model {
23 @CreatedAt
24 createdAt: Date
25
26 @UpdatedAt
27 updatedAt: Date
28
29 @AllowNull(false)
30 @IsInt
31 @Column
32 currentTime: 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 @ForeignKey(() => UserModel)
47 @Column
48 userId: number
49
50 @BelongsTo(() => UserModel, {
51 foreignKey: {
52 allowNull: false
53 },
54 onDelete: 'CASCADE'
55 })
56 User: UserModel
57
58 static listForApi (user: MUserAccountId, start: number, count: number, search?: string) {
59 return VideoModel.listForApi({
60 start,
61 count,
62 search,
63 sort: '-"userVideoHistory"."updatedAt"',
64 nsfw: null, // All
65 includeLocalVideos: true,
66 withFiles: false,
67 user,
68 historyOfUser: user
69 })
70 }
71
72 static removeUserHistoryBefore (user: MUserId, beforeDate: string, t: Transaction) {
73 const query: DestroyOptions = {
74 where: {
75 userId: user.id
76 },
77 transaction: t
78 }
79
80 if (beforeDate) {
81 query.where['updatedAt'] = {
82 [Op.lt]: beforeDate
83 }
84 }
85
86 return UserVideoHistoryModel.destroy(query)
87 }
88
89 static removeOldHistory (beforeDate: string) {
90 const query: DestroyOptions = {
91 where: {
92 updatedAt: {
93 [Op.lt]: beforeDate
94 }
95 }
96 }
97
98 return UserVideoHistoryModel.destroy(query)
99 }
100}