prod
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user