]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/video/video-blacklist.ts
Fix preview 404
[github/Chocobozzz/PeerTube.git] / server / models / video / video-blacklist.ts
CommitLineData
3fd3ab2d 1import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
792dbaf0 2import { SortType } from '../../helpers'
3fd3ab2d
C
3import { getSortOnModel } from '../utils'
4import { VideoModel } from './video'
e02643f3 5
3fd3ab2d
C
6@Table({
7 tableName: 'videoBlacklist',
8 indexes: [
198b205c 9 {
3fd3ab2d
C
10 fields: [ 'videoId' ],
11 unique: true
198b205c 12 }
e02643f3 13 ]
3fd3ab2d
C
14})
15export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
198b205c 16
3fd3ab2d
C
17 @CreatedAt
18 createdAt: Date
198b205c 19
3fd3ab2d
C
20 @UpdatedAt
21 updatedAt: Date
198b205c 22
3fd3ab2d
C
23 @ForeignKey(() => VideoModel)
24 @Column
25 videoId: number
198b205c 26
3fd3ab2d 27 @BelongsTo(() => VideoModel, {
0a6658fd 28 foreignKey: {
0a6658fd
C
29 allowNull: false
30 },
3fd3ab2d 31 onDelete: 'cascade'
198b205c 32 })
3fd3ab2d
C
33 Video: VideoModel
34
35 static listForApi (start: number, count: number, sort: SortType) {
36 const query = {
37 offset: start,
38 limit: count,
39 order: [ getSortOnModel(sort.sortModel, sort.sortValue) ],
40 include: [ { model: VideoModel } ]
41 }
198b205c 42
3fd3ab2d
C
43 return VideoBlacklistModel.findAndCountAll(query)
44 .then(({ rows, count }) => {
45 return {
46 data: rows,
47 total: count
48 }
49 })
198b205c
GS
50 }
51
3fd3ab2d
C
52 static loadByVideoId (id: number) {
53 const query = {
54 where: {
55 videoId: id
56 }
6fcd19ba 57 }
198b205c 58
3fd3ab2d 59 return VideoBlacklistModel.findOne(query)
198b205c
GS
60 }
61
3fd3ab2d
C
62 toFormattedJSON () {
63 const video = this.Video
64
65 return {
66 id: this.id,
67 videoId: this.videoId,
68 createdAt: this.createdAt,
69 updatedAt: this.updatedAt,
70 name: video.name,
71 uuid: video.uuid,
72 description: video.description,
73 duration: video.duration,
74 views: video.views,
75 likes: video.likes,
76 dislikes: video.dislikes,
77 nsfw: video.nsfw
78 }
79 }
198b205c 80}