@morphika/webframe 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/admin/assets.ts +4 -0
- package/admin/database.ts +4 -0
- package/admin/index.ts +6 -0
- package/admin/login.ts +4 -0
- package/admin/navigation.ts +4 -0
- package/admin/pages-editor.ts +4 -0
- package/admin/pages.ts +4 -0
- package/admin/projects-editor.ts +4 -0
- package/admin/projects.ts +4 -0
- package/admin/settings.ts +4 -0
- package/admin/setup.ts +4 -0
- package/admin/storage.ts +4 -0
- package/admin/styles.ts +4 -0
- package/app/(site)/[slug]/loading.tsx +20 -0
- package/app/(site)/[slug]/page.tsx +83 -0
- package/app/(site)/error.tsx +32 -0
- package/app/(site)/layout.tsx +53 -0
- package/app/(site)/loading.tsx +20 -0
- package/app/(site)/not-found.tsx +41 -0
- package/app/(site)/page.tsx +43 -0
- package/app/(site)/preview/page.tsx +99 -0
- package/app/(site)/work/[slug]/loading.tsx +23 -0
- package/app/(site)/work/[slug]/page.tsx +84 -0
- package/app/admin/assets/page.tsx +573 -0
- package/app/admin/database/page.tsx +302 -0
- package/app/admin/error.tsx +53 -0
- package/app/admin/layout.tsx +273 -0
- package/app/admin/login/page.tsx +88 -0
- package/app/admin/navigation/page.tsx +157 -0
- package/app/admin/page.tsx +17 -0
- package/app/admin/pages/[slug]/page.tsx +849 -0
- package/app/admin/pages/page.tsx +588 -0
- package/app/admin/projects/[slug]/page.tsx +3 -0
- package/app/admin/projects/page.tsx +669 -0
- package/app/admin/settings/page.tsx +132 -0
- package/app/admin/setup/page.tsx +64 -0
- package/app/admin/storage/page.tsx +518 -0
- package/app/admin/styles/page.tsx +243 -0
- package/app/api/admin/assets/file/route.ts +81 -0
- package/app/api/admin/assets/health/route.ts +170 -0
- package/app/api/admin/assets/register/route.ts +163 -0
- package/app/api/admin/assets/registry/route.ts +98 -0
- package/app/api/admin/assets/relink/confirm/route.ts +242 -0
- package/app/api/admin/assets/relink/route.ts +202 -0
- package/app/api/admin/assets/scan/route.ts +271 -0
- package/app/api/admin/auth/route.ts +160 -0
- package/app/api/admin/custom-sections/[slug]/route.ts +159 -0
- package/app/api/admin/custom-sections/route.ts +127 -0
- package/app/api/admin/database/route.ts +53 -0
- package/app/api/admin/pages/[slug]/duplicate/route.ts +91 -0
- package/app/api/admin/pages/[slug]/route.ts +617 -0
- package/app/api/admin/pages/[slug]/set-home/route.ts +76 -0
- package/app/api/admin/pages/route.ts +129 -0
- package/app/api/admin/preview/route.ts +53 -0
- package/app/api/admin/r2/connect/route.ts +181 -0
- package/app/api/admin/r2/delete/route.ts +198 -0
- package/app/api/admin/r2/disconnect/route.ts +42 -0
- package/app/api/admin/r2/rename/route.ts +265 -0
- package/app/api/admin/r2/status/route.ts +106 -0
- package/app/api/admin/r2/upload-url/route.ts +148 -0
- package/app/api/admin/revalidate/route.ts +55 -0
- package/app/api/admin/settings/route.ts +279 -0
- package/app/api/admin/setup/complete/route.ts +51 -0
- package/app/api/admin/setup/route.ts +118 -0
- package/app/api/admin/storage/switch/route.ts +117 -0
- package/app/api/admin/styles/fonts/route.ts +97 -0
- package/app/api/admin/styles/route.ts +304 -0
- package/app/api/assets/[...path]/route.ts +98 -0
- package/app/api/custom-sections/[id]/route.ts +43 -0
- package/app/api/draft-mode/disable/route.ts +10 -0
- package/app/api/draft-mode/enable/route.ts +26 -0
- package/app/api/projects/route.ts +42 -0
- package/app/api/styles/route.ts +88 -0
- package/app/favicon.ico +0 -0
- package/app/globals.css +7 -0
- package/app/layout.tsx +53 -0
- package/app/robots.ts +17 -0
- package/app/sitemap.ts +48 -0
- package/app/studio/[[...index]]/page.tsx +8 -0
- package/components/admin/MetadataEditor.tsx +173 -0
- package/components/admin/PublishToggle.tsx +130 -0
- package/components/admin/icons.tsx +40 -0
- package/components/admin/nav-builder/NavBuilder.tsx +182 -0
- package/components/admin/nav-builder/NavBuilderGrid.tsx +326 -0
- package/components/admin/nav-builder/NavGeneralSettings.tsx +275 -0
- package/components/admin/nav-builder/NavGridCell.tsx +48 -0
- package/components/admin/nav-builder/NavGridItem.tsx +189 -0
- package/components/admin/nav-builder/NavItemSettings.tsx +288 -0
- package/components/admin/nav-builder/NavItemTypePicker.tsx +102 -0
- package/components/admin/nav-builder/NavLivePreview.tsx +125 -0
- package/components/admin/nav-builder/NavSettingsFields.tsx +248 -0
- package/components/admin/nav-builder/NavSettingsPanel.tsx +127 -0
- package/components/admin/nav-builder/index.ts +10 -0
- package/components/admin/nav-builder/nav-builder-utils.ts +238 -0
- package/components/admin/setup-wizard/BrandingStep.tsx +218 -0
- package/components/admin/setup-wizard/DatabaseStep.tsx +331 -0
- package/components/admin/setup-wizard/DoneStep.tsx +187 -0
- package/components/admin/setup-wizard/SetupWizard.tsx +166 -0
- package/components/admin/setup-wizard/StorageStep.tsx +308 -0
- package/components/admin/setup-wizard/WelcomeStep.tsx +96 -0
- package/components/admin/setup-wizard/index.ts +9 -0
- package/components/admin/styles/ColorsEditor.tsx +214 -0
- package/components/admin/styles/FontsEditor.tsx +258 -0
- package/components/admin/styles/GridLayoutEditor.tsx +292 -0
- package/components/admin/styles/LinksButtonsEditor.tsx +120 -0
- package/components/admin/styles/TypographyEditor.tsx +266 -0
- package/components/admin/styles/index.ts +9 -0
- package/components/admin/styles/shared.tsx +68 -0
- package/components/blocks/BlockRenderer.tsx +404 -0
- package/components/blocks/ButtonBlockRenderer.tsx +52 -0
- package/components/blocks/CoverBlockRenderer.tsx +239 -0
- package/components/blocks/CustomSectionInstanceRenderer.tsx +82 -0
- package/components/blocks/EnterAnimationWrapper.tsx +140 -0
- package/components/blocks/HoverAnimationWrapper.tsx +308 -0
- package/components/blocks/ImageBlockRenderer.tsx +61 -0
- package/components/blocks/ImageGridBlockRenderer.tsx +545 -0
- package/components/blocks/PageBackground.tsx +28 -0
- package/components/blocks/PageNavAnimation.tsx +35 -0
- package/components/blocks/PageNavColor.tsx +24 -0
- package/components/blocks/PageRenderer.tsx +142 -0
- package/components/blocks/ParallaxGroupRenderer.tsx +448 -0
- package/components/blocks/ParallaxSlideRenderer.tsx +175 -0
- package/components/blocks/ProjectGridBlockRenderer.tsx +556 -0
- package/components/blocks/SectionRenderer.tsx +170 -0
- package/components/blocks/SectionV2Renderer.tsx +330 -0
- package/components/blocks/ShaderCanvas.tsx +392 -0
- package/components/blocks/SpacerBlockRenderer.tsx +17 -0
- package/components/blocks/TextBlockRenderer.tsx +87 -0
- package/components/blocks/TypewriterRichText.tsx +464 -0
- package/components/blocks/TypewriterWrapper.tsx +149 -0
- package/components/blocks/VideoBlockRenderer.tsx +304 -0
- package/components/blocks/index.ts +2 -0
- package/components/builder/AssetBrowser.tsx +2 -0
- package/components/builder/BlockLivePreview.tsx +101 -0
- package/components/builder/BlockTypePicker.tsx +178 -0
- package/components/builder/BuilderCanvas.tsx +354 -0
- package/components/builder/CanvasMinimap.tsx +200 -0
- package/components/builder/CanvasToolbar.tsx +202 -0
- package/components/builder/ColorPicker.tsx +243 -0
- package/components/builder/ColorSwatchPicker.tsx +274 -0
- package/components/builder/ColumnDragContext.tsx +51 -0
- package/components/builder/ColumnDragOverlay.tsx +110 -0
- package/components/builder/CustomSectionInstanceCard.tsx +97 -0
- package/components/builder/DeviceFrame.tsx +123 -0
- package/components/builder/DndWrapper.tsx +337 -0
- package/components/builder/InsertionLines.tsx +186 -0
- package/components/builder/ParallaxGroupCanvas.tsx +228 -0
- package/components/builder/ParallaxSlideHeader.tsx +113 -0
- package/components/builder/ReadOnlyFrame.tsx +417 -0
- package/components/builder/SectionEditorBar.tsx +288 -0
- package/components/builder/SectionTypePicker.tsx +422 -0
- package/components/builder/SectionV2Canvas.tsx +297 -0
- package/components/builder/SectionV2Column.tsx +488 -0
- package/components/builder/SettingsPanel.tsx +911 -0
- package/components/builder/SortableBlock.tsx +230 -0
- package/components/builder/SortableRow.tsx +362 -0
- package/components/builder/VirtualAssetGrid.tsx +397 -0
- package/components/builder/asset-browser/AssetBrowser.tsx +178 -0
- package/components/builder/asset-browser/FileLightbox.tsx +116 -0
- package/components/builder/asset-browser/FolderTreeItem.tsx +55 -0
- package/components/builder/asset-browser/R2BrowserContent.tsx +436 -0
- package/components/builder/asset-browser/R2ContextMenu.tsx +98 -0
- package/components/builder/asset-browser/VideoThumbnail.tsx +63 -0
- package/components/builder/asset-browser/helpers.ts +88 -0
- package/components/builder/asset-browser/index.ts +1 -0
- package/components/builder/asset-browser/types.ts +49 -0
- package/components/builder/asset-browser/useAssetBrowser.ts +344 -0
- package/components/builder/asset-browser/useR2DragDrop.ts +116 -0
- package/components/builder/asset-browser/useR2Operations.ts +189 -0
- package/components/builder/blockStyles.tsx +295 -0
- package/components/builder/editors/ButtonBlockEditor.tsx +184 -0
- package/components/builder/editors/CoverBlockEditor.tsx +488 -0
- package/components/builder/editors/EnterAnimationPicker.tsx +297 -0
- package/components/builder/editors/HoverEffectPicker.tsx +209 -0
- package/components/builder/editors/ImageBlockEditor.tsx +206 -0
- package/components/builder/editors/ImageGridBlockEditor.tsx +386 -0
- package/components/builder/editors/ProjectGridEditor.tsx +648 -0
- package/components/builder/editors/SpacerBlockEditor.tsx +167 -0
- package/components/builder/editors/StaggerSettings.tsx +108 -0
- package/components/builder/editors/TextAlignmentIcons.tsx +39 -0
- package/components/builder/editors/TextBlockEditor.tsx +462 -0
- package/components/builder/editors/TextStylePicker.tsx +183 -0
- package/components/builder/editors/VideoBlockEditor.tsx +278 -0
- package/components/builder/editors/index.ts +10 -0
- package/components/builder/editors/shared.tsx +345 -0
- package/components/builder/hooks/useColumnDrag.ts +472 -0
- package/components/builder/hooks/useColumnResize.ts +221 -0
- package/components/builder/index.ts +12 -0
- package/components/builder/live-preview/LiveButtonPreview.tsx +38 -0
- package/components/builder/live-preview/LiveCoverPreview.tsx +146 -0
- package/components/builder/live-preview/LiveImageGridPreview.tsx +123 -0
- package/components/builder/live-preview/LiveImagePreview.tsx +107 -0
- package/components/builder/live-preview/LiveProjectGridPreview.tsx +1010 -0
- package/components/builder/live-preview/LiveSpacerPreview.tsx +9 -0
- package/components/builder/live-preview/LiveTextEditor.tsx +198 -0
- package/components/builder/live-preview/LiveVideoPreview.tsx +98 -0
- package/components/builder/live-preview/index.ts +10 -0
- package/components/builder/live-preview/shared.tsx +153 -0
- package/components/builder/settings-panel/BlockLayoutTab.tsx +532 -0
- package/components/builder/settings-panel/BlockSettings.tsx +94 -0
- package/components/builder/settings-panel/ColumnV2Settings.tsx +160 -0
- package/components/builder/settings-panel/LayoutTab.tsx +310 -0
- package/components/builder/settings-panel/PageSettings.tsx +200 -0
- package/components/builder/settings-panel/ParallaxGroupSettings.tsx +118 -0
- package/components/builder/settings-panel/ParallaxSlideSettings.tsx +178 -0
- package/components/builder/settings-panel/SectionV2AnimationTab.tsx +103 -0
- package/components/builder/settings-panel/SectionV2LayoutTab.tsx +312 -0
- package/components/builder/settings-panel/SectionV2Settings.tsx +323 -0
- package/components/builder/settings-panel/TRBLInputs.tsx +51 -0
- package/components/builder/settings-panel/index.ts +19 -0
- package/components/builder/settings-panel/responsive-helpers.ts +524 -0
- package/components/ui/CustomCursor.tsx +118 -0
- package/components/ui/NavContentLightbox.tsx +152 -0
- package/components/ui/Navbar.tsx +582 -0
- package/components/ui/PortfolioTracker.tsx +87 -0
- package/components/ui/ScrollToTop.tsx +47 -0
- package/lib/animation/enter-presets.ts +147 -0
- package/lib/animation/enter-resolve.ts +90 -0
- package/lib/animation/enter-types.ts +128 -0
- package/lib/animation/hover-effect-presets.ts +210 -0
- package/lib/animation/hover-effect-types.ts +126 -0
- package/lib/asset-retry.ts +111 -0
- package/lib/assets.ts +92 -0
- package/lib/audit.ts +35 -0
- package/lib/auth-token.ts +94 -0
- package/lib/auth.ts +13 -0
- package/lib/builder/cascade-helpers.ts +51 -0
- package/lib/builder/cascade.ts +533 -0
- package/lib/builder/constants.ts +103 -0
- package/lib/builder/defaults.ts +182 -0
- package/lib/builder/history.ts +48 -0
- package/lib/builder/index.ts +21 -0
- package/lib/builder/layout-styles.ts +344 -0
- package/lib/builder/masonry.ts +166 -0
- package/lib/builder/responsive.ts +156 -0
- package/lib/builder/serializer.ts +845 -0
- package/lib/builder/store-blocks.ts +193 -0
- package/lib/builder/store-canvas.ts +319 -0
- package/lib/builder/store-helpers.ts +490 -0
- package/lib/builder/store-sections.ts +709 -0
- package/lib/builder/store.ts +333 -0
- package/lib/builder/templates.ts +297 -0
- package/lib/builder/types.ts +374 -0
- package/lib/builder/utils.ts +37 -0
- package/lib/color-utils.ts +116 -0
- package/lib/config/index.ts +57 -0
- package/lib/config/types.ts +122 -0
- package/lib/contexts/AssetContext.tsx +79 -0
- package/lib/contexts/NavAnimationContext.tsx +44 -0
- package/lib/contexts/NavColorContext.tsx +38 -0
- package/lib/contexts/PageExitContext.tsx +194 -0
- package/lib/contexts/ThumbStatusContext.tsx +83 -0
- package/lib/csrf-client.ts +34 -0
- package/lib/csrf.ts +68 -0
- package/lib/format-utils.ts +24 -0
- package/lib/hooks/useViewport.ts +42 -0
- package/lib/logger.ts +81 -0
- package/lib/revalidate.ts +23 -0
- package/lib/sanitize.ts +91 -0
- package/lib/sanity/client.ts +8 -0
- package/lib/sanity/queries.ts +486 -0
- package/lib/sanity/types.ts +869 -0
- package/lib/sanity/writeClient.ts +24 -0
- package/lib/security.ts +402 -0
- package/lib/setup/detect.ts +156 -0
- package/lib/shader/glsl/index.ts +27 -0
- package/lib/shader/glsl/pixelate.ts +51 -0
- package/lib/shader/glsl/rgb-shift.ts +45 -0
- package/lib/shader/glsl/ripple.ts +46 -0
- package/lib/shader/glsl/vertex.ts +14 -0
- package/lib/storage/index.ts +211 -0
- package/lib/storage/r2-adapter.ts +286 -0
- package/lib/storage/types.ts +125 -0
- package/lib/styles/provider.tsx +267 -0
- package/lib/thumbnails/generate.ts +151 -0
- package/lib/utils.ts +6 -0
- package/package.json +212 -0
- package/sanity/compose.ts +65 -0
- package/sanity/sanity.config.ts +126 -0
- package/sanity/schemas/assetRegistry.ts +301 -0
- package/sanity/schemas/blocks/blockLayout.ts +90 -0
- package/sanity/schemas/blocks/buttonBlock.ts +82 -0
- package/sanity/schemas/blocks/coverBlock.ts +229 -0
- package/sanity/schemas/blocks/imageBlock.ts +58 -0
- package/sanity/schemas/blocks/imageGridBlock.ts +112 -0
- package/sanity/schemas/blocks/index.ts +9 -0
- package/sanity/schemas/blocks/projectGridBlock.ts +251 -0
- package/sanity/schemas/blocks/spacerBlock.ts +41 -0
- package/sanity/schemas/blocks/textBlock.ts +139 -0
- package/sanity/schemas/blocks/videoBlock.ts +80 -0
- package/sanity/schemas/customSection.ts +69 -0
- package/sanity/schemas/customSectionInstance.ts +163 -0
- package/sanity/schemas/index.ts +111 -0
- package/sanity/schemas/objects/enterAnimationConfig.ts +72 -0
- package/sanity/schemas/objects/hoverEffectConfig.ts +90 -0
- package/sanity/schemas/objects/parallaxGroup.ts +66 -0
- package/sanity/schemas/objects/parallaxSlide.ts +217 -0
- package/sanity/schemas/objects/typewriterConfig.ts +38 -0
- package/sanity/schemas/page.ts +162 -0
- package/sanity/schemas/pageSection.ts +157 -0
- package/sanity/schemas/pageSectionV2.ts +269 -0
- package/sanity/schemas/siteSettings.ts +256 -0
- package/sanity/schemas/siteStyles.ts +210 -0
- package/site/error.ts +4 -0
- package/site/index.ts +8 -0
- package/site/not-found.ts +4 -0
- package/site/page.ts +4 -0
- package/site/preview.ts +4 -0
- package/site/robots.ts +4 -0
- package/site/sitemap.ts +4 -0
- package/site/work.ts +4 -0
- package/studio/index.ts +4 -0
- package/styles/admin.css +85 -0
- package/styles/animations.css +237 -0
- package/styles/base.css +148 -0
- package/styles/globals.css +10 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { client } from "../../../../lib/sanity/client";
|
|
3
|
+
import { writeClient } from "../../../../lib/sanity/writeClient";
|
|
4
|
+
import { allCustomSectionsQuery } from "../../../../lib/sanity/queries";
|
|
5
|
+
import { isAdminAuthenticated } from "../../../../lib/auth";
|
|
6
|
+
import { validateCsrf, csrfErrorResponse } from "../../../../lib/csrf";
|
|
7
|
+
import { isBodyTooLarge, MAX_JSON_BODY_SIZE } from "../../../../lib/security";
|
|
8
|
+
import { auditLog } from "../../../../lib/audit";
|
|
9
|
+
import { logger } from "../../../../lib/logger";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* GET /api/admin/custom-sections — List all custom sections
|
|
13
|
+
*/
|
|
14
|
+
export async function GET() {
|
|
15
|
+
if (!(await isAdminAuthenticated())) {
|
|
16
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const sections = await client.fetch(allCustomSectionsQuery);
|
|
21
|
+
return NextResponse.json({ sections });
|
|
22
|
+
} catch (err) {
|
|
23
|
+
logger.error("[Admin:CustomSections]", "Failed to fetch custom sections", err);
|
|
24
|
+
return NextResponse.json(
|
|
25
|
+
{ error: "Failed to fetch custom sections" },
|
|
26
|
+
{ status: 500 }
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* POST /api/admin/custom-sections — Create a new custom section
|
|
33
|
+
* Body: { title, slug, description?, section }
|
|
34
|
+
*/
|
|
35
|
+
export async function POST(request: NextRequest) {
|
|
36
|
+
if (!(await isAdminAuthenticated())) {
|
|
37
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
38
|
+
}
|
|
39
|
+
if (!validateCsrf(request)) {
|
|
40
|
+
return csrfErrorResponse();
|
|
41
|
+
}
|
|
42
|
+
if (isBodyTooLarge(request, MAX_JSON_BODY_SIZE)) {
|
|
43
|
+
return NextResponse.json({ error: "Request body too large" }, { status: 413 });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const body = await request.json();
|
|
48
|
+
const { title, slug, description, section } = body;
|
|
49
|
+
|
|
50
|
+
// Validate required fields
|
|
51
|
+
if (!title || !slug) {
|
|
52
|
+
return NextResponse.json(
|
|
53
|
+
{ error: "Missing required fields: title, slug" },
|
|
54
|
+
{ status: 400 }
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Validate title length
|
|
59
|
+
if (typeof title === "string" && title.length > 200) {
|
|
60
|
+
return NextResponse.json(
|
|
61
|
+
{ error: "Title exceeds maximum length of 200 characters" },
|
|
62
|
+
{ status: 400 }
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Validate slug format
|
|
67
|
+
if (typeof slug !== "string" || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug)) {
|
|
68
|
+
return NextResponse.json(
|
|
69
|
+
{ error: "Slug must be lowercase alphanumeric with hyphens only" },
|
|
70
|
+
{ status: 400 }
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Check for duplicate slug
|
|
75
|
+
const existing = await client.fetch(
|
|
76
|
+
`*[_type == "customSection" && slug.current == $slug][0]._id`,
|
|
77
|
+
{ slug }
|
|
78
|
+
);
|
|
79
|
+
if (existing) {
|
|
80
|
+
return NextResponse.json(
|
|
81
|
+
{ error: "A custom section with this slug already exists" },
|
|
82
|
+
{ status: 409 }
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Build document
|
|
87
|
+
const doc = {
|
|
88
|
+
_type: "customSection",
|
|
89
|
+
title,
|
|
90
|
+
slug: { _type: "slug", current: slug },
|
|
91
|
+
...(description ? { description } : {}),
|
|
92
|
+
section: section || {
|
|
93
|
+
_type: "pageSectionV2",
|
|
94
|
+
section_type: "empty-v2",
|
|
95
|
+
columns: [],
|
|
96
|
+
settings: {
|
|
97
|
+
preset: "full",
|
|
98
|
+
grid_columns: 12,
|
|
99
|
+
col_gap: 20,
|
|
100
|
+
row_gap: 20,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
updated_at: new Date().toISOString(),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const created = await writeClient.create(doc);
|
|
107
|
+
|
|
108
|
+
auditLog("customSection.create", { slug, title });
|
|
109
|
+
|
|
110
|
+
return NextResponse.json(
|
|
111
|
+
{
|
|
112
|
+
section: {
|
|
113
|
+
_id: created._id,
|
|
114
|
+
title,
|
|
115
|
+
slug: { current: slug },
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{ status: 201 }
|
|
119
|
+
);
|
|
120
|
+
} catch (err) {
|
|
121
|
+
logger.error("[Admin:CustomSections]", "Failed to create custom section", err);
|
|
122
|
+
return NextResponse.json(
|
|
123
|
+
{ error: "Failed to create custom section" },
|
|
124
|
+
{ status: 500 }
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { isAdminAuthenticated } from "../../../../lib/auth";
|
|
3
|
+
import { client } from "../../../../lib/sanity/client";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET /api/admin/database — Sanity connection status & stats
|
|
7
|
+
* Returns project info, dataset, document counts, and connection health.
|
|
8
|
+
*/
|
|
9
|
+
export async function GET() {
|
|
10
|
+
const authenticated = await isAdminAuthenticated();
|
|
11
|
+
if (!authenticated) {
|
|
12
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID || "";
|
|
16
|
+
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET || "production";
|
|
17
|
+
const hasWriteToken = !!process.env.SANITY_API_TOKEN;
|
|
18
|
+
|
|
19
|
+
// Test connection + gather stats
|
|
20
|
+
try {
|
|
21
|
+
// Count documents by type — single GROQ query
|
|
22
|
+
const stats = await client.fetch(`{
|
|
23
|
+
"totalDocuments": count(*[!(_type match "system.*")]),
|
|
24
|
+
"pages": count(*[_type == "page"]),
|
|
25
|
+
"publishedPages": count(*[_type == "page" && is_published == true]),
|
|
26
|
+
"draftPages": count(*[_type == "page" && is_published != true]),
|
|
27
|
+
"projects": count(*[_type == "page" && page_type == "project"]),
|
|
28
|
+
"siteSettings": count(*[_type == "siteSettings"]),
|
|
29
|
+
"siteStyles": count(*[_type == "siteStyles"]),
|
|
30
|
+
"assetRegistry": count(*[_type == "assetRegistry"]),
|
|
31
|
+
"datasets": ["${dataset}"]
|
|
32
|
+
}`);
|
|
33
|
+
|
|
34
|
+
return NextResponse.json({
|
|
35
|
+
connected: true,
|
|
36
|
+
projectId,
|
|
37
|
+
dataset,
|
|
38
|
+
hasWriteToken,
|
|
39
|
+
stats,
|
|
40
|
+
apiVersion: "2024-01-01",
|
|
41
|
+
});
|
|
42
|
+
} catch (err) {
|
|
43
|
+
return NextResponse.json({
|
|
44
|
+
connected: false,
|
|
45
|
+
projectId,
|
|
46
|
+
dataset,
|
|
47
|
+
hasWriteToken,
|
|
48
|
+
error: "Connection failed",
|
|
49
|
+
stats: null,
|
|
50
|
+
apiVersion: "2024-01-01",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { revalidatePath } from "next/cache";
|
|
3
|
+
import { client } from "../../../../../../lib/sanity/client";
|
|
4
|
+
import { writeClient } from "../../../../../../lib/sanity/writeClient";
|
|
5
|
+
import { pageBySlugQuery } from "../../../../../../lib/sanity/queries";
|
|
6
|
+
import { isAdminAuthenticated } from "../../../../../../lib/auth";
|
|
7
|
+
import { validateCsrf, csrfErrorResponse } from "../../../../../../lib/csrf";
|
|
8
|
+
import { logger } from "../../../../../../lib/logger";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* POST /api/admin/pages/[slug]/duplicate — Duplicate a page
|
|
12
|
+
* Creates a copy with "(Copy)" appended to title and "-copy" to slug.
|
|
13
|
+
*/
|
|
14
|
+
export async function POST(
|
|
15
|
+
request: NextRequest,
|
|
16
|
+
{ params }: { params: Promise<{ slug: string }> }
|
|
17
|
+
) {
|
|
18
|
+
if (!(await isAdminAuthenticated())) {
|
|
19
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
20
|
+
}
|
|
21
|
+
if (!validateCsrf(request)) {
|
|
22
|
+
return csrfErrorResponse();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const { slug } = await params;
|
|
27
|
+
const page = await client.fetch(pageBySlugQuery, { slug });
|
|
28
|
+
|
|
29
|
+
if (!page) {
|
|
30
|
+
return NextResponse.json(
|
|
31
|
+
{ error: "Resource not found" },
|
|
32
|
+
{ status: 404 }
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Generate unique slug (with max iteration limit to prevent infinite loops)
|
|
37
|
+
let newSlug = `${slug}-copy`;
|
|
38
|
+
let suffix = 1;
|
|
39
|
+
const MAX_ITERATIONS = 100;
|
|
40
|
+
while (suffix <= MAX_ITERATIONS) {
|
|
41
|
+
const existing = await client.fetch(
|
|
42
|
+
`*[_type == "page" && slug.current == $slug][0]._id`,
|
|
43
|
+
{ slug: newSlug }
|
|
44
|
+
);
|
|
45
|
+
if (!existing) break;
|
|
46
|
+
suffix++;
|
|
47
|
+
newSlug = `${slug}-copy-${suffix}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (suffix > MAX_ITERATIONS) {
|
|
51
|
+
return NextResponse.json(
|
|
52
|
+
{ error: "Unable to generate unique slug. Please try a different base slug." },
|
|
53
|
+
{ status: 400 }
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Create duplicate document (never copy is_home — only one page can be home)
|
|
58
|
+
const duplicate = await writeClient.create({
|
|
59
|
+
_type: "page",
|
|
60
|
+
title: `${page.title} (Copy)`,
|
|
61
|
+
slug: { _type: "slug", current: newSlug },
|
|
62
|
+
page_type: page.page_type,
|
|
63
|
+
is_home: false,
|
|
64
|
+
content_rows: page.content_rows || [],
|
|
65
|
+
metadata: page.metadata || {},
|
|
66
|
+
draft_mode: true,
|
|
67
|
+
...(page.thumbnail_path ? { thumbnail_path: page.thumbnail_path } : {}),
|
|
68
|
+
...(page.page_settings ? { page_settings: page.page_settings } : {}),
|
|
69
|
+
...(page.published_at ? { published_at: page.published_at } : {}),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Revalidate layout so project grids/lists pick up the new page
|
|
73
|
+
revalidatePath("/", "layout");
|
|
74
|
+
|
|
75
|
+
return NextResponse.json({
|
|
76
|
+
success: true,
|
|
77
|
+
page: {
|
|
78
|
+
_id: duplicate._id,
|
|
79
|
+
title: duplicate.title,
|
|
80
|
+
slug: { current: newSlug },
|
|
81
|
+
page_type: page.page_type,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
} catch (err) {
|
|
85
|
+
logger.error("[Admin:Pages]", "Failed to duplicate page", err);
|
|
86
|
+
return NextResponse.json(
|
|
87
|
+
{ error: "Failed to duplicate page" },
|
|
88
|
+
{ status: 500 }
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|