refactor (backend): flatten a type

This commit is contained in:
naskya 2024-04-27 10:05:48 +09:00
parent 38cd4bafde
commit e5bac649c8
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
2 changed files with 14 additions and 14 deletions

View file

@ -9,13 +9,11 @@ import sharp from "sharp";
import { encode } from "blurhash"; import { encode } from "blurhash";
import { inspect } from "node:util"; import { inspect } from "node:util";
export type FileInfo = { type FileInfo = {
size: number; size: number;
md5: string; md5: string;
type: { mime: string;
mime: string; fileExtension: string | null;
ext: string | null;
};
width?: number; width?: number;
height?: number; height?: number;
orientation?: number; orientation?: number;
@ -109,7 +107,8 @@ export async function getFileInfo(path: string): Promise<FileInfo> {
return { return {
size, size,
md5, md5,
type, mime: type.mime,
fileExtension: type.ext,
width, width,
height, height,
orientation, orientation,

View file

@ -482,7 +482,8 @@ export async function addFile({
// detect name // detect name
const detectedName = const detectedName =
name || (info.type.ext ? `untitled.${info.type.ext}` : "untitled"); name ||
(info.fileExtension ? `untitled.${info.fileExtension}` : "untitled");
if (user && !force) { if (user && !force) {
// Check if there is a file with the same hash // Check if there is a file with the same hash
@ -561,12 +562,12 @@ export async function addFile({
orientation?: number; orientation?: number;
} = {}; } = {};
if (info.width) { if (info.width != null && info.height != null) {
properties["width"] = info.width; properties.width = info.width;
properties["height"] = info.height; properties.height = info.height;
} }
if (info.orientation != null) { if (info.orientation != null) {
properties["orientation"] = info.orientation; properties.orientation = info.orientation;
} }
const profile = user const profile = user
@ -584,7 +585,7 @@ export async function addFile({
file.folderId = folder != null ? folder.id : null; file.folderId = folder != null ? folder.id : null;
file.comment = comment; file.comment = comment;
file.properties = properties; file.properties = properties;
file.blurhash = info.blurhash || null; file.blurhash = info.blurhash ?? null;
file.isLink = isLink; file.isLink = isLink;
file.requestIp = requestIp; file.requestIp = requestIp;
file.requestHeaders = requestHeaders; file.requestHeaders = requestHeaders;
@ -619,7 +620,7 @@ export async function addFile({
file.size = 0; file.size = 0;
file.md5 = info.md5; file.md5 = info.md5;
file.name = detectedName; file.name = detectedName;
file.type = info.type.mime; file.type = info.mime;
file.storedInternal = false; file.storedInternal = false;
file = await DriveFiles.insert(file).then((x) => file = await DriveFiles.insert(file).then((x) =>
@ -644,7 +645,7 @@ export async function addFile({
file, file,
path, path,
detectedName, detectedName,
info.type.mime, info.mime,
info.md5, info.md5,
info.size, info.size,
usageHint, usageHint,