chore (backend): remove unused value
This commit is contained in:
parent
e5bac649c8
commit
98cc23557f
2 changed files with 22 additions and 31 deletions
|
@ -7,7 +7,6 @@ import probeImageSize from "probe-image-size";
|
|||
import isSvg from "is-svg";
|
||||
import sharp from "sharp";
|
||||
import { encode } from "blurhash";
|
||||
import { inspect } from "node:util";
|
||||
|
||||
type FileInfo = {
|
||||
size: number;
|
||||
|
@ -18,7 +17,6 @@ type FileInfo = {
|
|||
height?: number;
|
||||
orientation?: number;
|
||||
blurhash?: string;
|
||||
warnings: string[];
|
||||
};
|
||||
|
||||
const TYPE_OCTET_STREAM = {
|
||||
|
@ -35,8 +33,6 @@ const TYPE_SVG = {
|
|||
* Get file information
|
||||
*/
|
||||
export async function getFileInfo(path: string): Promise<FileInfo> {
|
||||
const warnings = [] as string[];
|
||||
|
||||
const size = await getFileSize(path);
|
||||
const md5 = await calcHash(path);
|
||||
|
||||
|
@ -61,14 +57,12 @@ export async function getFileInfo(path: string): Promise<FileInfo> {
|
|||
"image/avif",
|
||||
].includes(type.mime)
|
||||
) {
|
||||
const imageSize = await detectImageSize(path).catch((e) => {
|
||||
warnings.push(`detectImageSize failed:\n${inspect(e)}`);
|
||||
const imageSize = await detectImageSize(path).catch((_) => {
|
||||
return undefined;
|
||||
});
|
||||
|
||||
// うまく判定できない画像は octet-stream にする
|
||||
if (!imageSize) {
|
||||
warnings.push("cannot detect image dimensions");
|
||||
type = TYPE_OCTET_STREAM;
|
||||
} else if (imageSize.wUnits === "px") {
|
||||
width = imageSize.width;
|
||||
|
@ -77,11 +71,8 @@ export async function getFileInfo(path: string): Promise<FileInfo> {
|
|||
|
||||
// 制限を超えている画像は octet-stream にする
|
||||
if (imageSize.width > 16383 || imageSize.height > 16383) {
|
||||
warnings.push("image dimensions exceeds limits");
|
||||
type = TYPE_OCTET_STREAM;
|
||||
}
|
||||
} else {
|
||||
warnings.push(`unsupported unit type: ${imageSize.wUnits}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,8 +89,7 @@ export async function getFileInfo(path: string): Promise<FileInfo> {
|
|||
"image/avif",
|
||||
].includes(type.mime)
|
||||
) {
|
||||
blurhash = await getBlurhash(path).catch((e) => {
|
||||
warnings.push(`getBlurhash failed:\n${inspect(e)}`);
|
||||
blurhash = await getBlurhash(path).catch((_) => {
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
@ -113,7 +103,6 @@ export async function getFileInfo(path: string): Promise<FileInfo> {
|
|||
height,
|
||||
orientation,
|
||||
blurhash,
|
||||
warnings,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -477,18 +477,20 @@ export async function addFile({
|
|||
requestHeaders = null,
|
||||
usageHint = null,
|
||||
}: AddFileArgs): Promise<DriveFile> {
|
||||
const info = await getFileInfo(path);
|
||||
logger.info(`${JSON.stringify(info)}`);
|
||||
const fileInfo = await getFileInfo(path);
|
||||
logger.info(`${JSON.stringify(fileInfo)}`);
|
||||
|
||||
// detect name
|
||||
const detectedName =
|
||||
name ||
|
||||
(info.fileExtension ? `untitled.${info.fileExtension}` : "untitled");
|
||||
(fileInfo.fileExtension
|
||||
? `untitled.${fileInfo.fileExtension}`
|
||||
: "untitled");
|
||||
|
||||
if (user && !force) {
|
||||
// Check if there is a file with the same hash
|
||||
const much = await DriveFiles.findOneBy({
|
||||
md5: info.md5,
|
||||
md5: fileInfo.md5,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
|
@ -516,7 +518,7 @@ export async function addFile({
|
|||
logger.debug("drive capacity override applied");
|
||||
logger.debug(
|
||||
`overrideCap: ${driveCapacity}bytes, usage: ${usage}bytes, u+s: ${
|
||||
usage + info.size
|
||||
usage + fileInfo.size
|
||||
}bytes`,
|
||||
);
|
||||
}
|
||||
|
@ -524,7 +526,7 @@ export async function addFile({
|
|||
logger.debug(`drive usage is ${usage} (max: ${driveCapacity})`);
|
||||
|
||||
// If usage limit exceeded
|
||||
if (usage + info.size > driveCapacity) {
|
||||
if (usage + fileInfo.size > driveCapacity) {
|
||||
if (Users.isLocalUser(user)) {
|
||||
throw new IdentifiableError(
|
||||
"c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6",
|
||||
|
@ -534,7 +536,7 @@ export async function addFile({
|
|||
// (アバターまたはバナーを含まず)最も古いファイルを削除する
|
||||
expireOldFile(
|
||||
(await Users.findOneByOrFail({ id: user.id })) as IRemoteUser,
|
||||
driveCapacity - info.size,
|
||||
driveCapacity - fileInfo.size,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -562,12 +564,12 @@ export async function addFile({
|
|||
orientation?: number;
|
||||
} = {};
|
||||
|
||||
if (info.width != null && info.height != null) {
|
||||
properties.width = info.width;
|
||||
properties.height = info.height;
|
||||
if (fileInfo.width != null && fileInfo.height != null) {
|
||||
properties.width = fileInfo.width;
|
||||
properties.height = fileInfo.height;
|
||||
}
|
||||
if (info.orientation != null) {
|
||||
properties.orientation = info.orientation;
|
||||
if (fileInfo.orientation != null) {
|
||||
properties.orientation = fileInfo.orientation;
|
||||
}
|
||||
|
||||
const profile = user
|
||||
|
@ -585,7 +587,7 @@ export async function addFile({
|
|||
file.folderId = folder != null ? folder.id : null;
|
||||
file.comment = comment;
|
||||
file.properties = properties;
|
||||
file.blurhash = info.blurhash ?? null;
|
||||
file.blurhash = fileInfo.blurhash ?? null;
|
||||
file.isLink = isLink;
|
||||
file.requestIp = requestIp;
|
||||
file.requestHeaders = requestHeaders;
|
||||
|
@ -618,9 +620,9 @@ export async function addFile({
|
|||
if (isLink) {
|
||||
try {
|
||||
file.size = 0;
|
||||
file.md5 = info.md5;
|
||||
file.md5 = fileInfo.md5;
|
||||
file.name = detectedName;
|
||||
file.type = info.mime;
|
||||
file.type = fileInfo.mime;
|
||||
file.storedInternal = false;
|
||||
|
||||
file = await DriveFiles.insert(file).then((x) =>
|
||||
|
@ -645,9 +647,9 @@ export async function addFile({
|
|||
file,
|
||||
path,
|
||||
detectedName,
|
||||
info.mime,
|
||||
info.md5,
|
||||
info.size,
|
||||
fileInfo.mime,
|
||||
fileInfo.md5,
|
||||
fileInfo.size,
|
||||
usageHint,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue