ファイルと画像認識処理の改善 (#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:
@ -1,6 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import define from '../../../define';
|
||||
import { detectUrlMine } from '../../../../../misc/detect-url-mine';
|
||||
import { detectUrlMime } from '../../../../../misc/detect-url-mime';
|
||||
import { Emojis } from '../../../../../models';
|
||||
import { genId } from '../../../../../misc/gen-id';
|
||||
import { getConnection } from 'typeorm';
|
||||
@ -46,7 +46,7 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, me) => {
|
||||
const type = await detectUrlMine(ps.url);
|
||||
const type = await detectUrlMime(ps.url);
|
||||
|
||||
const exists = await Emojis.findOne({
|
||||
name: ps.name,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import define from '../../../define';
|
||||
import { detectUrlMine } from '../../../../../misc/detect-url-mine';
|
||||
import { detectUrlMime } from '../../../../../misc/detect-url-mime';
|
||||
import { ID } from '../../../../../misc/cafy-id';
|
||||
import { Emojis } from '../../../../../models';
|
||||
import { getConnection } from 'typeorm';
|
||||
@ -52,7 +52,7 @@ export default define(meta, async (ps) => {
|
||||
|
||||
if (emoji == null) throw new ApiError(meta.errors.noSuchEmoji);
|
||||
|
||||
const type = await detectUrlMine(ps.url);
|
||||
const type = await detectUrlMime(ps.url);
|
||||
|
||||
await Emojis.update(emoji.id, {
|
||||
updatedAt: new Date(),
|
||||
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { serverLogger } from '..';
|
||||
import { IImage, convertToPng, convertToJpeg } from '../../services/drive/image-processor';
|
||||
import { createTemp } from '../../misc/create-temp';
|
||||
import { downloadUrl } from '../../misc/donwload-url';
|
||||
import { detectMine } from '../../misc/detect-mine';
|
||||
import { detectType } from '../../misc/get-file-info';
|
||||
|
||||
export async function proxyMedia(ctx: Koa.Context) {
|
||||
const url = 'url' in ctx.query ? ctx.query.url : 'https://' + ctx.params.url;
|
||||
@ -15,21 +15,21 @@ export async function proxyMedia(ctx: Koa.Context) {
|
||||
try {
|
||||
await downloadUrl(url, path);
|
||||
|
||||
const [type, ext] = await detectMine(path);
|
||||
const { mime, ext } = await detectType(path);
|
||||
|
||||
if (!type.startsWith('image/')) throw 403;
|
||||
if (!mime.startsWith('image/')) throw 403;
|
||||
|
||||
let image: IImage;
|
||||
|
||||
if ('static' in ctx.query && ['image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng'].includes(type)) {
|
||||
if ('static' in ctx.query && ['image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng'].includes(mime)) {
|
||||
image = await convertToPng(path, 498, 280);
|
||||
} else if ('preview' in ctx.query && ['image/jpeg', 'image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng'].includes(type)) {
|
||||
} else if ('preview' in ctx.query && ['image/jpeg', 'image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng'].includes(mime)) {
|
||||
image = await convertToJpeg(path, 200, 200);
|
||||
} else {
|
||||
image = {
|
||||
data: fs.readFileSync(path),
|
||||
ext,
|
||||
type,
|
||||
type: mime,
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user