]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Merge branch 'release/4.0.0' into develop
authorChocobozzz <me@florianbigard.com>
Fri, 3 Dec 2021 13:40:52 +0000 (14:40 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 3 Dec 2021 13:40:52 +0000 (14:40 +0100)
client/src/app/+admin/config/edit-custom-config/edit-vod-transcoding.component.html
client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts
server/lib/job-queue/handlers/video-transcoding.ts
server/middlewares/validators/videos/videos.ts
server/models/video/video-job-info.ts

index 048f7908d1f069589edbe7d605e0bdae643c5b62..1158f027bd71ceeee9d57a5c29a7e131f93d101e 100644 (file)
@@ -51,7 +51,7 @@
                     i18n-labelText labelText="Allow additional extensions"
                   >
                     <ng-container ngProjectAs="description">
-                      <span i18n>Allows users to upload {{ additionalVideoExtensions }} videos.</span>
+                      <span i18n>Allows users to upload videos with additional extensions than .mp4, .ogv and .webm (for example: .avi, .mov, .mkv etc).</span>
                     </ng-container>
                   </my-peertube-checkbox>
                 </div>
index 76205db4448601ff09732fa9c1f90e39829a91e0..28d7ec45894852cc37fccb837ee9822bd41499df 100644 (file)
@@ -1,4 +1,6 @@
+import { truncate } from 'lodash-es'
 import { UploadState, UploadxOptions, UploadxService } from 'ngx-uploadx'
+import { isIOS } from 'src/assets/player/utils'
 import { HttpErrorResponse, HttpEventType, HttpHeaders } from '@angular/common/http'
 import { AfterViewInit, Component, ElementRef, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
 import { Router } from '@angular/router'
@@ -10,7 +12,6 @@ import { LoadingBarService } from '@ngx-loading-bar/core'
 import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
 import { UploaderXFormData } from './uploaderx-form-data'
 import { VideoSend } from './video-send'
-import { isIOS } from 'src/assets/player/utils'
 
 @Component({
   selector: 'my-video-upload',
@@ -281,6 +282,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
       channelId: this.firstStepChannelId,
       nsfw: this.serverConfig.instance.isNSFW,
       privacy: this.highestPrivacy.toString(),
+      name: this.buildVideoFilename(file.name),
       filename: file.name,
       previewfile: previewfile as any
     }
@@ -311,8 +313,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
   }
 
   private closeFirstStep (filename: string) {
-    const nameWithoutExtension = filename.replace(/\.[^/.]+$/, '')
-    const name = nameWithoutExtension.length < 3 ? filename : nameWithoutExtension
+    const name = this.buildVideoFilename(filename)
 
     this.form.patchValue({
       name,
@@ -369,4 +370,18 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
 
     return extensions.some(e => filename.endsWith(e))
   }
+
+  private buildVideoFilename (filename: string) {
+    const nameWithoutExtension = filename.replace(/\.[^/.]+$/, '')
+    let name = nameWithoutExtension.length < 3
+      ? filename
+      : nameWithoutExtension
+
+    const videoNameMaxSize = 110
+    if (name.length > videoNameMaxSize) {
+      name = truncate(name, { length: videoNameMaxSize, omission: '' })
+    }
+
+    return name
+  }
 }
index 0d80eb6c58f66dd4f00f905cfd63f0b8db9a90cb..0edcdcba3967af55e1f51bfda28410f5b68717e4 100644 (file)
@@ -53,6 +53,7 @@ async function processVideoTranscoding (job: Job) {
 
   if (!handler) {
     await moveToFailedTranscodingState(video)
+    await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
 
     throw new Error('Cannot find transcoding handler for ' + payload.type)
   }
@@ -62,12 +63,20 @@ async function processVideoTranscoding (job: Job) {
   } catch (error) {
     await moveToFailedTranscodingState(video)
 
+    await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
+
     throw error
   }
 
   return video
 }
 
+// ---------------------------------------------------------------------------
+
+export {
+  processVideoTranscoding
+}
+
 // ---------------------------------------------------------------------------
 // Job handlers
 // ---------------------------------------------------------------------------
@@ -119,7 +128,7 @@ async function handleWebTorrentMergeAudioJob (job: Job, payload: MergeAudioTrans
 
   logger.info('Merge audio transcoding job for %s ended.', video.uuid, lTags(video.uuid))
 
-  await onVideoFileOptimizer(video, payload, 'video', user)
+  await onVideoFirstWebTorrentTranscoding(video, payload, 'video', user)
 }
 
 async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodingPayload, video: MVideoFullLight, user: MUserId) {
@@ -129,7 +138,7 @@ async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodi
 
   logger.info('Optimize transcoding job for %s ended.', video.uuid, lTags(video.uuid))
 
-  await onVideoFileOptimizer(video, payload, transcodeType, user)
+  await onVideoFirstWebTorrentTranscoding(video, payload, transcodeType, user)
 }
 
 // ---------------------------------------------------------------------------
@@ -159,7 +168,7 @@ async function onHlsPlaylistGeneration (video: MVideoFullLight, user: MUser, pay
   await retryTransactionWrapper(moveToNextState, video, payload.isNewVideo)
 }
 
-async function onVideoFileOptimizer (
+async function onVideoFirstWebTorrentTranscoding (
   videoArg: MVideoWithFile,
   payload: OptimizeTranscodingPayload | MergeAudioTranscodingPayload,
   transcodeType: TranscodeOptionsType,
@@ -211,6 +220,8 @@ async function onNewWebTorrentFileResolution (
   await retryTransactionWrapper(moveToNextState, video, payload.isNewVideo)
 }
 
+// ---------------------------------------------------------------------------
+
 async function createHlsJobIfEnabled (user: MUserId, payload: {
   videoUUID: string
   resolution: number
@@ -241,16 +252,6 @@ async function createHlsJobIfEnabled (user: MUserId, payload: {
   return true
 }
 
-// ---------------------------------------------------------------------------
-
-export {
-  processVideoTranscoding,
-  createHlsJobIfEnabled,
-  onNewWebTorrentFileResolution
-}
-
-// ---------------------------------------------------------------------------
-
 async function createLowerResolutionsJobs (options: {
   video: MVideoFullLight
   user: MUserId
index 4916decbf3c483c59de21af03974fd4d0352fdbf..3ebdbc33d1141ac699693ef7199a6463e11a9ace 100644 (file)
@@ -211,7 +211,7 @@ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([
     const videoFileMetadata = {
       mimetype: req.headers['x-upload-content-type'] as string,
       size: +req.headers['x-upload-content-length'],
-      originalname: req.body.name
+      originalname: req.body.filename
     }
 
     const user = res.locals.oauth.token.User
index cb1f3f2f095daf55969dd2b92ceb0c95e11e7657..7da5128d7598a338262bf3b8b5a09082270240c2 100644 (file)
@@ -3,6 +3,8 @@ import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, IsInt, Mo
 import { AttributesOnly } from '@shared/core-utils'
 import { VideoModel } from './video'
 
+export type VideoJobInfoColumnType = 'pendingMove' | 'pendingTranscode'
+
 @Table({
   tableName: 'videoJobInfo',
   indexes: [
@@ -57,7 +59,7 @@ export class VideoJobInfoModel extends Model<Partial<AttributesOnly<VideoJobInfo
     return VideoJobInfoModel.findOne({ where, transaction })
   }
 
-  static async increaseOrCreate (videoUUID: string, column: 'pendingMove' | 'pendingTranscode'): Promise<number> {
+  static async increaseOrCreate (videoUUID: string, column: VideoJobInfoColumnType): Promise<number> {
     const options = { type: QueryTypes.SELECT as QueryTypes.SELECT, bind: { videoUUID } }
 
     const [ { pendingMove } ] = await VideoJobInfoModel.sequelize.query<{ pendingMove: number }>(`
@@ -79,7 +81,7 @@ export class VideoJobInfoModel extends Model<Partial<AttributesOnly<VideoJobInfo
     return pendingMove
   }
 
-  static async decrease (videoUUID: string, column: 'pendingMove' | 'pendingTranscode'): Promise<number> {
+  static async decrease (videoUUID: string, column: VideoJobInfoColumnType): Promise<number> {
     const options = { type: QueryTypes.SELECT as QueryTypes.SELECT, bind: { videoUUID } }
 
     const [ { pendingMove } ] = await VideoJobInfoModel.sequelize.query<{ pendingMove: number }>(`