]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-import.ts
Import torrents with webtorrent
[github/Chocobozzz/PeerTube.git] / server / models / video / video-import.ts
index c2e55509c128fb75ab0645525afd50092f030c15..d6c02e5ac9af65dfded8a7b91dd2eb1e324e2a6d 100644 (file)
@@ -21,6 +21,7 @@ import { VideoImport, VideoImportState } from '../../../shared'
 import { VideoChannelModel } from './video-channel'
 import { AccountModel } from '../account/account'
 import { TagModel } from './tag'
+import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos'
 
 @DefaultScope({
   include: [
@@ -39,8 +40,7 @@ import { TagModel } from './tag'
           ]
         },
         {
-          model: () => TagModel,
-          required: false
+          model: () => TagModel
         }
       ]
     }
@@ -63,11 +63,23 @@ export class VideoImportModel extends Model<VideoImportModel> {
   @UpdatedAt
   updatedAt: Date
 
-  @AllowNull(false)
+  @AllowNull(true)
+  @Default(null)
   @Is('VideoImportTargetUrl', value => throwIfNotValid(value, isVideoImportTargetUrlValid, 'targetUrl'))
   @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_IMPORTS.URL.max))
   targetUrl: string
 
+  @AllowNull(true)
+  @Default(null)
+  @Is('VideoImportMagnetUri', value => throwIfNotValid(value, isVideoMagnetUriValid, 'magnetUri'))
+  @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_IMPORTS.URL.max)) // Use the same constraints than URLs
+  magnetUri: string
+
+  @AllowNull(true)
+  @Default(null)
+  @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_NAME.max))
+  torrentName: string
+
   @AllowNull(false)
   @Default(null)
   @Is('VideoImportState', value => throwIfNotValid(value, isVideoImportStateValid, 'state'))
@@ -106,6 +118,7 @@ export class VideoImportModel extends Model<VideoImportModel> {
 
   static listUserVideoImportsForApi (accountId: number, start: number, count: number, sort: string) {
     const query = {
+      distinct: true,
       offset: start,
       limit: count,
       order: getSort(sort),
@@ -158,7 +171,11 @@ export class VideoImportModel extends Model<VideoImportModel> {
 
     return {
       id: this.id,
+
       targetUrl: this.targetUrl,
+      magnetUri: this.magnetUri,
+      torrentName: this.torrentName,
+
       state: {
         id: this.state,
         label: VideoImportModel.getStateLabel(this.state)