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

View file

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