From ea54cd04c1ff0e55651cd5fb1a83672acde68604 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 8 Jun 2021 09:33:03 +0200 Subject: Fix video upload with a capitalized ext --- server/lib/activitypub/actors/shared/object-to-model-attributes.ts | 4 ++-- server/lib/job-queue/handlers/video-file-import.ts | 3 ++- server/lib/job-queue/handlers/video-import.ts | 3 ++- server/lib/local-actor.ts | 5 +++-- 4 files changed, 9 insertions(+), 6 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/actors/shared/object-to-model-attributes.ts b/server/lib/activitypub/actors/shared/object-to-model-attributes.ts index 66b22c952..f53b98448 100644 --- a/server/lib/activitypub/actors/shared/object-to-model-attributes.ts +++ b/server/lib/activitypub/actors/shared/object-to-model-attributes.ts @@ -1,5 +1,5 @@ -import { extname } from 'path' import { v4 as uuidv4 } from 'uuid' +import { getLowercaseExtension } from '@server/helpers/core-utils' import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' import { MIMETYPES } from '@server/initializers/constants' import { ActorModel } from '@server/models/actor/actor' @@ -43,7 +43,7 @@ function getImageInfoFromObject (actorObject: ActivityPubActor, type: ActorImage if (icon.mediaType) { extension = mimetypes.MIMETYPE_EXT[icon.mediaType] } else { - const tmp = extname(icon.url) + const tmp = getLowercaseExtension(icon.url) if (mimetypes.EXT_MIMETYPE[tmp] !== undefined) extension = tmp } diff --git a/server/lib/job-queue/handlers/video-file-import.ts b/server/lib/job-queue/handlers/video-file-import.ts index 8297a1571..048963033 100644 --- a/server/lib/job-queue/handlers/video-file-import.ts +++ b/server/lib/job-queue/handlers/video-file-import.ts @@ -1,6 +1,7 @@ import * as Bull from 'bull' import { copy, stat } from 'fs-extra' import { extname } from 'path' +import { getLowercaseExtension } from '@server/helpers/core-utils' import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' import { UserModel } from '@server/models/user/user' @@ -55,7 +56,7 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) { const { size } = await stat(inputFilePath) const fps = await getVideoFileFPS(inputFilePath) - const fileExt = extname(inputFilePath) + const fileExt = getLowercaseExtension(inputFilePath) const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === videoFileResolution) diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index d71053e87..937f586c9 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts @@ -1,6 +1,7 @@ import * as Bull from 'bull' import { move, remove, stat } from 'fs-extra' import { extname } from 'path' +import { getLowercaseExtension } from '@server/helpers/core-utils' import { retryTransactionWrapper } from '@server/helpers/database-utils' import { YoutubeDL } from '@server/helpers/youtube-dl' import { isPostImportVideoAccepted } from '@server/lib/moderation' @@ -119,7 +120,7 @@ async function processFile (downloader: () => Promise, videoImport: MVid const duration = await getDurationFromVideoFile(tempVideoPath) // Prepare video file object for creation in database - const fileExt = extname(tempVideoPath) + const fileExt = getLowercaseExtension(tempVideoPath) const videoFileData = { extname: fileExt, resolution: videoFileResolution, diff --git a/server/lib/local-actor.ts b/server/lib/local-actor.ts index 55e77dd04..2d2bd43a1 100644 --- a/server/lib/local-actor.ts +++ b/server/lib/local-actor.ts @@ -1,8 +1,9 @@ import 'multer' import { queue } from 'async' import * as LRUCache from 'lru-cache' -import { extname, join } from 'path' +import { join } from 'path' import { v4 as uuidv4 } from 'uuid' +import { getLowercaseExtension } from '@server/helpers/core-utils' import { ActorModel } from '@server/models/actor/actor' import { ActivityPubActorType, ActorImageType } from '@shared/models' import { retryTransactionWrapper } from '../helpers/database-utils' @@ -41,7 +42,7 @@ async function updateLocalActorImageFile ( ? ACTOR_IMAGES_SIZE.AVATARS : ACTOR_IMAGES_SIZE.BANNERS - const extension = extname(imagePhysicalFile.filename) + const extension = getLowercaseExtension(imagePhysicalFile.filename) const imageName = uuidv4() + extension const destination = join(CONFIG.STORAGE.ACTOR_IMAGES, imageName) -- cgit v1.2.3