]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-abuse.ts
Improve create import file job
[github/Chocobozzz/PeerTube.git] / server / models / video / video-abuse.ts
index d0ee969fb10c89f13fdba06c1cd880c9ce60507c..a6319bb79186314d8304fb416b88aae2079b412f 100644 (file)
@@ -1,9 +1,9 @@
-import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
+import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
 import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
+import { VideoAbuse } from '../../../shared/models/videos'
 import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos'
-import { CONFIG } from '../../initializers'
+import { Emailer } from '../../lib/emailer'
 import { AccountModel } from '../account/account'
-import { ServerModel } from '../server/server'
 import { getSort, throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
 
@@ -55,21 +55,20 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
   })
   Video: VideoModel
 
+  @AfterCreate
+  static sendEmailNotification (instance: VideoAbuseModel) {
+    return Emailer.Instance.addVideoAbuseReport(instance.videoId)
+  }
+
   static listForApi (start: number, count: number, sort: string) {
     const query = {
       offset: start,
       limit: count,
-      order: [ getSort(sort) ],
+      order: getSort(sort),
       include: [
         {
           model: AccountModel,
-          required: true,
-          include: [
-            {
-              model: ServerModel,
-              required: false
-            }
-          ]
+          required: true
         },
         {
           model: VideoModel,
@@ -84,24 +83,17 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
       })
   }
 
-  toFormattedJSON () {
-    let reporterServerHost
-
-    if (this.Account.Server) {
-      reporterServerHost = this.Account.Server.host
-    } else {
-      // It means it's our video
-      reporterServerHost = CONFIG.WEBSERVER.HOST
-    }
-
+  toFormattedJSON (): VideoAbuse {
     return {
       id: this.id,
       reason: this.reason,
-      reporterUsername: this.Account.name,
-      reporterServerHost,
-      videoId: this.Video.id,
-      videoUUID: this.Video.uuid,
-      videoName: this.Video.name,
+      reporterAccount: this.Account.toFormattedJSON(),
+      video: {
+        id: this.Video.id,
+        uuid: this.Video.uuid,
+        url: this.Video.url,
+        name: this.Video.name
+      },
       createdAt: this.createdAt
     }
   }