summaryrefslogtreecommitdiff
path: root/src/services/drive/add-file.ts
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2020-08-18 22:48:52 +0900
committerGitHub <noreply@github.com>2020-08-18 22:48:52 +0900
commit48e8ee440bcff712710666861262b0a6492a3794 (patch)
tree68a2845d0c2555ec632eb282c57f21109d9f157f /src/services/drive/add-file.ts
parentChannel (#6621) (diff)
downloadmisskey-48e8ee440bcff712710666861262b0a6492a3794.tar.gz
misskey-48e8ee440bcff712710666861262b0a6492a3794.tar.bz2
misskey-48e8ee440bcff712710666861262b0a6492a3794.zip
WebPのアニメーションが失われるのを修正 Fix #6625 (#6649)
Diffstat (limited to 'src/services/drive/add-file.ts')
-rw-r--r--src/services/drive/add-file.ts47
1 files changed, 35 insertions, 12 deletions
diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts
index 91bbace481..fbd2f76ddc 100644
--- a/src/services/drive/add-file.ts
+++ b/src/services/drive/add-file.ts
@@ -7,7 +7,7 @@ import { deleteFile } from './delete-file';
import { fetchMeta } from '../../misc/fetch-meta';
import { GenerateVideoThumbnail } from './generate-video-thumbnail';
import { driveLogger } from './logger';
-import { IImage, convertToJpeg, convertToWebp, convertToPng, convertToPngOrJpeg } from './image-processor';
+import { IImage, convertSharpToJpeg, convertSharpToWebp, convertSharpToPng, convertSharpToPngOrJpeg } from './image-processor';
import { contentDisposition } from '../../misc/content-disposition';
import { getFileInfo } from '../../misc/get-file-info';
import { DriveFiles, DriveFolders, Users, Instances, UserProfiles } from '../../models';
@@ -19,6 +19,7 @@ import { genId } from '../../misc/gen-id';
import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error';
import * as S3 from 'aws-sdk/clients/s3';
import { getS3 } from './s3';
+import * as sharp from 'sharp';
const logger = driveLogger.createSubLogger('register', 'yellow');
@@ -143,6 +144,34 @@ async function save(file: DriveFile, path: string, name: string, type: string, h
* @param generateWeb Generate webpublic or not
*/
export async function generateAlts(path: string, type: string, generateWeb: boolean) {
+ if (type.startsWith('video/')) {
+ try {
+ const thumbnail = await GenerateVideoThumbnail(path);
+ return {
+ webpublic: null,
+ thumbnail
+ };
+ } catch (e) {
+ logger.warn(`GenerateVideoThumbnail failed: ${e}`);
+ return {
+ webpublic: null,
+ thumbnail: null
+ };
+ }
+ }
+
+ const img = sharp(path);
+ const metadata = await img.metadata();
+ const isAnimated = metadata.pages && metadata.pages > 1;
+
+ // skip animated
+ if (isAnimated) {
+ return {
+ webpublic: null,
+ thumbnail: null
+ };
+ }
+
// #region webpublic
let webpublic: IImage | null = null;
@@ -151,11 +180,11 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
try {
if (['image/jpeg'].includes(type)) {
- webpublic = await convertToJpeg(path, 2048, 2048);
+ webpublic = await convertSharpToJpeg(img, 2048, 2048);
} else if (['image/webp'].includes(type)) {
- webpublic = await convertToWebp(path, 2048, 2048);
+ webpublic = await convertSharpToWebp(img, 2048, 2048);
} else if (['image/png'].includes(type)) {
- webpublic = await convertToPng(path, 2048, 2048);
+ webpublic = await convertSharpToPng(img, 2048, 2048);
} else {
logger.debug(`web image not created (not an required image)`);
}
@@ -172,15 +201,9 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
try {
if (['image/jpeg', 'image/webp'].includes(type)) {
- thumbnail = await convertToJpeg(path, 498, 280);
+ thumbnail = await convertSharpToJpeg(img, 498, 280);
} else if (['image/png'].includes(type)) {
- thumbnail = await convertToPngOrJpeg(path, 498, 280);
- } else if (type.startsWith('video/')) {
- try {
- thumbnail = await GenerateVideoThumbnail(path);
- } catch (e) {
- logger.warn(`GenerateVideoThumbnail failed: ${e}`);
- }
+ thumbnail = await convertSharpToPngOrJpeg(img, 498, 280);
} else {
logger.debug(`thumbnail not created (not an required file)`);
}