diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video-comment.ts | 95 | ||||
-rw-r--r-- | server/models/video/video.ts | 12 |
2 files changed, 107 insertions, 0 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts new file mode 100644 index 000000000..92c0c6112 --- /dev/null +++ b/server/models/video/video-comment.ts | |||
@@ -0,0 +1,95 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import { | ||
3 | AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, IFindOptions, Is, IsUUID, Model, Table, | ||
4 | UpdatedAt | ||
5 | } from 'sequelize-typescript' | ||
6 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' | ||
7 | import { CONSTRAINTS_FIELDS } from '../../initializers' | ||
8 | import { ActorModel } from '../activitypub/actor' | ||
9 | import { throwIfNotValid } from '../utils' | ||
10 | import { VideoModel } from './video' | ||
11 | |||
12 | @Table({ | ||
13 | tableName: 'videoComment', | ||
14 | indexes: [ | ||
15 | { | ||
16 | fields: [ 'videoId' ] | ||
17 | } | ||
18 | ] | ||
19 | }) | ||
20 | export class VideoCommentModel extends Model<VideoCommentModel> { | ||
21 | @CreatedAt | ||
22 | createdAt: Date | ||
23 | |||
24 | @UpdatedAt | ||
25 | updatedAt: Date | ||
26 | |||
27 | @AllowNull(false) | ||
28 | @Is('VideoCommentUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) | ||
29 | @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max)) | ||
30 | url: string | ||
31 | |||
32 | @AllowNull(false) | ||
33 | @Column(DataType.TEXT) | ||
34 | text: string | ||
35 | |||
36 | @ForeignKey(() => VideoCommentModel) | ||
37 | @Column | ||
38 | originCommentId: number | ||
39 | |||
40 | @BelongsTo(() => VideoCommentModel, { | ||
41 | foreignKey: { | ||
42 | allowNull: true | ||
43 | }, | ||
44 | onDelete: 'CASCADE' | ||
45 | }) | ||
46 | OriginVideoComment: VideoCommentModel | ||
47 | |||
48 | @ForeignKey(() => VideoCommentModel) | ||
49 | @Column | ||
50 | inReplyToCommentId: number | ||
51 | |||
52 | @BelongsTo(() => VideoCommentModel, { | ||
53 | foreignKey: { | ||
54 | allowNull: true | ||
55 | }, | ||
56 | onDelete: 'CASCADE' | ||
57 | }) | ||
58 | InReplyToVideoComment: VideoCommentModel | ||
59 | |||
60 | @ForeignKey(() => VideoModel) | ||
61 | @Column | ||
62 | videoId: number | ||
63 | |||
64 | @BelongsTo(() => VideoModel, { | ||
65 | foreignKey: { | ||
66 | allowNull: false | ||
67 | }, | ||
68 | onDelete: 'CASCADE' | ||
69 | }) | ||
70 | Video: VideoModel | ||
71 | |||
72 | @ForeignKey(() => ActorModel) | ||
73 | @Column | ||
74 | actorId: number | ||
75 | |||
76 | @BelongsTo(() => ActorModel, { | ||
77 | foreignKey: { | ||
78 | allowNull: false | ||
79 | }, | ||
80 | onDelete: 'CASCADE' | ||
81 | }) | ||
82 | Actor: ActorModel | ||
83 | |||
84 | static loadByUrl (url: string, t?: Sequelize.Transaction) { | ||
85 | const query: IFindOptions<VideoCommentModel> = { | ||
86 | where: { | ||
87 | url | ||
88 | } | ||
89 | } | ||
90 | |||
91 | if (t !== undefined) query.transaction = t | ||
92 | |||
93 | return VideoCommentModel.findOne(query) | ||
94 | } | ||
95 | } | ||
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 8c49bc3af..b6a2ce6b5 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -491,6 +491,18 @@ export class VideoModel extends Model<VideoModel> { | |||
491 | return VideoModel.findById(id) | 491 | return VideoModel.findById(id) |
492 | } | 492 | } |
493 | 493 | ||
494 | static loadByUrl (url: string, t?: Sequelize.Transaction) { | ||
495 | const query: IFindOptions<VideoModel> = { | ||
496 | where: { | ||
497 | url | ||
498 | } | ||
499 | } | ||
500 | |||
501 | if (t !== undefined) query.transaction = t | ||
502 | |||
503 | return VideoModel.findOne(query) | ||
504 | } | ||
505 | |||
494 | static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { | 506 | static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { |
495 | const query: IFindOptions<VideoModel> = { | 507 | const query: IFindOptions<VideoModel> = { |
496 | where: { | 508 | where: { |