This commit is contained in:
Ivan Rezchikov
2026-07-11 21:21:38 +03:00
parent 18161f4604
commit 4c42b5aa1d
20 changed files with 369 additions and 260 deletions
+27
View File
@@ -9,6 +9,8 @@ import { validatePage } from "./validation";
import { requireAdmin } from "../user/require";
import { runAction } from "../run-action";
import type { ActionResult } from "../action-result";
import { uploadImage, removeImage, getImageUrl } from "../image";
import { getBlocksByPageId } from "./repository";
export async function savePageAction(params: {
id: string | null,
@@ -52,7 +54,32 @@ export async function archivePageAction(id: string, slug: string, type: PageType
export async function deletePageAction(id: string, type: PageType): Promise<ActionResult> {
return runAction(async () => {
await requireAdmin();
const blocks = await getBlocksByPageId(id);
const imageKeys = blocks
.filter((b) => b.type === "IMAGE")
.map((b) => (b.content as { type: "IMAGE"; url: string }).url)
.filter(Boolean);
if (imageKeys.length) {
await Promise.allSettled(imageKeys.map(removeImage));
}
await deletePage(id);
revalidatePath(`/${type.toLowerCase()}`);
});
}
export async function uploadPageImage(file: File): Promise<string> {
await requireAdmin();
return uploadImage(file, "pages/images", { maxHeight: 800 });
}
export async function removePageImages(keys: string[]): Promise<void> {
await requireAdmin();
await Promise.allSettled(keys.map(removeImage));
}
export async function getImagePreviewUrl(key: string): Promise<string> {
return getImageUrl(key);
}