ファイルと画像認識処理の改善 (#5690)

* dimensions制限とリファクタ

* comment

* 不要な変更削除

* use fromFile など

* Add probe-image-size.d.ts

* えーCRLFで作るなよ…

* Update src/@types/probe-image-size.d.ts

Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* fix d.ts

* Update src/@types/probe-image-size.d.ts

Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* Update src/@types/probe-image-size.d.ts

Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* fix

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
MeiMei 2020-01-12 16:40:58 +09:00 committed by GitHub
parent d09d06e4cb
commit 9703ba5340
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 456 additions and 154 deletions

View file

@ -8,7 +8,7 @@ import { contentDisposition } from '../../misc/content-disposition';
import { DriveFiles } from '../../models';
import { InternalStorage } from '../../services/drive/internal-storage';
import { downloadUrl } from '../../misc/donwload-url';
import { detectMine } from '../../misc/detect-mine';
import { detectType } from '../../misc/get-file-info';
import { convertToJpeg, convertToPng } from '../../services/drive/image-processor';
import { GenerateVideoThumbnail } from '../../services/drive/generate-video-thumbnail';
@ -52,15 +52,15 @@ export default async function(ctx: Koa.Context) {
try {
await downloadUrl(file.uri, path);
const [type, ext] = await detectMine(path);
const { mime, ext } = await detectType(path);
const convertFile = async () => {
if (isThumbnail) {
if (['image/jpeg', 'image/webp'].includes(type)) {
if (['image/jpeg', 'image/webp'].includes(mime)) {
return await convertToJpeg(path, 498, 280);
} else if (['image/png'].includes(type)) {
} else if (['image/png'].includes(mime)) {
return await convertToPng(path, 498, 280);
} else if (type.startsWith('video/')) {
} else if (mime.startsWith('video/')) {
return await GenerateVideoThumbnail(path);
}
}
@ -68,7 +68,7 @@ export default async function(ctx: Koa.Context) {
return {
data: fs.readFileSync(path),
ext,
type,
type: mime,
};
};