@devvistatech/devvista-kit 0.0.1
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/CHANGELOG.md +13 -0
- package/LICENSE +7 -0
- package/README.md +15 -0
- package/app/about/page.tsx +306 -0
- package/app/adRequest/page.tsx +550 -0
- package/app/analytics/page.tsx +347 -0
- package/app/api/about/route.ts +307 -0
- package/app/api/adRequest/route.ts +568 -0
- package/app/api/analytics/[reportType]/route.ts +338 -0
- package/app/api/bio/route.ts +314 -0
- package/app/api/blog/route.ts +307 -0
- package/app/api/chat/route.ts +15 -0
- package/app/api/contact/route.ts +410 -0
- package/app/api/contacts/route.ts +225 -0
- package/app/api/files/route.ts +430 -0
- package/app/api/gallery-data/route.ts +661 -0
- package/app/api/schedule/route.ts +456 -0
- package/app/api/sync-user/route.ts +114 -0
- package/app/api/trial-request/route.ts +298 -0
- package/app/blog/[id]/page.tsx +281 -0
- package/app/blog/page.tsx +217 -0
- package/app/constants/about.ts +49 -0
- package/app/constants/adRequest.ts +114 -0
- package/app/constants/contact.ts +41 -0
- package/app/constants/faq.ts +46 -0
- package/app/constants/gallery.ts +43 -0
- package/app/constants/page.ts +70 -0
- package/app/constants/schedule.ts +72 -0
- package/app/contact/page.tsx +285 -0
- package/app/faq/page.tsx +192 -0
- package/app/favicon.ico +0 -0
- package/app/gallery/page.tsx +320 -0
- package/app/globals.css +58 -0
- package/app/layout.tsx +62 -0
- package/app/page.tsx +339 -0
- package/app/schedule/page.tsx +661 -0
- package/bin/init.js +187 -0
- package/components/addOns/functional/BioEditor.tsx +430 -0
- package/components/addOns/functional/CalendlyWidget.tsx +101 -0
- package/components/addOns/functional/ClassList.tsx +146 -0
- package/components/addOns/functional/ClassPopup.tsx +399 -0
- package/components/addOns/functional/ContactForm.tsx +285 -0
- package/components/addOns/functional/FileUploader.tsx +293 -0
- package/components/addOns/functional/ImageDescCarousel.tsx +821 -0
- package/components/addOns/functional/NewUserAnalytics.tsx +101 -0
- package/components/addOns/functional/ScheduleCarousel.tsx +172 -0
- package/components/addOns/functional/aboutSections/AboutSection.tsx +571 -0
- package/components/addOns/functional/aboutSections/constants/aboutSection.ts +66 -0
- package/components/addOns/functional/blogSections/BlogDashboard.tsx +185 -0
- package/components/addOns/functional/blogSections/BlogFormPopUp.tsx +555 -0
- package/components/addOns/functional/blogSections/BlogList.tsx +149 -0
- package/components/addOns/functional/blogSections/BlogSidebar.tsx +59 -0
- package/components/addOns/functional/blogSections/constants/blogDashboard.ts +29 -0
- package/components/addOns/functional/blogSections/constants/blogFormPopUp.ts +98 -0
- package/components/addOns/functional/blogSections/constants/blogList.ts +23 -0
- package/components/addOns/functional/blogSections/constants/blogSidebar.ts +16 -0
- package/components/addOns/functional/contactsDashboard/ContactsDashboard.tsx +348 -0
- package/components/addOns/functional/contactsDashboard/constants/contactsDashboard.ts +71 -0
- package/components/addOns/functional/galleries/GalleryComplex.tsx +908 -0
- package/components/addOns/functional/galleries/GallerySimple.tsx +604 -0
- package/components/addOns/functional/galleries/constants/galleryComplex.ts +105 -0
- package/components/addOns/functional/galleries/constants/gallerySimple.ts +75 -0
- package/components/addOns/functional/schedules/ScheduleGridOne.tsx +263 -0
- package/components/addOns/functional/schedules/ScheduleGridTwo.tsx +295 -0
- package/components/addOns/functional/schedules/ScheduleGridTwoBasic.tsx +289 -0
- package/components/addOns/functional/schedules/SchedulerForm.tsx +429 -0
- package/components/addOns/functional/schedules/constants/ScheduleGridTwo.ts +41 -0
- package/components/addOns/functional/schedules/constants/ScheduleGridTwoBasic.ts +41 -0
- package/components/addOns/functional/schedules/constants/SchedulerForm.ts +66 -0
- package/components/addOns/functional/schedules/constants/scheduleGridOne.ts +55 -0
- package/components/addOns/non-functional/AnnouncementBanner.tsx +47 -0
- package/components/addOns/non-functional/FeaturesSection.tsx +63 -0
- package/components/addOns/non-functional/HeroSection.tsx +143 -0
- package/components/addOns/non-functional/IconBubble.tsx +50 -0
- package/components/addOns/non-functional/SampleCarousel.tsx +205 -0
- package/components/addOns/non-functional/Testimonials.tsx +336 -0
- package/components/addOns/non-functional/ThreeSetGallery.tsx +64 -0
- package/components/addOns/non-functional/aboutSections/AboutSection.tsx +63 -0
- package/components/addOns/non-functional/aboutSections/constants/aboutSection.ts +25 -0
- package/components/addOns/non-functional/imageCarousels/ProductSlider.tsx +118 -0
- package/components/addOns/non-functional/imageCarousels/ProgramCarousel.tsx +233 -0
- package/components/addOns/non-functional/imageCarousels/constants/programCarousel.ts +40 -0
- package/components/addOns/non-functional/imageCarousels/constants/programSlider.ts +37 -0
- package/components/addOns/non-functional/spinner.tsx +22 -0
- package/components/footers/footer.tsx +454 -0
- package/components/navBars/navbar.tsx +311 -0
- package/components/other/accordion.tsx +58 -0
- package/components/other/admin-menu.tsx +69 -0
- package/components/other/alert-dialog.tsx +141 -0
- package/components/other/alert.tsx +59 -0
- package/components/other/aspect-ratio.tsx +7 -0
- package/components/other/avatar.tsx +50 -0
- package/components/other/badge.tsx +36 -0
- package/components/other/breadcrumb.tsx +115 -0
- package/components/other/button.tsx +733 -0
- package/components/other/calendar.tsx +66 -0
- package/components/other/card.tsx +86 -0
- package/components/other/carousel.tsx +275 -0
- package/components/other/chart.tsx +363 -0
- package/components/other/checkbox.tsx +30 -0
- package/components/other/collapsible.tsx +11 -0
- package/components/other/command.tsx +155 -0
- package/components/other/context-menu.tsx +200 -0
- package/components/other/dialog.tsx +122 -0
- package/components/other/drawer.tsx +118 -0
- package/components/other/dropdown-menu.tsx +200 -0
- package/components/other/form.tsx +179 -0
- package/components/other/hover-card.tsx +29 -0
- package/components/other/input-otp.tsx +71 -0
- package/components/other/input.tsx +25 -0
- package/components/other/label.tsx +26 -0
- package/components/other/login-popup.tsx +0 -0
- package/components/other/menubar.tsx +236 -0
- package/components/other/mobile-icon.tsx +22 -0
- package/components/other/navigation-menu.tsx +128 -0
- package/components/other/pagination.tsx +117 -0
- package/components/other/popover.tsx +31 -0
- package/components/other/progress.tsx +28 -0
- package/components/other/radio-group.tsx +44 -0
- package/components/other/resizable.tsx +45 -0
- package/components/other/scroll-area.tsx +48 -0
- package/components/other/select.tsx +160 -0
- package/components/other/separator.tsx +31 -0
- package/components/other/sheet.tsx +140 -0
- package/components/other/signup-popup.tsx +0 -0
- package/components/other/skeleton.tsx +15 -0
- package/components/other/slider.tsx +28 -0
- package/components/other/social-icons.tsx +40 -0
- package/components/other/sonner.tsx +31 -0
- package/components/other/switch.tsx +29 -0
- package/components/other/table.tsx +117 -0
- package/components/other/tabs.tsx +55 -0
- package/components/other/textarea.tsx +24 -0
- package/components/other/toast.tsx +123 -0
- package/components/other/toaster.tsx +35 -0
- package/components/other/toggle-group.tsx +61 -0
- package/components/other/toggle.tsx +45 -0
- package/components/other/tooltip.tsx +30 -0
- package/components/theme-provider.tsx +9 -0
- package/components/types.ts +22 -0
- package/dist/.next/types/app/api/about/route.js +52 -0
- package/dist/.next/types/app/api/blog/route.js +52 -0
- package/dist/.next/types/app/api/files/route.js +52 -0
- package/dist/.next/types/app/api/schedule/route.js +52 -0
- package/dist/.next/types/app/api/sync-user/route.js +52 -0
- package/dist/.next/types/app/layout.js +22 -0
- package/dist/.next/types/app/page.js +22 -0
- package/dist/app/about/page.jsx +259 -0
- package/dist/app/adRequest/page.jsx +531 -0
- package/dist/app/analytics/page.jsx +298 -0
- package/dist/app/api/about/route.js +285 -0
- package/dist/app/api/adRequest/route.js +440 -0
- package/dist/app/api/analytics/[reportType]/route.js +346 -0
- package/dist/app/api/bio/route.js +293 -0
- package/dist/app/api/blog/route.js +366 -0
- package/dist/app/api/chat/route.js +58 -0
- package/dist/app/api/contact/route.js +163 -0
- package/dist/app/api/contacts/route.js +234 -0
- package/dist/app/api/files/route.js +444 -0
- package/dist/app/api/gallery-data/route.js +642 -0
- package/dist/app/api/schedule/route.js +461 -0
- package/dist/app/api/sync-user/route.js +174 -0
- package/dist/app/api/trial-request/route.js +165 -0
- package/dist/app/blog/[id]/page.jsx +307 -0
- package/dist/app/blog/page.jsx +210 -0
- package/dist/app/constants/about.js +32 -0
- package/dist/app/constants/adRequest.js +113 -0
- package/dist/app/constants/contact.js +40 -0
- package/dist/app/constants/faq.js +36 -0
- package/dist/app/constants/gallery.js +42 -0
- package/dist/app/constants/page.js +69 -0
- package/dist/app/constants/schedule.js +71 -0
- package/dist/app/contact/page.jsx +119 -0
- package/dist/app/faq/page.jsx +97 -0
- package/dist/app/gallery/page.jsx +280 -0
- package/dist/app/layout.jsx +45 -0
- package/dist/app/page.jsx +324 -0
- package/dist/app/schedule/page.jsx +500 -0
- package/dist/components/addOns/functional/BioEditor.jsx +175 -0
- package/dist/components/addOns/functional/CalendlyWidget.jsx +61 -0
- package/dist/components/addOns/functional/ClassList.jsx +158 -0
- package/dist/components/addOns/functional/ClassPopup.jsx +300 -0
- package/dist/components/addOns/functional/ContactForm.jsx +219 -0
- package/dist/components/addOns/functional/FileUploader.jsx +222 -0
- package/dist/components/addOns/functional/ImageDescCarousel.jsx +464 -0
- package/dist/components/addOns/functional/NewUserAnalytics.jsx +71 -0
- package/dist/components/addOns/functional/ScheduleCarousel.jsx +68 -0
- package/dist/components/addOns/functional/aboutSections/AboutSection.jsx +369 -0
- package/dist/components/addOns/functional/aboutSections/constants/aboutSection.js +65 -0
- package/dist/components/addOns/functional/blogSections/BlogDashboard.jsx +111 -0
- package/dist/components/addOns/functional/blogSections/BlogFormPopUp.jsx +465 -0
- package/dist/components/addOns/functional/blogSections/BlogList.jsx +170 -0
- package/dist/components/addOns/functional/blogSections/BlogSidebar.jsx +35 -0
- package/dist/components/addOns/functional/blogSections/constants/blogDashboard.js +28 -0
- package/dist/components/addOns/functional/blogSections/constants/blogFormPopUp.js +97 -0
- package/dist/components/addOns/functional/blogSections/constants/blogList.js +22 -0
- package/dist/components/addOns/functional/blogSections/constants/blogSidebar.js +15 -0
- package/dist/components/addOns/functional/contactsDashboard/ContactsDashboard.jsx +323 -0
- package/dist/components/addOns/functional/contactsDashboard/constants/contactsDashboard.js +70 -0
- package/dist/components/addOns/functional/galleries/GalleryComplex.jsx +586 -0
- package/dist/components/addOns/functional/galleries/GallerySimple.jsx +385 -0
- package/dist/components/addOns/functional/galleries/constants/galleryComplex.js +104 -0
- package/dist/components/addOns/functional/galleries/constants/gallerySimple.js +74 -0
- package/dist/components/addOns/functional/schedules/ScheduleGridOne.jsx +167 -0
- package/dist/components/addOns/functional/schedules/ScheduleGridTwo.jsx +100 -0
- package/dist/components/addOns/functional/schedules/ScheduleGridTwoBasic.jsx +97 -0
- package/dist/components/addOns/functional/schedules/SchedulerForm.jsx +188 -0
- package/dist/components/addOns/functional/schedules/constants/ScheduleGridTwo.js +40 -0
- package/dist/components/addOns/functional/schedules/constants/ScheduleGridTwoBasic.js +40 -0
- package/dist/components/addOns/functional/schedules/constants/SchedulerForm.js +65 -0
- package/dist/components/addOns/functional/schedules/constants/scheduleGridOne.js +54 -0
- package/dist/components/addOns/non-functional/AnnouncementBanner.jsx +24 -0
- package/dist/components/addOns/non-functional/FeaturesSection.jsx +38 -0
- package/dist/components/addOns/non-functional/HeroSection.jsx +71 -0
- package/dist/components/addOns/non-functional/IconBubble.jsx +36 -0
- package/dist/components/addOns/non-functional/SampleCarousel.jsx +114 -0
- package/dist/components/addOns/non-functional/Testimonials.jsx +177 -0
- package/dist/components/addOns/non-functional/ThreeSetGallery.jsx +40 -0
- package/dist/components/addOns/non-functional/aboutSections/AboutSection.jsx +35 -0
- package/dist/components/addOns/non-functional/aboutSections/constants/aboutSection.js +24 -0
- package/dist/components/addOns/non-functional/imageCarousels/ProductSlider.jsx +80 -0
- package/dist/components/addOns/non-functional/imageCarousels/ProgramCarousel.jsx +155 -0
- package/dist/components/addOns/non-functional/imageCarousels/constants/programCarousel.js +39 -0
- package/dist/components/addOns/non-functional/imageCarousels/constants/programSlider.js +36 -0
- package/dist/components/addOns/non-functional/spinner.jsx +13 -0
- package/dist/components/footers/footer.jsx +219 -0
- package/dist/components/navBars/navbar.jsx +158 -0
- package/dist/components/other/accordion.jsx +40 -0
- package/dist/components/other/admin-menu.jsx +34 -0
- package/dist/components/other/alert-dialog.jsx +64 -0
- package/dist/components/other/alert.jsx +41 -0
- package/dist/components/other/aspect-ratio.jsx +4 -0
- package/dist/components/other/avatar.jsx +31 -0
- package/dist/components/other/badge.jsx +32 -0
- package/dist/components/other/breadcrumb.jsx +57 -0
- package/dist/components/other/button.jsx +321 -0
- package/dist/components/other/calendar.jsx +43 -0
- package/dist/components/other/card.jsx +44 -0
- package/dist/components/other/carousel.jsx +140 -0
- package/dist/components/other/chart.jsx +182 -0
- package/dist/components/other/checkbox.jsx +26 -0
- package/dist/components/other/collapsible.jsx +6 -0
- package/dist/components/other/command.jsx +68 -0
- package/dist/components/other/context-menu.jsx +88 -0
- package/dist/components/other/dialog.jsx +60 -0
- package/dist/components/other/drawer.jsx +60 -0
- package/dist/components/other/dropdown-menu.jsx +90 -0
- package/dist/components/other/form.jsx +89 -0
- package/dist/components/other/hover-card.jsx +23 -0
- package/dist/components/other/input-otp.jsx +46 -0
- package/dist/components/other/input.jsx +19 -0
- package/dist/components/other/label.jsx +23 -0
- package/dist/components/other/login-popup.jsx +1 -0
- package/dist/components/other/menubar.jsx +96 -0
- package/dist/components/other/mobile-icon.jsx +11 -0
- package/dist/components/other/navigation-menu.jsx +62 -0
- package/dist/components/other/pagination.jsx +63 -0
- package/dist/components/other/popover.jsx +25 -0
- package/dist/components/other/progress.jsx +23 -0
- package/dist/components/other/radio-group.jsx +31 -0
- package/dist/components/other/resizable.jsx +29 -0
- package/dist/components/other/scroll-area.jsx +36 -0
- package/dist/components/other/select.jsx +83 -0
- package/dist/components/other/separator.jsx +21 -0
- package/dist/components/other/sheet.jsx +74 -0
- package/dist/components/other/signup-popup.jsx +1 -0
- package/dist/components/other/skeleton.jsx +17 -0
- package/dist/components/other/slider.jsx +26 -0
- package/dist/components/other/social-icons.jsx +15 -0
- package/dist/components/other/sonner.jsx +27 -0
- package/dist/components/other/switch.jsx +23 -0
- package/dist/components/other/table.jsx +56 -0
- package/dist/components/other/tabs.jsx +32 -0
- package/dist/components/other/textarea.jsx +19 -0
- package/dist/components/other/toast.jsx +58 -0
- package/dist/components/other/toaster.jsx +31 -0
- package/dist/components/other/toggle-group.jsx +41 -0
- package/dist/components/other/toggle.jsx +39 -0
- package/dist/components/other/tooltip.jsx +24 -0
- package/dist/components/theme-provider.jsx +18 -0
- package/dist/components/types.js +1 -0
- package/dist/hooks/use-toast.js +135 -0
- package/dist/lib/auth-context.jsx +144 -0
- package/dist/lib/google-analytics.jsx +148 -0
- package/dist/lib/utils.js +9 -0
- package/dist/lib/verify-user.js +142 -0
- package/dist/middleware.js +32 -0
- package/dist/tailwind.config.js +86 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/hooks/use-toast.ts +188 -0
- package/lib/auth-context.tsx +131 -0
- package/lib/google-analytics.tsx +98 -0
- package/lib/utils.ts +6 -0
- package/lib/verify-user.ts +118 -0
- package/middleware.ts +35 -0
- package/next.config.js +10 -0
- package/package.json +116 -0
- package/postcss.config.js +6 -0
- package/public/images/FitStop.png +0 -0
- package/public/images/classes/bodyblast.JPG +0 -0
- package/public/images/classes/cardioxtrain.JPG +0 -0
- package/public/images/classes/combo.JPG +0 -0
- package/public/images/classes/flexiblefriday.JPG +0 -0
- package/public/images/classes/freestyle.jpg +0 -0
- package/public/images/classes/noclasses.jpg +0 -0
- package/public/images/classes/seniorstretch.JPG +0 -0
- package/public/images/classes/stretch.JPG +0 -0
- package/public/images/classes/zoomba.JPG +0 -0
- package/public/images/fitstoproom1.jpg +0 -0
- package/public/images/fitstoproom2.jpg +0 -0
- package/public/images/gallery/021-1024x768.jpg +0 -0
- package/public/images/gallery/023-1024x768.jpg +0 -0
- package/public/images/gallery/027-1024x768.jpg +0 -0
- package/public/images/gallery/029-1024x768.jpg +0 -0
- package/public/images/gallery/030-1024x768.jpg +0 -0
- package/public/images/gallery/042-1024x768.jpg +0 -0
- package/public/images/gallery/049-1024x768.jpg +0 -0
- package/public/images/gallery/073-1024x768.jpg +0 -0
- package/public/images/gallery/108-300x225.jpg +0 -0
- package/public/images/gallery/109-300x225.jpg +0 -0
- package/public/images/gallery/116.jpg +0 -0
- package/public/images/gallery/123-1-1024x768.jpg +0 -0
- package/public/images/gallery/133.jpg +0 -0
- package/public/images/gallery/142-1.jpg +0 -0
- package/public/images/gallery/143.jpg +0 -0
- package/public/images/gallery/145-1-1024x768.jpg +0 -0
- package/public/images/gallery/151-1024x768.jpg +0 -0
- package/public/images/gallery/166-300x225.jpg +0 -0
- package/public/images/gallery/175.jpg +0 -0
- package/public/images/gallery/183-1024x768.jpg +0 -0
- package/public/images/gallery/311.JPG +0 -0
- package/public/images/gallery/413-1.jpg +0 -0
- package/public/images/gallery/Cathys-Fit-Stop-Holiday-Party-0003-1024x683.jpg +0 -0
- package/public/images/gallery/Cathys-Fit-Stop-Holiday-Party-0076-1024x683.jpg +0 -0
- package/public/images/gallery/Cathys-Fit-Stop-Holiday-Party-0171-1024x683.jpg +0 -0
- package/public/images/gallery/DSCN0233-1024x768.jpg +0 -0
- package/public/images/gallery/DSCN0245-1-1024x768.jpg +0 -0
- package/public/images/gallery/Fitstopgirls2.jpg +0 -0
- package/public/images/gallery/GrandOpening2009.JPG +0 -0
- package/public/images/gallery/IMG_1937.JPG +0 -0
- package/public/images/gallery/IMG_1950-20.jpg +0 -0
- package/public/images/gallery/IMG_2112.JPG +0 -0
- package/public/images/gallery/IMG_2229.JPG +0 -0
- package/public/images/gallery/IMG_2272.JPG +0 -0
- package/public/images/gallery/IMG_2336.JPG +0 -0
- package/public/images/gallery/IMG_2367.JPG +0 -0
- package/public/images/gallery/IMG_2520.jpg +0 -0
- package/public/images/gallery/IMG_2564.jpg +0 -0
- package/public/images/gallery/IMG_3678.jpg +0 -0
- package/public/images/gallery/IMG_3744.jpg +0 -0
- package/public/images/gallery/IMG_3745.jpg +0 -0
- package/public/images/gallery/IMG_6383.jpg +0 -0
- package/public/images/gallery/Jillian-8-Months-2338-1024x683.jpg +0 -0
- package/public/images/gallery/Kathys-Fit-Stop-0032-1024x675.jpg +0 -0
- package/public/images/gallery/LaurieinPlank.jpeg +0 -0
- package/public/images/gallery/May2017032.JPG +0 -0
- package/public/images/gallery/clubpic10.jpg +0 -0
- package/public/images/gallery/clubpic15.jpg +0 -0
- package/public/images/gallery/clubpic2.jpg +0 -0
- package/public/images/gallery/clubpic3.jpg +0 -0
- package/public/images/gallery/clubpic4.jpg +0 -0
- package/public/images/gallery/clubpic5.jpg +0 -0
- package/public/images/gallery/clubpic6.jpg +0 -0
- package/public/images/gallery/clubpic7.jpg +0 -0
- package/public/images/gallery/clubpic8.jpg +0 -0
- package/public/images/gallery/clubpic9.jpg +0 -0
- package/public/images/gallery/z014-1024x768.jpg +0 -0
- package/public/images/gallery/z019-1-1024x768.jpg +0 -0
- package/public/images/kathy_faq-300x132.jpg +0 -0
- package/public/images/kathyportrait.jpg +0 -0
- package/public/images/kristiportrait.jpg +0 -0
- package/public/images/maincoverbackground.JPG +0 -0
- package/public/images/videos/FitStopLoopVideo.mp4 +0 -0
- package/public/images/weights.jpg +0 -0
- package/public/pdf/FitStop-Forum-April-2025.pdf +0 -0
- package/tailwind.config.ts +89 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
// app/api/gallery-data/route.ts
|
|
2
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
3
|
+
import { getAuth } from "@clerk/nextjs/server";
|
|
4
|
+
|
|
5
|
+
export const revalidate = 0;
|
|
6
|
+
|
|
7
|
+
interface StrapiUser {
|
|
8
|
+
id: number;
|
|
9
|
+
username: string;
|
|
10
|
+
email: string;
|
|
11
|
+
authId: string;
|
|
12
|
+
authProvider: string;
|
|
13
|
+
businessAdminId?: string;
|
|
14
|
+
userRole?: string;
|
|
15
|
+
firstName?: string;
|
|
16
|
+
lastName?: string;
|
|
17
|
+
businessId?: string[] | null;
|
|
18
|
+
dateJoined?: string;
|
|
19
|
+
businessOwner?: boolean;
|
|
20
|
+
userStatus?: string;
|
|
21
|
+
timezone?: string | null;
|
|
22
|
+
language?: string | null;
|
|
23
|
+
isVerified?: boolean;
|
|
24
|
+
businessTitle?: string | null;
|
|
25
|
+
userTitle?: string | null;
|
|
26
|
+
number?: string | null;
|
|
27
|
+
address?: {
|
|
28
|
+
zip: string;
|
|
29
|
+
city: string;
|
|
30
|
+
state: string;
|
|
31
|
+
street: string;
|
|
32
|
+
country: string;
|
|
33
|
+
} | null;
|
|
34
|
+
websiteUrl?: string | null;
|
|
35
|
+
primaryBusinessColor?: string | null;
|
|
36
|
+
secondaryBusinessColor?: string | null;
|
|
37
|
+
logoImage?: string | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface UploadedImage {
|
|
41
|
+
id: number;
|
|
42
|
+
documentId: string;
|
|
43
|
+
title?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
url: string;
|
|
46
|
+
createdAt: string;
|
|
47
|
+
category?: "none" | "indoor" | "outdoor" | "commercial";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const CONTENT_API_URL = process.env.STRAPI_CONTENT_API_URL || "";
|
|
51
|
+
const BASE_URL = process.env.STRAPI_API_URL || "";
|
|
52
|
+
const UPLOAD_API_URL = `${BASE_URL}/api/upload`;
|
|
53
|
+
const STRAPI_API_TOKEN = process.env.STRAPI_API_TOKEN || "";
|
|
54
|
+
const STRAPI_USER_LIST_API_URL = process.env.STRAPI_USER_LIST_API_URL || "";
|
|
55
|
+
const ADMIN_BUSINESS_ID = process.env.ADMIN_BUSINESS_ID || "";
|
|
56
|
+
|
|
57
|
+
async function verifyUser(request: NextRequest): Promise<StrapiUser | null> {
|
|
58
|
+
const { userId } = getAuth(request);
|
|
59
|
+
|
|
60
|
+
if (!userId) {
|
|
61
|
+
console.error("verifyUser: No userId found in request");
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
if (!STRAPI_USER_LIST_API_URL || !STRAPI_API_TOKEN) {
|
|
67
|
+
console.error("verifyUser: Missing environment variables", {
|
|
68
|
+
STRAPI_USER_LIST_API_URL,
|
|
69
|
+
STRAPI_API_TOKEN: !!STRAPI_API_TOKEN,
|
|
70
|
+
});
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const response = await fetch(
|
|
75
|
+
`${STRAPI_USER_LIST_API_URL}?filters[authId][$eq]=${userId}&populate=*`,
|
|
76
|
+
{
|
|
77
|
+
headers: {
|
|
78
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
},
|
|
81
|
+
cache: "no-store",
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
const errorText = await response.text();
|
|
87
|
+
console.error("verifyUser failed:", { status: response.status, errorText });
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const userData = await response.json();
|
|
92
|
+
|
|
93
|
+
if (!userData || !Array.isArray(userData.data) || userData.data.length === 0) {
|
|
94
|
+
console.error("verifyUser: No user found or invalid response for authId:", {
|
|
95
|
+
userId,
|
|
96
|
+
data: userData,
|
|
97
|
+
});
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const strapiUser = userData.data.find((user: any) => user.authId === userId);
|
|
102
|
+
|
|
103
|
+
if (!strapiUser) {
|
|
104
|
+
console.error("verifyUser: No user found for authId", { userId });
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
id: strapiUser.id,
|
|
110
|
+
username: strapiUser.username || "Unknown",
|
|
111
|
+
email: strapiUser.email || "",
|
|
112
|
+
authId: strapiUser.authId,
|
|
113
|
+
authProvider: strapiUser.authProvider,
|
|
114
|
+
businessAdminId: strapiUser.businessAdminId,
|
|
115
|
+
userRole: strapiUser.userRole,
|
|
116
|
+
firstName: strapiUser.firstName,
|
|
117
|
+
lastName: strapiUser.lastName,
|
|
118
|
+
businessId: strapiUser.businessId,
|
|
119
|
+
dateJoined: strapiUser.dateJoined,
|
|
120
|
+
businessOwner: strapiUser.businessOwner,
|
|
121
|
+
userStatus: strapiUser.userStatus,
|
|
122
|
+
timezone: strapiUser.timezone,
|
|
123
|
+
language: strapiUser.language,
|
|
124
|
+
isVerified: strapiUser.isVerified,
|
|
125
|
+
businessTitle: strapiUser.businessTitle,
|
|
126
|
+
userTitle: strapiUser.userTitle,
|
|
127
|
+
number: strapiUser.number,
|
|
128
|
+
address: strapiUser.address,
|
|
129
|
+
websiteUrl: strapiUser.websiteUrl,
|
|
130
|
+
primaryBusinessColor: strapiUser.primaryBusinessColor,
|
|
131
|
+
secondaryBusinessColor: strapiUser.secondaryBusinessColor,
|
|
132
|
+
logoImage: strapiUser.logoImage,
|
|
133
|
+
};
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error("verifyUser error:", error);
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function GET(request: NextRequest) {
|
|
141
|
+
try {
|
|
142
|
+
if (!CONTENT_API_URL || !STRAPI_API_TOKEN) {
|
|
143
|
+
console.error(
|
|
144
|
+
"Missing environment variables:",
|
|
145
|
+
!CONTENT_API_URL && "STRAPI_CONTENT_API_URL",
|
|
146
|
+
!STRAPI_API_TOKEN && "STRAPI_API_TOKEN"
|
|
147
|
+
);
|
|
148
|
+
return NextResponse.json(
|
|
149
|
+
{ error: "Server configuration error: Missing required environment variables" },
|
|
150
|
+
{ status: 500 }
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const response = await fetch(
|
|
155
|
+
`${CONTENT_API_URL}?publicationState=live&populate=image&fields[0]=title&fields[1]=description&fields[2]=createdAt&fields[3]=category&pagination[pageSize]=100&t=${Date.now()}`,
|
|
156
|
+
{
|
|
157
|
+
headers: {
|
|
158
|
+
"Content-Type": "application/json",
|
|
159
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
160
|
+
},
|
|
161
|
+
cache: "no-store",
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
if (!response.ok) {
|
|
166
|
+
const errorText = await response.text();
|
|
167
|
+
console.error("GET /api/gallery-data: Fetch images failed:", { status: response.status, errorText });
|
|
168
|
+
return NextResponse.json(
|
|
169
|
+
{ error: `Failed to fetch images: ${errorText}` },
|
|
170
|
+
{ status: response.status }
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const result = await response.json();
|
|
175
|
+
let allImages = result.data;
|
|
176
|
+
|
|
177
|
+
if (result.meta?.pagination?.total > 100) {
|
|
178
|
+
const totalPages = result.meta.pagination.pageCount;
|
|
179
|
+
for (let page = 2; page <= totalPages; page++) {
|
|
180
|
+
const nextPageResponse = await fetch(
|
|
181
|
+
`${CONTENT_API_URL}?publicationState=live&populate=image&fields[0]=title&fields[1]=description&fields[2]=createdAt&fields[3]=category&pagination[page]=${page}&pagination[pageSize]=100&t=${Date.now()}`,
|
|
182
|
+
{
|
|
183
|
+
headers: {
|
|
184
|
+
"Content-Type": "application/json",
|
|
185
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
186
|
+
},
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
const nextPageResult = await nextPageResponse.json();
|
|
190
|
+
allImages = [...allImages, ...nextPageResult.data];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const images: UploadedImage[] = allImages
|
|
195
|
+
.map((item: any) => {
|
|
196
|
+
const image = item.image;
|
|
197
|
+
if (!image || !image.url) {
|
|
198
|
+
console.warn(`Image missing for item ${item.id}:`, JSON.stringify(item, null, 2));
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
const rawUrl = image.url || "";
|
|
202
|
+
const imageUrl = rawUrl.startsWith("http") ? rawUrl : `${BASE_URL}${rawUrl}`;
|
|
203
|
+
return {
|
|
204
|
+
id: item.id,
|
|
205
|
+
documentId: item.documentId,
|
|
206
|
+
title: item.title || "",
|
|
207
|
+
description: item.description || "",
|
|
208
|
+
url: imageUrl,
|
|
209
|
+
createdAt: item.createdAt,
|
|
210
|
+
category: item.category || "none",
|
|
211
|
+
};
|
|
212
|
+
})
|
|
213
|
+
.filter((image: UploadedImage | null): image is UploadedImage => image !== null)
|
|
214
|
+
.sort((a: UploadedImage, b: UploadedImage) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
215
|
+
|
|
216
|
+
return NextResponse.json({
|
|
217
|
+
data: images,
|
|
218
|
+
meta: result.meta,
|
|
219
|
+
});
|
|
220
|
+
} catch (error) {
|
|
221
|
+
console.error("GET /api/gallery-data: Error:", error);
|
|
222
|
+
return NextResponse.json(
|
|
223
|
+
{ error: error instanceof Error ? error.message : "An error occurred while fetching images" },
|
|
224
|
+
{ status: 500 }
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export async function POST(request: NextRequest) {
|
|
230
|
+
const { userId } = getAuth(request);
|
|
231
|
+
if (!userId) {
|
|
232
|
+
console.error("POST /api/gallery-data: No userId, returning 401");
|
|
233
|
+
return NextResponse.json({ error: "Unauthorized: No user ID" }, { status: 401 });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const user = await verifyUser(request);
|
|
237
|
+
|
|
238
|
+
if (!user || user.businessAdminId !== ADMIN_BUSINESS_ID || user.userRole !== "admin") {
|
|
239
|
+
console.error("POST /api/gallery-data: Unauthorized access attempt", {
|
|
240
|
+
authId: user?.authId,
|
|
241
|
+
businessAdminId: user?.businessAdminId,
|
|
242
|
+
envBusinessAdminId: ADMIN_BUSINESS_ID,
|
|
243
|
+
userRole: user?.userRole,
|
|
244
|
+
});
|
|
245
|
+
return NextResponse.json({ error: "Unauthorized: Only admins can upload images" }, { status: 403 });
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
if (!CONTENT_API_URL || !UPLOAD_API_URL || !STRAPI_API_TOKEN) {
|
|
250
|
+
console.error(
|
|
251
|
+
"Missing environment variables:",
|
|
252
|
+
!CONTENT_API_URL && "STRAPI_CONTENT_API_URL",
|
|
253
|
+
!UPLOAD_API_URL && "UPLOAD_API_URL",
|
|
254
|
+
!STRAPI_API_TOKEN && "STRAPI_API_TOKEN"
|
|
255
|
+
);
|
|
256
|
+
return NextResponse.json(
|
|
257
|
+
{ error: "Server configuration error: Missing required environment variables" },
|
|
258
|
+
{ status: 500 }
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const formData = await request.formData();
|
|
263
|
+
const file = formData.get("file") as File | null;
|
|
264
|
+
const title = formData.get("title") as string | null;
|
|
265
|
+
const description = formData.get("description") as string | null;
|
|
266
|
+
const category = formData.get("category") as UploadedImage["category"] | null;
|
|
267
|
+
|
|
268
|
+
if (!file) {
|
|
269
|
+
console.error("POST /api/gallery-data: No file provided");
|
|
270
|
+
return NextResponse.json({ error: "No file provided" }, { status: 400 });
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (!["image/jpeg", "image/png", "image/gif"].includes(file.type)) {
|
|
274
|
+
console.error("POST /api/gallery-data: Invalid file type", { fileType: file.type });
|
|
275
|
+
return NextResponse.json({ error: "Only JPEG, PNG, or GIF images are allowed" }, { status: 400 });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const validCategory = category && ["none", "indoor", "outdoor", "commercial"].includes(category) ? category : "none";
|
|
279
|
+
|
|
280
|
+
const uploadFormData = new FormData();
|
|
281
|
+
uploadFormData.append("files", file);
|
|
282
|
+
|
|
283
|
+
const uploadResponse = await fetch(UPLOAD_API_URL, {
|
|
284
|
+
method: "POST",
|
|
285
|
+
headers: {
|
|
286
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
287
|
+
},
|
|
288
|
+
body: uploadFormData,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
if (!uploadResponse.ok) {
|
|
292
|
+
const errorText = await uploadResponse.text();
|
|
293
|
+
console.error("POST /api/gallery-data: Upload failed:", { status: uploadResponse.status, errorText });
|
|
294
|
+
return NextResponse.json(
|
|
295
|
+
{ error: `Failed to upload image: ${errorText}` },
|
|
296
|
+
{ status: uploadResponse.status }
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const uploadResult = await uploadResponse.json();
|
|
301
|
+
const uploadedFileId = uploadResult[0]?.id;
|
|
302
|
+
const uploadedFileUrl = uploadResult[0]?.url;
|
|
303
|
+
if (!uploadedFileId || !uploadedFileUrl) {
|
|
304
|
+
console.error("POST /api/gallery-data: Invalid upload response", { uploadResult });
|
|
305
|
+
return NextResponse.json({ error: "Invalid upload response" }, { status: 500 });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const payload = {
|
|
309
|
+
data: {
|
|
310
|
+
image: uploadedFileId,
|
|
311
|
+
title: title || `Image ${new Date().toISOString()}`,
|
|
312
|
+
description: description || "",
|
|
313
|
+
category: validCategory,
|
|
314
|
+
publishedAt: new Date().toISOString(),
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const createResponse = await fetch(CONTENT_API_URL, {
|
|
319
|
+
method: "POST",
|
|
320
|
+
headers: {
|
|
321
|
+
"Content-Type": "application/json",
|
|
322
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
323
|
+
},
|
|
324
|
+
body: JSON.stringify(payload),
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
if (!createResponse.ok) {
|
|
328
|
+
const errorData = await createResponse.json();
|
|
329
|
+
let errorMessage = `Failed to create content entry: ${createResponse.status} - ${errorData.error?.message || "Unknown error"}`;
|
|
330
|
+
if (errorData.error?.details) {
|
|
331
|
+
errorMessage += `\nDetails: ${JSON.stringify(errorData.error.details, null, 2)}`;
|
|
332
|
+
}
|
|
333
|
+
console.error("POST /api/gallery-data: Create content failed", { errorMessage });
|
|
334
|
+
return NextResponse.json({ error: errorMessage }, { status: createResponse.status });
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const filesResponse = await fetch(
|
|
338
|
+
`${CONTENT_API_URL}?publicationState=live&populate=image&fields[0]=title&fields[1]=description&fields[2]=createdAt&fields[3]=category&pagination[pageSize]=100&t=${Date.now()}`,
|
|
339
|
+
{
|
|
340
|
+
headers: {
|
|
341
|
+
"Content-Type": "application/json",
|
|
342
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
343
|
+
},
|
|
344
|
+
cache: "no-store",
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
if (!filesResponse.ok) {
|
|
349
|
+
const errorText = await filesResponse.text();
|
|
350
|
+
console.error("POST /api/gallery-data: Refetch images failed:", { status: filesResponse.status, errorText });
|
|
351
|
+
return NextResponse.json(
|
|
352
|
+
{ error: `Failed to refetch images: ${errorText}` },
|
|
353
|
+
{ status: filesResponse.status }
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const filesResult = await filesResponse.json();
|
|
358
|
+
const images: UploadedImage[] = filesResult.data
|
|
359
|
+
.map((item: any) => {
|
|
360
|
+
const image = item.image;
|
|
361
|
+
if (!image || !image.url) {
|
|
362
|
+
console.warn(`Image missing for item ${item.id}:`, JSON.stringify(item, null, 2));
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
const rawUrl = image.url || "";
|
|
366
|
+
const imageUrl = rawUrl.startsWith("http") ? rawUrl : `${BASE_URL}${rawUrl}`;
|
|
367
|
+
return {
|
|
368
|
+
id: item.id,
|
|
369
|
+
documentId: item.documentId,
|
|
370
|
+
title: item.title || "",
|
|
371
|
+
description: item.description || "",
|
|
372
|
+
url: imageUrl,
|
|
373
|
+
createdAt: item.createdAt,
|
|
374
|
+
category: item.category || "none",
|
|
375
|
+
};
|
|
376
|
+
})
|
|
377
|
+
.filter((image: UploadedImage | null): image is UploadedImage => image !== null)
|
|
378
|
+
.sort((a: UploadedImage, b: UploadedImage) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
379
|
+
|
|
380
|
+
return NextResponse.json({
|
|
381
|
+
data: images,
|
|
382
|
+
meta: filesResult.meta,
|
|
383
|
+
newImageUrl: uploadedFileUrl,
|
|
384
|
+
});
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.error("POST /api/gallery-data: Error:", error);
|
|
387
|
+
return NextResponse.json(
|
|
388
|
+
{ error: error instanceof Error ? error.message : "Failed to upload image" },
|
|
389
|
+
{ status: 500 }
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export async function PUT(request: NextRequest) {
|
|
395
|
+
const { userId } = getAuth(request);
|
|
396
|
+
if (!userId) {
|
|
397
|
+
console.error("PUT /api/gallery-data: No userId, returning 401");
|
|
398
|
+
return NextResponse.json({ error: "Unauthorized: No user ID" }, { status: 401 });
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const user = await verifyUser(request);
|
|
402
|
+
|
|
403
|
+
if (!user || user.businessAdminId !== ADMIN_BUSINESS_ID || user.userRole !== "admin") {
|
|
404
|
+
console.error("PUT /api/gallery-data: Unauthorized access attempt", {
|
|
405
|
+
authId: user?.authId,
|
|
406
|
+
businessAdminId: user?.businessAdminId,
|
|
407
|
+
envBusinessAdminId: ADMIN_BUSINESS_ID,
|
|
408
|
+
userRole: user?.userRole,
|
|
409
|
+
});
|
|
410
|
+
return NextResponse.json({ error: "Unauthorized: Only admins can edit images" }, { status: 403 });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
try {
|
|
414
|
+
if (!CONTENT_API_URL || !STRAPI_API_TOKEN) {
|
|
415
|
+
console.error(
|
|
416
|
+
"Missing environment variables:",
|
|
417
|
+
!CONTENT_API_URL && "STRAPI_CONTENT_API_URL",
|
|
418
|
+
!STRAPI_API_TOKEN && "STRAPI_API_TOKEN"
|
|
419
|
+
);
|
|
420
|
+
return NextResponse.json(
|
|
421
|
+
{ error: "Server configuration error: Missing required environment variables" },
|
|
422
|
+
{ status: 500 }
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const { documentId, title, description, category } = await request.json();
|
|
427
|
+
|
|
428
|
+
if (!documentId) {
|
|
429
|
+
console.error("PUT /api/gallery-data: Document ID is required");
|
|
430
|
+
return NextResponse.json({ error: "Document ID is required" }, { status: 400 });
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const validCategory = category && ["none", "indoor", "outdoor", "commercial"].includes(category) ? category : "none";
|
|
434
|
+
|
|
435
|
+
const payload = {
|
|
436
|
+
data: {
|
|
437
|
+
title: title || `Image ${new Date().toISOString()}`,
|
|
438
|
+
description: description || "",
|
|
439
|
+
category: validCategory,
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
const updateResponse = await fetch(`${CONTENT_API_URL}/${documentId}`, {
|
|
444
|
+
method: "PUT",
|
|
445
|
+
headers: {
|
|
446
|
+
"Content-Type": "application/json",
|
|
447
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
448
|
+
},
|
|
449
|
+
body: JSON.stringify(payload),
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
if (!updateResponse.ok) {
|
|
453
|
+
const errorData = await updateResponse.json();
|
|
454
|
+
let errorMessage = `Failed to update content entry: ${updateResponse.status} - ${errorData.error?.message || "Unknown error"}`;
|
|
455
|
+
if (errorData.error?.details) {
|
|
456
|
+
errorMessage += `\nDetails: ${JSON.stringify(errorData.error.details, null, 2)}`;
|
|
457
|
+
}
|
|
458
|
+
console.error("PUT /api/gallery-data: Update content failed", { errorMessage });
|
|
459
|
+
return NextResponse.json({ error: errorMessage }, { status: updateResponse.status });
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const filesResponse = await fetch(
|
|
463
|
+
`${CONTENT_API_URL}?publicationState=live&populate=image&fields[0]=title&fields[1]=description&fields[2]=createdAt&fields[3]=category&pagination[pageSize]=100&t=${Date.now()}`,
|
|
464
|
+
{
|
|
465
|
+
headers: {
|
|
466
|
+
"Content-Type": "application/json",
|
|
467
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
468
|
+
},
|
|
469
|
+
cache: "no-store",
|
|
470
|
+
}
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
if (!filesResponse.ok) {
|
|
474
|
+
const errorText = await filesResponse.text();
|
|
475
|
+
console.error("PUT /api/gallery-data: Refetch images failed:", { status: filesResponse.status, errorText });
|
|
476
|
+
return NextResponse.json(
|
|
477
|
+
{ error: `Failed to refetch images: ${errorText}` },
|
|
478
|
+
{ status: filesResponse.status }
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const filesResult = await filesResponse.json();
|
|
483
|
+
const images: UploadedImage[] = filesResult.data
|
|
484
|
+
.map((item: any) => {
|
|
485
|
+
const image = item.image;
|
|
486
|
+
if (!image || !image.url) {
|
|
487
|
+
console.warn(`Image missing for item ${item.id}:`, JSON.stringify(item, null, 2));
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
const rawUrl = image.url || "";
|
|
491
|
+
const imageUrl = rawUrl.startsWith("http") ? rawUrl : `${BASE_URL}${rawUrl}`;
|
|
492
|
+
return {
|
|
493
|
+
id: item.id,
|
|
494
|
+
documentId: item.documentId,
|
|
495
|
+
title: item.title || "",
|
|
496
|
+
description: item.description || "",
|
|
497
|
+
url: imageUrl,
|
|
498
|
+
createdAt: item.createdAt,
|
|
499
|
+
category: item.category || "none",
|
|
500
|
+
};
|
|
501
|
+
})
|
|
502
|
+
.filter((image: UploadedImage | null): image is UploadedImage => image !== null)
|
|
503
|
+
.sort((a: UploadedImage, b: UploadedImage) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
504
|
+
|
|
505
|
+
return NextResponse.json({
|
|
506
|
+
data: images,
|
|
507
|
+
meta: filesResult.meta,
|
|
508
|
+
});
|
|
509
|
+
} catch (error) {
|
|
510
|
+
console.error("PUT /api/gallery-data: Error:", error);
|
|
511
|
+
return NextResponse.json(
|
|
512
|
+
{ error: error instanceof Error ? error.message : "Failed to update image" },
|
|
513
|
+
{ status: 500 }
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export async function DELETE(request: NextRequest) {
|
|
519
|
+
const { userId } = getAuth(request);
|
|
520
|
+
if (!userId) {
|
|
521
|
+
console.error("DELETE /api/gallery-data: No userId, returning 401");
|
|
522
|
+
return NextResponse.json({ error: "Unauthorized: No user ID" }, { status: 401 });
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const user = await verifyUser(request);
|
|
526
|
+
|
|
527
|
+
if (!user || user.businessAdminId !== ADMIN_BUSINESS_ID || user.userRole !== "admin") {
|
|
528
|
+
console.error("DELETE /api/gallery-data: Unauthorized access attempt", {
|
|
529
|
+
authId: user?.authId,
|
|
530
|
+
businessAdminId: user?.businessAdminId,
|
|
531
|
+
envBusinessAdminId: ADMIN_BUSINESS_ID,
|
|
532
|
+
userRole: user?.userRole,
|
|
533
|
+
});
|
|
534
|
+
return NextResponse.json({ error: "Unauthorized: Only admins can delete images" }, { status: 403 });
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
try {
|
|
538
|
+
if (!CONTENT_API_URL || !STRAPI_API_TOKEN) {
|
|
539
|
+
console.error(
|
|
540
|
+
"Missing environment variables:",
|
|
541
|
+
!CONTENT_API_URL && "STRAPI_CONTENT_API_URL",
|
|
542
|
+
!STRAPI_API_TOKEN && "STRAPI_API_TOKEN"
|
|
543
|
+
);
|
|
544
|
+
return NextResponse.json(
|
|
545
|
+
{ error: "Server configuration error: Missing required environment variables" },
|
|
546
|
+
{ status: 500 }
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const { documentId } = await request.json();
|
|
551
|
+
if (!documentId) {
|
|
552
|
+
console.error("DELETE /api/gallery-data: Document ID is required");
|
|
553
|
+
return NextResponse.json({ error: "Document ID is required" }, { status: 400 });
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const docResponse = await fetch(`${CONTENT_API_URL}/${documentId}?populate=image`, {
|
|
557
|
+
headers: {
|
|
558
|
+
"Content-Type": "application/json",
|
|
559
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
560
|
+
},
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
if (!docResponse.ok) {
|
|
564
|
+
const errorText = await docResponse.text();
|
|
565
|
+
console.error("DELETE /api/gallery-data: Fetch document failed:", { status: docResponse.status, errorText });
|
|
566
|
+
return NextResponse.json(
|
|
567
|
+
{ error: `Failed to fetch content: ${errorText}` },
|
|
568
|
+
{ status: docResponse.status }
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const docData = await docResponse.json();
|
|
573
|
+
const uploadFileId = docData.data?.image?.id;
|
|
574
|
+
|
|
575
|
+
const deleteDocResponse = await fetch(`${CONTENT_API_URL}/${documentId}`, {
|
|
576
|
+
method: "DELETE",
|
|
577
|
+
headers: {
|
|
578
|
+
"Content-Type": "application/json",
|
|
579
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
580
|
+
},
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
if (!deleteDocResponse.ok) {
|
|
584
|
+
const errorText = await deleteDocResponse.text();
|
|
585
|
+
console.error("DELETE /api/gallery-data: Delete document failed:", { status: deleteDocResponse.status, errorText });
|
|
586
|
+
return NextResponse.json(
|
|
587
|
+
{ error: `Failed to delete content: ${errorText}` },
|
|
588
|
+
{ status: deleteDocResponse.status }
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (uploadFileId) {
|
|
593
|
+
const deleteFileResponse = await fetch(`${UPLOAD_API_URL}/files/${uploadFileId}`, {
|
|
594
|
+
method: "DELETE",
|
|
595
|
+
headers: {
|
|
596
|
+
"Content-Type": "application/json",
|
|
597
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
598
|
+
},
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
if (!deleteFileResponse.ok) {
|
|
602
|
+
const errorText = await deleteFileResponse.text();
|
|
603
|
+
console.warn(`DELETE /api/gallery-data: Failed to delete associated file: ${deleteFileResponse.status} - ${errorText}`);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const filesResponse = await fetch(
|
|
608
|
+
`${CONTENT_API_URL}?publicationState=live&populate=image&fields[0]=title&fields[1]=description&fields[2]=createdAt&fields[3]=category&pagination[pageSize]=100&t=${Date.now()}`,
|
|
609
|
+
{
|
|
610
|
+
headers: {
|
|
611
|
+
"Content-Type": "application/json",
|
|
612
|
+
Authorization: `Bearer ${STRAPI_API_TOKEN}`,
|
|
613
|
+
},
|
|
614
|
+
cache: "no-store",
|
|
615
|
+
}
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
if (!filesResponse.ok) {
|
|
619
|
+
const errorText = await filesResponse.text();
|
|
620
|
+
console.error("DELETE /api/gallery-data: Refetch images failed:", { status: filesResponse.status, errorText });
|
|
621
|
+
return NextResponse.json(
|
|
622
|
+
{ error: `Failed to refetch images: ${errorText}` },
|
|
623
|
+
{ status: filesResponse.status }
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const filesResult = await filesResponse.json();
|
|
628
|
+
const images: UploadedImage[] = filesResult.data
|
|
629
|
+
.map((item: any) => {
|
|
630
|
+
const image = item.image;
|
|
631
|
+
if (!image || !image.url) {
|
|
632
|
+
console.warn(`Image missing for item ${item.id}:`, JSON.stringify(item, null, 2));
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
const rawUrl = image.url || "";
|
|
636
|
+
const imageUrl = rawUrl.startsWith("http") ? rawUrl : `${BASE_URL}${rawUrl}`;
|
|
637
|
+
return {
|
|
638
|
+
id: item.id,
|
|
639
|
+
documentId: item.documentId,
|
|
640
|
+
title: item.title || "",
|
|
641
|
+
description: item.description || "",
|
|
642
|
+
url: imageUrl,
|
|
643
|
+
createdAt: item.createdAt,
|
|
644
|
+
category: item.category || "none",
|
|
645
|
+
};
|
|
646
|
+
})
|
|
647
|
+
.filter((image: UploadedImage | null): image is UploadedImage => image !== null)
|
|
648
|
+
.sort((a: UploadedImage, b: UploadedImage) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
649
|
+
|
|
650
|
+
return NextResponse.json({
|
|
651
|
+
data: images,
|
|
652
|
+
meta: filesResult.meta,
|
|
653
|
+
});
|
|
654
|
+
} catch (error) {
|
|
655
|
+
console.error("DELETE /api/gallery-data: Error:", error);
|
|
656
|
+
return NextResponse.json(
|
|
657
|
+
{ error: error instanceof Error ? error.message : "Failed to delete image" },
|
|
658
|
+
{ status: 500 }
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
}
|