diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-03 14:23:45 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-03 14:23:45 +0100 |
commit | 453537426a4e172967320cfac4bb1f53c28d94f5 (patch) | |
tree | e29f12f364a5e449c9edb6e011e6ca1d2a4f5857 /client/src | |
parent | e78acf81ff00568555e9823c1d9b01c7616b7272 (diff) | |
download | PeerTube-453537426a4e172967320cfac4bb1f53c28d94f5.tar.gz PeerTube-453537426a4e172967320cfac4bb1f53c28d94f5.tar.zst PeerTube-453537426a4e172967320cfac4bb1f53c28d94f5.zip |
Fix too long filename video upload
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts index 76205db44..28d7ec458 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts | |||
@@ -1,4 +1,6 @@ | |||
1 | import { truncate } from 'lodash-es' | ||
1 | import { UploadState, UploadxOptions, UploadxService } from 'ngx-uploadx' | 2 | import { UploadState, UploadxOptions, UploadxService } from 'ngx-uploadx' |
3 | import { isIOS } from 'src/assets/player/utils' | ||
2 | import { HttpErrorResponse, HttpEventType, HttpHeaders } from '@angular/common/http' | 4 | import { HttpErrorResponse, HttpEventType, HttpHeaders } from '@angular/common/http' |
3 | import { AfterViewInit, Component, ElementRef, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' | 5 | import { AfterViewInit, Component, ElementRef, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' |
4 | import { Router } from '@angular/router' | 6 | import { Router } from '@angular/router' |
@@ -10,7 +12,6 @@ import { LoadingBarService } from '@ngx-loading-bar/core' | |||
10 | import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' | 12 | import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' |
11 | import { UploaderXFormData } from './uploaderx-form-data' | 13 | import { UploaderXFormData } from './uploaderx-form-data' |
12 | import { VideoSend } from './video-send' | 14 | import { VideoSend } from './video-send' |
13 | import { isIOS } from 'src/assets/player/utils' | ||
14 | 15 | ||
15 | @Component({ | 16 | @Component({ |
16 | selector: 'my-video-upload', | 17 | selector: 'my-video-upload', |
@@ -281,6 +282,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
281 | channelId: this.firstStepChannelId, | 282 | channelId: this.firstStepChannelId, |
282 | nsfw: this.serverConfig.instance.isNSFW, | 283 | nsfw: this.serverConfig.instance.isNSFW, |
283 | privacy: this.highestPrivacy.toString(), | 284 | privacy: this.highestPrivacy.toString(), |
285 | name: this.buildVideoFilename(file.name), | ||
284 | filename: file.name, | 286 | filename: file.name, |
285 | previewfile: previewfile as any | 287 | previewfile: previewfile as any |
286 | } | 288 | } |
@@ -311,8 +313,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
311 | } | 313 | } |
312 | 314 | ||
313 | private closeFirstStep (filename: string) { | 315 | private closeFirstStep (filename: string) { |
314 | const nameWithoutExtension = filename.replace(/\.[^/.]+$/, '') | 316 | const name = this.buildVideoFilename(filename) |
315 | const name = nameWithoutExtension.length < 3 ? filename : nameWithoutExtension | ||
316 | 317 | ||
317 | this.form.patchValue({ | 318 | this.form.patchValue({ |
318 | name, | 319 | name, |
@@ -369,4 +370,18 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
369 | 370 | ||
370 | return extensions.some(e => filename.endsWith(e)) | 371 | return extensions.some(e => filename.endsWith(e)) |
371 | } | 372 | } |
373 | |||
374 | private buildVideoFilename (filename: string) { | ||
375 | const nameWithoutExtension = filename.replace(/\.[^/.]+$/, '') | ||
376 | let name = nameWithoutExtension.length < 3 | ||
377 | ? filename | ||
378 | : nameWithoutExtension | ||
379 | |||
380 | const videoNameMaxSize = 110 | ||
381 | if (name.length > videoNameMaxSize) { | ||
382 | name = truncate(name, { length: videoNameMaxSize, omission: '' }) | ||
383 | } | ||
384 | |||
385 | return name | ||
386 | } | ||
372 | } | 387 | } |