style:lint

This commit is contained in:
手瓜一十雪
2024-08-25 11:45:50 +08:00
parent 5685605731
commit 05ab077521
11 changed files with 58 additions and 70 deletions

View File

@@ -4,6 +4,7 @@ import crypto, { randomUUID } from 'crypto';
import util from 'util';
import path from 'node:path';
import * as fileType from 'file-type';
import { solveAsyncProblem, solveProblem } from './helper';
export function isGIF(path: string) {
const buffer = Buffer.alloc(4);
@@ -185,12 +186,11 @@ export enum FileUriType {
}
export async function checkUriType(Uri: string) {
//先判断是否是本地文件
try {
if (fs.existsSync(Uri)) return { Uri: Uri, Type: FileUriType.Local };
} catch (error) {
}
try {
const LocalFileRet = await solveProblem((Uri) => { if (fs.existsSync(Uri)) return { Uri: Uri, Type: FileUriType.Local }; });
if (LocalFileRet) return LocalFileRet;
const OtherFileRet = await solveProblem((Uri) => {
//再判断是否是Http
if (Uri.startsWith('http://') || Uri.startsWith('https://')) {
return { Uri: Uri, Type: FileUriType.Remote };
@@ -200,10 +200,9 @@ export async function checkUriType(Uri: string) {
return { Uri: Uri, Type: FileUriType.Base64 };
}
if (Uri.startsWith('file://')) {
let pathname: string;
let filePath: string;
// await fs.copyFile(url.pathname, filePath);
pathname = decodeURIComponent(new URL(Uri).pathname);
const pathname = decodeURIComponent(new URL(Uri).pathname);
if (process.platform === 'win32') {
filePath = pathname.slice(1);
} else {
@@ -211,8 +210,9 @@ export async function checkUriType(Uri: string) {
}
return { Uri: filePath, Type: FileUriType.Local };
}
} catch (error) {
}
});
if (OtherFileRet) return OtherFileRet;
return { Uri: Uri, Type: FileUriType.Unknown };
}
@@ -232,7 +232,7 @@ export async function uri2local(dir: string, uri: string, filename: string | und
//接下来都要有文件名
if (!filename) filename = randomUUID();
//解析Http和Https协议
if (UriType == FileUriType.Remote) {
const pathInfo = path.parse(decodeURIComponent(new URL(HandledUri).pathname));
if (pathInfo.name) {

View File

@@ -3,8 +3,28 @@ import fs from 'fs';
import os from 'node:os';
import { QQLevel } from '@/core';
//下面这个类是用于将uid+msgid合并的类
export async function solveProblem<T extends (...arg: any[]) => any>(func: T): Promise<ReturnType<T> | undefined> {
return new Promise<ReturnType<T> | undefined>(async (resolve) => {
try {
const result = func();
resolve(result);
} catch (e) {
resolve(undefined);
}
});
}
export async function solveAsyncProblem<T extends (...arg: any[]) => Promise<any>>(func: T): Promise<Awaited<ReturnType<T>> | undefined> {
return new Promise<Awaited<ReturnType<T>> | undefined>(async (resolve) => {
try {
const result = await func();
resolve(result);
} catch (e) {
resolve(undefined);
}
});
}
//下面这个类是用于将uid+msgid合并的类
export class UUIDConverter {
static encode(highStr: string, lowStr: string): string {
const high = BigInt(highStr);