X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fmodels%2Faccount%2Fuser-video-history.ts;h=15cb399c952bc909305e331baf8cece53bccd45d;hb=8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4;hp=0476cad9deef992bc6347e7d6cbb387d598a6b4f;hpb=6e46de095d7169355dd83030f6ce4a582304153a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/user-video-history.ts b/server/models/account/user-video-history.ts index 0476cad9d..15cb399c9 100644 --- a/server/models/account/user-video-history.ts +++ b/server/models/account/user-video-history.ts @@ -1,6 +1,7 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Min, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript' import { VideoModel } from '../video/video' import { UserModel } from './user' +import { Transaction, Op, DestroyOptions } from 'sequelize' @Table({ tableName: 'userVideoHistory', @@ -52,4 +53,34 @@ export class UserVideoHistoryModel extends Model { onDelete: 'CASCADE' }) User: UserModel + + static listForApi (user: UserModel, start: number, count: number) { + return VideoModel.listForApi({ + start, + count, + sort: '-UserVideoHistories.updatedAt', + nsfw: null, // All + includeLocalVideos: true, + withFiles: false, + user, + historyOfUser: user + }) + } + + static removeHistoryBefore (user: UserModel, beforeDate: string, t: Transaction) { + const query: DestroyOptions = { + where: { + userId: user.id + }, + transaction: t + } + + if (beforeDate) { + query.where.updatedAt = { + [Op.lt]: beforeDate + } + } + + return UserVideoHistoryModel.destroy(query) + } }