31 lines
980 B
TypeScript
31 lines
980 B
TypeScript
import "server-only";
|
|
|
|
import { getDefaultStorageConfig, getSystemSetting } from "@/lib/db/queries";
|
|
import {
|
|
AGENT_PSD_FONTS_KEY,
|
|
parseAgentPsdFonts,
|
|
type AgentPsdFont,
|
|
} from "@/lib/agents/psd-font-config";
|
|
|
|
export async function readAgentPsdFonts() {
|
|
const setting = await getSystemSetting({ key: AGENT_PSD_FONTS_KEY });
|
|
return parseAgentPsdFonts(setting?.value);
|
|
}
|
|
|
|
export async function tryDeleteAgentPsdFontAssets(font: AgentPsdFont) {
|
|
if (!font.filePath) return;
|
|
|
|
try {
|
|
const storageConfig = await getDefaultStorageConfig().catch(() => undefined);
|
|
if (!storageConfig || storageConfig.type !== "s3") return;
|
|
|
|
const { deleteS3ObjectByPath, toDbS3UploadConfig } = await import("@/lib/storage/service");
|
|
const uploadConfig = toDbS3UploadConfig(storageConfig);
|
|
if (!uploadConfig) return;
|
|
|
|
await deleteS3ObjectByPath(font.filePath, uploadConfig);
|
|
} catch (error) {
|
|
console.warn("[PSD Font] Failed to delete font asset:", error);
|
|
}
|
|
}
|