2023-04-07 01:56:46 +00:00
|
|
|
import * as assert from "assert";
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { dirname } from "node:path";
|
|
|
|
import { getFileInfo } from "../src/misc/get-file-info.js";
|
|
|
|
import { async } from "./utils.js";
|
2022-05-14 07:09:47 +00:00
|
|
|
|
|
|
|
const _filename = fileURLToPath(import.meta.url);
|
|
|
|
const _dirname = dirname(_filename);
|
2020-01-12 07:40:58 +00:00
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
describe("Get file info", () => {
|
|
|
|
it("Empty file", async(async () => {
|
2022-05-14 07:09:47 +00:00
|
|
|
const path = `${_dirname}/resources/emptyfile`;
|
2023-04-07 01:56:46 +00:00
|
|
|
const info = (await getFileInfo(path, {
|
|
|
|
skipSensitiveDetection: true,
|
|
|
|
})) as any;
|
2023-06-05 23:40:48 +00:00
|
|
|
info.warnings = undefined;
|
|
|
|
info.blurhash = undefined;
|
|
|
|
info.sensitive = undefined;
|
|
|
|
info.porn = undefined;
|
2020-01-12 07:40:58 +00:00
|
|
|
assert.deepStrictEqual(info, {
|
|
|
|
size: 0,
|
2023-04-07 01:56:46 +00:00
|
|
|
md5: "d41d8cd98f00b204e9800998ecf8427e",
|
2020-01-12 07:40:58 +00:00
|
|
|
type: {
|
2023-04-07 01:56:46 +00:00
|
|
|
mime: "application/octet-stream",
|
2022-05-21 13:21:41 +00:00
|
|
|
ext: null,
|
2020-01-12 07:40:58 +00:00
|
|
|
},
|
|
|
|
width: undefined,
|
|
|
|
height: undefined,
|
2021-12-03 02:19:28 +00:00
|
|
|
orientation: undefined,
|
2020-01-12 07:40:58 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("Generic JPEG", async(async () => {
|
2022-05-14 07:09:47 +00:00
|
|
|
const path = `${_dirname}/resources/Lenna.jpg`;
|
2023-04-07 01:56:46 +00:00
|
|
|
const info = (await getFileInfo(path, {
|
|
|
|
skipSensitiveDetection: true,
|
|
|
|
})) as any;
|
2023-06-05 23:40:48 +00:00
|
|
|
info.warnings = undefined;
|
|
|
|
info.blurhash = undefined;
|
|
|
|
info.sensitive = undefined;
|
|
|
|
info.porn = undefined;
|
2020-01-12 07:40:58 +00:00
|
|
|
assert.deepStrictEqual(info, {
|
|
|
|
size: 25360,
|
2023-04-07 01:56:46 +00:00
|
|
|
md5: "091b3f259662aa31e2ffef4519951168",
|
2020-01-12 07:40:58 +00:00
|
|
|
type: {
|
2023-04-07 01:56:46 +00:00
|
|
|
mime: "image/jpeg",
|
|
|
|
ext: "jpg",
|
2020-01-12 07:40:58 +00:00
|
|
|
},
|
|
|
|
width: 512,
|
|
|
|
height: 512,
|
2021-12-03 02:19:28 +00:00
|
|
|
orientation: undefined,
|
2020-01-12 07:40:58 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("Generic APNG", async(async () => {
|
2022-05-14 07:09:47 +00:00
|
|
|
const path = `${_dirname}/resources/anime.png`;
|
2023-04-07 01:56:46 +00:00
|
|
|
const info = (await getFileInfo(path, {
|
|
|
|
skipSensitiveDetection: true,
|
|
|
|
})) as any;
|
2023-06-05 23:40:48 +00:00
|
|
|
info.warnings = undefined;
|
|
|
|
info.blurhash = undefined;
|
|
|
|
info.sensitive = undefined;
|
|
|
|
info.porn = undefined;
|
2020-01-12 07:40:58 +00:00
|
|
|
assert.deepStrictEqual(info, {
|
|
|
|
size: 1868,
|
2023-04-07 01:56:46 +00:00
|
|
|
md5: "08189c607bea3b952704676bb3c979e0",
|
2020-01-12 07:40:58 +00:00
|
|
|
type: {
|
2023-04-07 01:56:46 +00:00
|
|
|
mime: "image/apng",
|
|
|
|
ext: "apng",
|
2020-01-12 07:40:58 +00:00
|
|
|
},
|
|
|
|
width: 256,
|
|
|
|
height: 256,
|
2021-12-03 02:19:28 +00:00
|
|
|
orientation: undefined,
|
2020-01-12 07:40:58 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("Generic AGIF", async(async () => {
|
2022-05-14 07:09:47 +00:00
|
|
|
const path = `${_dirname}/resources/anime.gif`;
|
2023-04-07 01:56:46 +00:00
|
|
|
const info = (await getFileInfo(path, {
|
|
|
|
skipSensitiveDetection: true,
|
|
|
|
})) as any;
|
2023-06-05 23:40:48 +00:00
|
|
|
info.warnings = undefined;
|
|
|
|
info.blurhash = undefined;
|
|
|
|
info.sensitive = undefined;
|
|
|
|
info.porn = undefined;
|
2020-01-12 07:40:58 +00:00
|
|
|
assert.deepStrictEqual(info, {
|
|
|
|
size: 2248,
|
2023-04-07 01:56:46 +00:00
|
|
|
md5: "32c47a11555675d9267aee1a86571e7e",
|
2020-01-12 07:40:58 +00:00
|
|
|
type: {
|
2023-04-07 01:56:46 +00:00
|
|
|
mime: "image/gif",
|
|
|
|
ext: "gif",
|
2020-01-12 07:40:58 +00:00
|
|
|
},
|
|
|
|
width: 256,
|
|
|
|
height: 256,
|
2021-12-03 02:19:28 +00:00
|
|
|
orientation: undefined,
|
2020-01-12 07:40:58 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("PNG with alpha", async(async () => {
|
2022-05-14 07:09:47 +00:00
|
|
|
const path = `${_dirname}/resources/with-alpha.png`;
|
2023-04-07 01:56:46 +00:00
|
|
|
const info = (await getFileInfo(path, {
|
|
|
|
skipSensitiveDetection: true,
|
|
|
|
})) as any;
|
2023-06-05 23:40:48 +00:00
|
|
|
info.warnings = undefined;
|
|
|
|
info.blurhash = undefined;
|
|
|
|
info.sensitive = undefined;
|
|
|
|
info.porn = undefined;
|
2020-01-12 07:40:58 +00:00
|
|
|
assert.deepStrictEqual(info, {
|
|
|
|
size: 3772,
|
2023-04-07 01:56:46 +00:00
|
|
|
md5: "f73535c3e1e27508885b69b10cf6e991",
|
2020-01-12 07:40:58 +00:00
|
|
|
type: {
|
2023-04-07 01:56:46 +00:00
|
|
|
mime: "image/png",
|
|
|
|
ext: "png",
|
2020-01-12 07:40:58 +00:00
|
|
|
},
|
|
|
|
width: 256,
|
|
|
|
height: 256,
|
2021-12-03 02:19:28 +00:00
|
|
|
orientation: undefined,
|
2020-01-12 07:40:58 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("Generic SVG", async(async () => {
|
2022-05-14 07:09:47 +00:00
|
|
|
const path = `${_dirname}/resources/image.svg`;
|
2023-04-07 01:56:46 +00:00
|
|
|
const info = (await getFileInfo(path, {
|
|
|
|
skipSensitiveDetection: true,
|
|
|
|
})) as any;
|
2023-06-05 23:40:48 +00:00
|
|
|
info.warnings = undefined;
|
|
|
|
info.blurhash = undefined;
|
|
|
|
info.sensitive = undefined;
|
|
|
|
info.porn = undefined;
|
2020-01-12 07:40:58 +00:00
|
|
|
assert.deepStrictEqual(info, {
|
|
|
|
size: 505,
|
2023-04-07 01:56:46 +00:00
|
|
|
md5: "b6f52b4b021e7b92cdd04509c7267965",
|
2020-01-12 07:40:58 +00:00
|
|
|
type: {
|
2023-04-07 01:56:46 +00:00
|
|
|
mime: "image/svg+xml",
|
|
|
|
ext: "svg",
|
2020-01-12 07:40:58 +00:00
|
|
|
},
|
|
|
|
width: 256,
|
|
|
|
height: 256,
|
2021-12-03 02:19:28 +00:00
|
|
|
orientation: undefined,
|
2020-01-12 07:40:58 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("SVG with XML definition", async(async () => {
|
2021-03-24 03:23:05 +00:00
|
|
|
// https://github.com/misskey-dev/misskey/issues/4413
|
2022-05-14 07:09:47 +00:00
|
|
|
const path = `${_dirname}/resources/with-xml-def.svg`;
|
2023-04-07 01:56:46 +00:00
|
|
|
const info = (await getFileInfo(path, {
|
|
|
|
skipSensitiveDetection: true,
|
|
|
|
})) as any;
|
2023-06-05 23:40:48 +00:00
|
|
|
info.warnings = undefined;
|
|
|
|
info.blurhash = undefined;
|
|
|
|
info.sensitive = undefined;
|
|
|
|
info.porn = undefined;
|
2020-01-12 07:40:58 +00:00
|
|
|
assert.deepStrictEqual(info, {
|
|
|
|
size: 544,
|
2023-04-07 01:56:46 +00:00
|
|
|
md5: "4b7a346cde9ccbeb267e812567e33397",
|
2020-01-12 07:40:58 +00:00
|
|
|
type: {
|
2023-04-07 01:56:46 +00:00
|
|
|
mime: "image/svg+xml",
|
|
|
|
ext: "svg",
|
2020-01-12 07:40:58 +00:00
|
|
|
},
|
|
|
|
width: 256,
|
|
|
|
height: 256,
|
2021-12-03 02:19:28 +00:00
|
|
|
orientation: undefined,
|
2020-01-12 07:40:58 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("Dimension limit", async(async () => {
|
2022-05-14 07:09:47 +00:00
|
|
|
const path = `${_dirname}/resources/25000x25000.png`;
|
2023-04-07 01:56:46 +00:00
|
|
|
const info = (await getFileInfo(path, {
|
|
|
|
skipSensitiveDetection: true,
|
|
|
|
})) as any;
|
2023-06-05 23:40:48 +00:00
|
|
|
info.warnings = undefined;
|
|
|
|
info.blurhash = undefined;
|
|
|
|
info.sensitive = undefined;
|
|
|
|
info.porn = undefined;
|
2020-01-12 07:40:58 +00:00
|
|
|
assert.deepStrictEqual(info, {
|
|
|
|
size: 75933,
|
2023-04-07 01:56:46 +00:00
|
|
|
md5: "268c5dde99e17cf8fe09f1ab3f97df56",
|
2020-01-12 07:40:58 +00:00
|
|
|
type: {
|
2023-04-07 01:56:46 +00:00
|
|
|
mime: "application/octet-stream", // do not treat as image
|
2022-05-21 13:21:41 +00:00
|
|
|
ext: null,
|
2020-01-12 07:40:58 +00:00
|
|
|
},
|
|
|
|
width: 25000,
|
|
|
|
height: 25000,
|
2021-12-03 02:19:28 +00:00
|
|
|
orientation: undefined,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("Rotate JPEG", async(async () => {
|
2022-05-14 07:09:47 +00:00
|
|
|
const path = `${_dirname}/resources/rotate.jpg`;
|
2023-04-07 01:56:46 +00:00
|
|
|
const info = (await getFileInfo(path, {
|
|
|
|
skipSensitiveDetection: true,
|
|
|
|
})) as any;
|
2023-06-05 23:40:48 +00:00
|
|
|
info.warnings = undefined;
|
|
|
|
info.blurhash = undefined;
|
|
|
|
info.sensitive = undefined;
|
|
|
|
info.porn = undefined;
|
2021-12-03 02:19:28 +00:00
|
|
|
assert.deepStrictEqual(info, {
|
|
|
|
size: 12624,
|
2023-04-07 01:56:46 +00:00
|
|
|
md5: "68d5b2d8d1d1acbbce99203e3ec3857e",
|
2021-12-03 02:19:28 +00:00
|
|
|
type: {
|
2023-04-07 01:56:46 +00:00
|
|
|
mime: "image/jpeg",
|
|
|
|
ext: "jpg",
|
2021-12-03 02:19:28 +00:00
|
|
|
},
|
|
|
|
width: 512,
|
|
|
|
height: 256,
|
|
|
|
orientation: 8,
|
2020-01-12 07:40:58 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|