mirror of https://github.com/Chocobozzz/PeerTube
Fix too long filename video upload
parent
e78acf81ff
commit
453537426a
|
@ -1,4 +1,6 @@
|
||||||
|
import { truncate } from 'lodash-es'
|
||||||
import { UploadState, UploadxOptions, UploadxService } from 'ngx-uploadx'
|
import { UploadState, UploadxOptions, UploadxService } from 'ngx-uploadx'
|
||||||
|
import { isIOS } from 'src/assets/player/utils'
|
||||||
import { HttpErrorResponse, HttpEventType, HttpHeaders } from '@angular/common/http'
|
import { HttpErrorResponse, HttpEventType, HttpHeaders } from '@angular/common/http'
|
||||||
import { AfterViewInit, Component, ElementRef, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
|
import { AfterViewInit, Component, ElementRef, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
|
||||||
import { Router } from '@angular/router'
|
import { Router } from '@angular/router'
|
||||||
|
@ -10,7 +12,6 @@ import { LoadingBarService } from '@ngx-loading-bar/core'
|
||||||
import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
|
import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
|
||||||
import { UploaderXFormData } from './uploaderx-form-data'
|
import { UploaderXFormData } from './uploaderx-form-data'
|
||||||
import { VideoSend } from './video-send'
|
import { VideoSend } from './video-send'
|
||||||
import { isIOS } from 'src/assets/player/utils'
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-video-upload',
|
selector: 'my-video-upload',
|
||||||
|
@ -281,6 +282,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
|
||||||
channelId: this.firstStepChannelId,
|
channelId: this.firstStepChannelId,
|
||||||
nsfw: this.serverConfig.instance.isNSFW,
|
nsfw: this.serverConfig.instance.isNSFW,
|
||||||
privacy: this.highestPrivacy.toString(),
|
privacy: this.highestPrivacy.toString(),
|
||||||
|
name: this.buildVideoFilename(file.name),
|
||||||
filename: file.name,
|
filename: file.name,
|
||||||
previewfile: previewfile as any
|
previewfile: previewfile as any
|
||||||
}
|
}
|
||||||
|
@ -311,8 +313,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
|
||||||
}
|
}
|
||||||
|
|
||||||
private closeFirstStep (filename: string) {
|
private closeFirstStep (filename: string) {
|
||||||
const nameWithoutExtension = filename.replace(/\.[^/.]+$/, '')
|
const name = this.buildVideoFilename(filename)
|
||||||
const name = nameWithoutExtension.length < 3 ? filename : nameWithoutExtension
|
|
||||||
|
|
||||||
this.form.patchValue({
|
this.form.patchValue({
|
||||||
name,
|
name,
|
||||||
|
@ -369,4 +370,18 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
|
||||||
|
|
||||||
return extensions.some(e => filename.endsWith(e))
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,7 +211,7 @@ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([
|
||||||
const videoFileMetadata = {
|
const videoFileMetadata = {
|
||||||
mimetype: req.headers['x-upload-content-type'] as string,
|
mimetype: req.headers['x-upload-content-type'] as string,
|
||||||
size: +req.headers['x-upload-content-length'],
|
size: +req.headers['x-upload-content-length'],
|
||||||
originalname: req.body.name
|
originalname: req.body.filename
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = res.locals.oauth.token.User
|
const user = res.locals.oauth.token.User
|
||||||
|
|
Loading…
Reference in New Issue