create-nextjs-cms 0.5.8
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 +71 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +395 -0
- package/dist/lib/utils.d.ts +11 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +48 -0
- package/package.json +44 -0
- package/templates/default/.env +24 -0
- package/templates/default/.env.development +8 -0
- package/templates/default/.eslintrc.json +5 -0
- package/templates/default/.prettierignore +7 -0
- package/templates/default/.prettierrc.json +19 -0
- package/templates/default/CHANGELOG.md +77 -0
- package/templates/default/README.md +45 -0
- package/templates/default/app/(auth)/auth/login/LoginPage.tsx +175 -0
- package/templates/default/app/(auth)/auth/login/page.tsx +12 -0
- package/templates/default/app/(rootLayout)/admins/page.tsx +5 -0
- package/templates/default/app/(rootLayout)/advanced/page.tsx +5 -0
- package/templates/default/app/(rootLayout)/analytics/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/browse/[section]/[page]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/categorized/[section]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/dashboard/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/edit/[section]/[itemId]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/emails/page.tsx +6 -0
- package/templates/default/app/(rootLayout)/layout.tsx +5 -0
- package/templates/default/app/(rootLayout)/loading.tsx +10 -0
- package/templates/default/app/(rootLayout)/log/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/new/[section]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/page.tsx +9 -0
- package/templates/default/app/(rootLayout)/section/[section]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/settings/page.tsx +7 -0
- package/templates/default/app/_trpc/client.ts +4 -0
- package/templates/default/app/api/auth/csrf/route.ts +25 -0
- package/templates/default/app/api/auth/refresh/route.ts +10 -0
- package/templates/default/app/api/auth/route.ts +23 -0
- package/templates/default/app/api/auth/session/route.ts +20 -0
- package/templates/default/app/api/editor/photo/route.ts +42 -0
- package/templates/default/app/api/photo/route.ts +27 -0
- package/templates/default/app/api/placeholder/route.ts +7 -0
- package/templates/default/app/api/submit/section/item/[slug]/route.ts +63 -0
- package/templates/default/app/api/submit/section/item/route.ts +53 -0
- package/templates/default/app/api/submit/section/simple/route.ts +54 -0
- package/templates/default/app/api/trpc/[trpc]/route.ts +33 -0
- package/templates/default/app/api/video/route.ts +174 -0
- package/templates/default/app/dictionaries.ts +14 -0
- package/templates/default/app/layout.tsx +28 -0
- package/templates/default/app/providers.tsx +151 -0
- package/templates/default/cli.ts +4 -0
- package/templates/default/components/AdminCard.tsx +163 -0
- package/templates/default/components/AdminEditPage.tsx +123 -0
- package/templates/default/components/AdminPrivilegeCard.tsx +184 -0
- package/templates/default/components/AdminsPage.tsx +43 -0
- package/templates/default/components/AdvancedSettingsPage.tsx +167 -0
- package/templates/default/components/AnalyticsPage.tsx +127 -0
- package/templates/default/components/BarChartBox.tsx +43 -0
- package/templates/default/components/BrowsePage.tsx +119 -0
- package/templates/default/components/CategorizedSectionPage.tsx +36 -0
- package/templates/default/components/CategoryDeleteConfirmPage.tsx +129 -0
- package/templates/default/components/CategorySectionSelectInput.tsx +139 -0
- package/templates/default/components/ConditionalFields.tsx +49 -0
- package/templates/default/components/ContainerBox.tsx +24 -0
- package/templates/default/components/DashboardPage.tsx +187 -0
- package/templates/default/components/DashboardPageAlt.tsx +43 -0
- package/templates/default/components/DefaultNavItems.tsx +3 -0
- package/templates/default/components/Dropzone.tsx +153 -0
- package/templates/default/components/EmailCard.tsx +137 -0
- package/templates/default/components/EmailPasswordForm.tsx +84 -0
- package/templates/default/components/EmailQuotaForm.tsx +72 -0
- package/templates/default/components/EmailsPage.tsx +48 -0
- package/templates/default/components/GalleryPhoto.tsx +93 -0
- package/templates/default/components/InfoCard.tsx +94 -0
- package/templates/default/components/ItemEditPage.tsx +217 -0
- package/templates/default/components/Layout.tsx +70 -0
- package/templates/default/components/LoadingSpinners.tsx +67 -0
- package/templates/default/components/LogPage.tsx +17 -0
- package/templates/default/components/Modal.tsx +99 -0
- package/templates/default/components/Navbar.tsx +29 -0
- package/templates/default/components/NavbarAlt.tsx +182 -0
- package/templates/default/components/NewAdminForm.tsx +172 -0
- package/templates/default/components/NewEmailForm.tsx +131 -0
- package/templates/default/components/NewPage.tsx +206 -0
- package/templates/default/components/NewVariantComponent.tsx +228 -0
- package/templates/default/components/PhotoGallery.tsx +35 -0
- package/templates/default/components/PieChartBox.tsx +101 -0
- package/templates/default/components/ProgressBar.tsx +24 -0
- package/templates/default/components/ProtectedDocument.tsx +78 -0
- package/templates/default/components/ProtectedImage.tsx +143 -0
- package/templates/default/components/ProtectedVideo.tsx +76 -0
- package/templates/default/components/SectionItemCard.tsx +143 -0
- package/templates/default/components/SectionItemStatusBadge.tsx +16 -0
- package/templates/default/components/SectionPage.tsx +124 -0
- package/templates/default/components/SelectBox.tsx +99 -0
- package/templates/default/components/SelectInputButtons.tsx +124 -0
- package/templates/default/components/SettingsPage.tsx +238 -0
- package/templates/default/components/Sidebar.tsx +209 -0
- package/templates/default/components/SidebarDropdownItem.tsx +74 -0
- package/templates/default/components/SidebarItem.tsx +19 -0
- package/templates/default/components/TempPage.tsx +12 -0
- package/templates/default/components/ThemeProvider.tsx +8 -0
- package/templates/default/components/TooltipComponent.tsx +27 -0
- package/templates/default/components/VariantCard.tsx +123 -0
- package/templates/default/components/VariantEditPage.tsx +229 -0
- package/templates/default/components/analytics/BounceRate.tsx +69 -0
- package/templates/default/components/analytics/LivePageViews.tsx +54 -0
- package/templates/default/components/analytics/LiveUsersCount.tsx +32 -0
- package/templates/default/components/analytics/MonthlyPageViews.tsx +41 -0
- package/templates/default/components/analytics/TopCountries.tsx +51 -0
- package/templates/default/components/analytics/TopDevices.tsx +45 -0
- package/templates/default/components/analytics/TopMediums.tsx +57 -0
- package/templates/default/components/analytics/TopSources.tsx +44 -0
- package/templates/default/components/analytics/TotalPageViews.tsx +40 -0
- package/templates/default/components/analytics/TotalSessions.tsx +40 -0
- package/templates/default/components/analytics/TotalUniqueUsers.tsx +40 -0
- package/templates/default/components/custom/RightHomeRoomVariantCard.tsx +137 -0
- package/templates/default/components/dndKit/Draggable.tsx +21 -0
- package/templates/default/components/dndKit/Droppable.tsx +20 -0
- package/templates/default/components/dndKit/SortableItem.tsx +18 -0
- package/templates/default/components/form/DateRangeFormInput.tsx +55 -0
- package/templates/default/components/form/Form.tsx +298 -0
- package/templates/default/components/form/FormInputElement.tsx +68 -0
- package/templates/default/components/form/FormInputs.tsx +108 -0
- package/templates/default/components/form/helpers/util.ts +20 -0
- package/templates/default/components/form/inputs/CheckboxFormInput.tsx +33 -0
- package/templates/default/components/form/inputs/ColorFormInput.tsx +44 -0
- package/templates/default/components/form/inputs/DateFormInput.tsx +107 -0
- package/templates/default/components/form/inputs/DocumentFormInput.tsx +124 -0
- package/templates/default/components/form/inputs/MapFormInput.tsx +139 -0
- package/templates/default/components/form/inputs/MultipleSelectFormInput.tsx +150 -0
- package/templates/default/components/form/inputs/NumberFormInput.tsx +42 -0
- package/templates/default/components/form/inputs/PasswordFormInput.tsx +47 -0
- package/templates/default/components/form/inputs/PhotoFormInput.tsx +218 -0
- package/templates/default/components/form/inputs/RichTextFormInput.tsx +133 -0
- package/templates/default/components/form/inputs/SelectFormInput.tsx +164 -0
- package/templates/default/components/form/inputs/TagsFormInput.tsx +63 -0
- package/templates/default/components/form/inputs/TextFormInput.tsx +48 -0
- package/templates/default/components/form/inputs/TextareaFormInput.tsx +47 -0
- package/templates/default/components/form/inputs/VideoFormInput.tsx +117 -0
- package/templates/default/components/pagination/Pagination.tsx +36 -0
- package/templates/default/components/pagination/PaginationButtons.tsx +145 -0
- package/templates/default/components/ui/accordion.tsx +57 -0
- package/templates/default/components/ui/alert.tsx +46 -0
- package/templates/default/components/ui/badge.tsx +33 -0
- package/templates/default/components/ui/button.tsx +57 -0
- package/templates/default/components/ui/calendar.tsx +68 -0
- package/templates/default/components/ui/card.tsx +76 -0
- package/templates/default/components/ui/checkbox.tsx +29 -0
- package/templates/default/components/ui/dropdown-menu.tsx +205 -0
- package/templates/default/components/ui/input.tsx +25 -0
- package/templates/default/components/ui/label.tsx +26 -0
- package/templates/default/components/ui/popover.tsx +31 -0
- package/templates/default/components/ui/scroll-area.tsx +42 -0
- package/templates/default/components/ui/select.tsx +164 -0
- package/templates/default/components/ui/sheet.tsx +107 -0
- package/templates/default/components/ui/switch.tsx +29 -0
- package/templates/default/components/ui/table.tsx +120 -0
- package/templates/default/components/ui/tabs.tsx +55 -0
- package/templates/default/components/ui/toast.tsx +113 -0
- package/templates/default/components/ui/toaster.tsx +35 -0
- package/templates/default/components/ui/tooltip.tsx +30 -0
- package/templates/default/components/ui/use-toast.ts +188 -0
- package/templates/default/components.json +16 -0
- package/templates/default/context/ModalProvider.tsx +53 -0
- package/templates/default/drizzle.config.ts +4 -0
- package/templates/default/dynamic-schemas/schema.ts +373 -0
- package/templates/default/env/env.js +130 -0
- package/templates/default/envConfig.ts +4 -0
- package/templates/default/hooks/useModal.ts +8 -0
- package/templates/default/lib/apiHelpers.ts +106 -0
- package/templates/default/lz.config.ts +40 -0
- package/templates/default/middleware.ts +33 -0
- package/templates/default/next.config.ts +46 -0
- package/templates/default/package.json +134 -0
- package/templates/default/postcss.config.js +6 -0
- package/templates/default/postinstall.js +14 -0
- package/templates/default/public/blank_avatar.png +0 -0
- package/templates/default/public/favicon.ico +0 -0
- package/templates/default/public/img/placeholder.svg +1 -0
- package/templates/default/public/lazemni_logo.png +0 -0
- package/templates/default/public/next.svg +1 -0
- package/templates/default/public/vercel.svg +1 -0
- package/templates/default/section-tests.ts +92 -0
- package/templates/default/styles/globals.css +88 -0
- package/templates/default/tailwind.config.js +95 -0
- package/templates/default/test.ts +77 -0
- package/templates/default/tsconfig.json +44 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server'
|
|
2
|
+
import { EditSubmit } from 'nextjs-cms/core/submit'
|
|
3
|
+
import auth from 'nextjs-cms/auth'
|
|
4
|
+
|
|
5
|
+
export async function PUT(request: NextRequest, { params }: { params: Promise<{ slug: string }> }) {
|
|
6
|
+
const session = await auth()
|
|
7
|
+
const { slug: itemId } = await params
|
|
8
|
+
|
|
9
|
+
if (!session || !session.user) {
|
|
10
|
+
return NextResponse.json(
|
|
11
|
+
{
|
|
12
|
+
error: 'Access token not provided',
|
|
13
|
+
},
|
|
14
|
+
{ status: 401 },
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (itemId === null) {
|
|
19
|
+
return NextResponse.json(
|
|
20
|
+
{
|
|
21
|
+
error: 'Item id not provided',
|
|
22
|
+
},
|
|
23
|
+
{ status: 401 },
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const user = session.user
|
|
28
|
+
const formData = await request.formData()
|
|
29
|
+
const sectionName = formData.get('sectionName') as string | null
|
|
30
|
+
|
|
31
|
+
if (!sectionName) {
|
|
32
|
+
return NextResponse.json(
|
|
33
|
+
{
|
|
34
|
+
error: 'Section name not provided',
|
|
35
|
+
},
|
|
36
|
+
{ status: 400 },
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const submit = new EditSubmit({
|
|
41
|
+
itemId: itemId as string,
|
|
42
|
+
sectionName,
|
|
43
|
+
user,
|
|
44
|
+
postData: formData,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
await submit.initialize()
|
|
48
|
+
await submit.submit()
|
|
49
|
+
if (submit.error) {
|
|
50
|
+
return NextResponse.json(
|
|
51
|
+
{
|
|
52
|
+
error: submit.errorMessage,
|
|
53
|
+
},
|
|
54
|
+
{ status: 400 },
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
return NextResponse.json(
|
|
58
|
+
{
|
|
59
|
+
message: 'Section item submitted successfully',
|
|
60
|
+
},
|
|
61
|
+
{ status: 200 },
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server'
|
|
2
|
+
import { NewSubmit } from 'nextjs-cms/core/submit'
|
|
3
|
+
import auth from 'nextjs-cms/auth'
|
|
4
|
+
|
|
5
|
+
export async function POST(request: NextRequest) {
|
|
6
|
+
const session = await auth()
|
|
7
|
+
|
|
8
|
+
if (!session || !session.user) {
|
|
9
|
+
return NextResponse.json(
|
|
10
|
+
{
|
|
11
|
+
error: 'Access token not provided',
|
|
12
|
+
},
|
|
13
|
+
{ status: 401 },
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const user = session.user
|
|
18
|
+
const formData = await request.formData()
|
|
19
|
+
const sectionName = formData.get('sectionName') as string | null
|
|
20
|
+
|
|
21
|
+
if (!sectionName) {
|
|
22
|
+
return NextResponse.json(
|
|
23
|
+
{
|
|
24
|
+
error: 'Section name not provided',
|
|
25
|
+
},
|
|
26
|
+
{ status: 400 },
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const submit = new NewSubmit({
|
|
31
|
+
sectionName,
|
|
32
|
+
user,
|
|
33
|
+
postData: formData,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
await submit.initialize()
|
|
37
|
+
await submit.submit()
|
|
38
|
+
if (submit.error) {
|
|
39
|
+
return NextResponse.json(
|
|
40
|
+
{
|
|
41
|
+
error: submit.errorMessage,
|
|
42
|
+
},
|
|
43
|
+
{ status: 400 },
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return NextResponse.json(
|
|
48
|
+
{
|
|
49
|
+
message: 'Section item submitted successfully',
|
|
50
|
+
},
|
|
51
|
+
{ status: 200 },
|
|
52
|
+
)
|
|
53
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server'
|
|
2
|
+
import { SimpleSectionSubmit } from 'nextjs-cms/core/submit'
|
|
3
|
+
import auth from 'nextjs-cms/auth'
|
|
4
|
+
|
|
5
|
+
export async function PUT(request: NextRequest) {
|
|
6
|
+
const session = await auth()
|
|
7
|
+
|
|
8
|
+
if (!session || !session.user) {
|
|
9
|
+
return NextResponse.json(
|
|
10
|
+
{
|
|
11
|
+
error: 'Access token not provided',
|
|
12
|
+
},
|
|
13
|
+
{ status: 401 },
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const user = session.user
|
|
18
|
+
const formData = await request.formData()
|
|
19
|
+
const sectionName = formData.get('sectionName') as string | null
|
|
20
|
+
|
|
21
|
+
if (!sectionName) {
|
|
22
|
+
return NextResponse.json(
|
|
23
|
+
{
|
|
24
|
+
error: 'Section name not provided',
|
|
25
|
+
},
|
|
26
|
+
{ status: 400 },
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const submit = new SimpleSectionSubmit({
|
|
31
|
+
itemId: '1',
|
|
32
|
+
sectionName,
|
|
33
|
+
user,
|
|
34
|
+
postData: formData,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
await submit.initialize()
|
|
38
|
+
await submit.submit()
|
|
39
|
+
if (submit.error) {
|
|
40
|
+
return NextResponse.json(
|
|
41
|
+
{
|
|
42
|
+
error: submit.errorMessage,
|
|
43
|
+
},
|
|
44
|
+
{ status: 400 },
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return NextResponse.json(
|
|
49
|
+
{
|
|
50
|
+
message: 'Section item submitted successfully',
|
|
51
|
+
},
|
|
52
|
+
{ status: 200 },
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'
|
|
2
|
+
import { appRouter, createTRPCContext } from 'nextjs-cms/api'
|
|
3
|
+
import { NextRequest } from 'next/server'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This wraps the `createContext` helper and provides the required context for the tRPC API when
|
|
7
|
+
* handling a HTTP request (e.g. when you make requests from Client Components).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const context = async (req: NextRequest) => {
|
|
11
|
+
return createTRPCContext({
|
|
12
|
+
req: req,
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const handler = (req: NextRequest) =>
|
|
17
|
+
fetchRequestHandler({
|
|
18
|
+
endpoint: '/api/trpc',
|
|
19
|
+
req,
|
|
20
|
+
router: appRouter,
|
|
21
|
+
createContext: () => context(req),
|
|
22
|
+
/*onError(opts) {
|
|
23
|
+
return opts.error
|
|
24
|
+
},*/
|
|
25
|
+
onError:
|
|
26
|
+
process.env.NODE_ENV === 'development'
|
|
27
|
+
? ({ path, error }) => {
|
|
28
|
+
console.error(`❌ tRPC failed on ${path ?? '<no-path>'}: ${error.message}`)
|
|
29
|
+
}
|
|
30
|
+
: undefined,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export { handler as GET, handler as POST }
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import { readChunk } from 'read-chunk'
|
|
5
|
+
import { fileTypeFromBuffer } from 'file-type'
|
|
6
|
+
import { SectionFactory } from 'nextjs-cms/core/factories'
|
|
7
|
+
import { FileField } from 'nextjs-cms/core/fields'
|
|
8
|
+
import auth from 'nextjs-cms/auth'
|
|
9
|
+
import { sanitizeFileName, sanitizeFolderOrFileName } from 'nextjs-cms/utils'
|
|
10
|
+
import { streamFile } from 'nextjs-cms/api/helpers'
|
|
11
|
+
import { getCMSConfig } from 'nextjs-cms/core/config'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This route handler is used to stream a video file from the server
|
|
15
|
+
* It's used to protect the video files from being accessed directly
|
|
16
|
+
* It's being used in the `<ProtectedVideo />` component
|
|
17
|
+
* @param request
|
|
18
|
+
* @constructor
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export async function GET(request: NextRequest) {
|
|
22
|
+
const session = await auth()
|
|
23
|
+
const searchParams = request.nextUrl.searchParams
|
|
24
|
+
|
|
25
|
+
const name = searchParams.get('name')
|
|
26
|
+
const sectionName = searchParams.get('sectionName')
|
|
27
|
+
const fieldName = searchParams.get('fieldName')
|
|
28
|
+
|
|
29
|
+
if (!name || !sectionName || !fieldName) {
|
|
30
|
+
return NextResponse.json(
|
|
31
|
+
{
|
|
32
|
+
error: 'Invalid request',
|
|
33
|
+
},
|
|
34
|
+
{ status: 400 },
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Check if the session is valid
|
|
39
|
+
if (!session || !session.user) {
|
|
40
|
+
return NextResponse.json(
|
|
41
|
+
{
|
|
42
|
+
error: 'Invalid token',
|
|
43
|
+
},
|
|
44
|
+
{ status: 401 },
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const uploadsFolder: string = getCMSConfig().files.upload.uploadPath
|
|
49
|
+
|
|
50
|
+
// Sanitize the inputs
|
|
51
|
+
const sanitizedFolder = sanitizeFolderOrFileName(sectionName)
|
|
52
|
+
const sanitizedName = sanitizeFileName(name)
|
|
53
|
+
/**
|
|
54
|
+
* Check the section and the field name, and get the allowed extensions,
|
|
55
|
+
* while also checking if the user has access to the section
|
|
56
|
+
*/
|
|
57
|
+
const section = await SectionFactory.getSectionForAdmin({
|
|
58
|
+
name: sanitizedFolder,
|
|
59
|
+
admin: { id: session.user.id },
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* If the check fails, throw an error
|
|
64
|
+
*/
|
|
65
|
+
if (!section || !section.name) {
|
|
66
|
+
return NextResponse.json(
|
|
67
|
+
{
|
|
68
|
+
error: 'Invalid file path',
|
|
69
|
+
},
|
|
70
|
+
{ status: 400 },
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const fieldInfo = section.fields.find((field) => field.name === fieldName) as FileField
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* If field is not found, throw an error
|
|
78
|
+
*/
|
|
79
|
+
if (!fieldInfo || !fieldInfo.name || !fieldInfo.extensions || fieldInfo.extensions.length === 0) {
|
|
80
|
+
return NextResponse.json(
|
|
81
|
+
{
|
|
82
|
+
error: 'Invalid request',
|
|
83
|
+
},
|
|
84
|
+
{ status: 400 },
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Split the allowed extensions into an array
|
|
90
|
+
*/
|
|
91
|
+
const videoAllowedExtensions = fieldInfo.extensions
|
|
92
|
+
const dir = '.videos'
|
|
93
|
+
const pathToFile = path.join(uploadsFolder, dir, sanitizedFolder, sanitizedName)
|
|
94
|
+
/**
|
|
95
|
+
* First, check if the file exists
|
|
96
|
+
*/
|
|
97
|
+
if (!fs.existsSync(pathToFile)) {
|
|
98
|
+
return NextResponse.json(
|
|
99
|
+
{
|
|
100
|
+
error: 'File not found',
|
|
101
|
+
},
|
|
102
|
+
{ status: 404 },
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Read the first 4100 bytes of the file
|
|
108
|
+
*/
|
|
109
|
+
const chunkBuffer = await readChunk(pathToFile, { length: 4100 })
|
|
110
|
+
/**
|
|
111
|
+
* Get the file type from the buffer
|
|
112
|
+
*/
|
|
113
|
+
const fileType = await fileTypeFromBuffer(chunkBuffer)
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* If the file type is invalid, return an error
|
|
117
|
+
*/
|
|
118
|
+
if (!fileType) {
|
|
119
|
+
return NextResponse.json(
|
|
120
|
+
{
|
|
121
|
+
error: 'Invalid file type',
|
|
122
|
+
},
|
|
123
|
+
{ status: 400 },
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Check if the file type is allowed
|
|
129
|
+
*/
|
|
130
|
+
if (!videoAllowedExtensions.includes(fileType.ext)) {
|
|
131
|
+
return NextResponse.json(
|
|
132
|
+
{
|
|
133
|
+
error: 'Invalid file type',
|
|
134
|
+
},
|
|
135
|
+
{ status: 400 },
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const fileStats = fs.statSync(pathToFile)
|
|
140
|
+
const range = request.headers.get('range')
|
|
141
|
+
const videoSize = fileStats.size
|
|
142
|
+
const videoMimeType = fileType.mime
|
|
143
|
+
|
|
144
|
+
let res = null
|
|
145
|
+
if (range) {
|
|
146
|
+
const parts = range.replace(/bytes=/, '').split('-')
|
|
147
|
+
const start = parseInt(parts[0] ?? '0', 10)
|
|
148
|
+
const end = parts[1] ? parseInt(parts[1], 10) : videoSize - 1
|
|
149
|
+
const chunkSize = end - start + 1
|
|
150
|
+
|
|
151
|
+
const data: ReadableStream<Uint8Array> = await streamFile(pathToFile, { start, end })
|
|
152
|
+
|
|
153
|
+
res = new NextResponse(data, {
|
|
154
|
+
headers: {
|
|
155
|
+
'Content-Range': `bytes ${start}-${end}/${videoSize}`,
|
|
156
|
+
'Accept-Ranges': 'bytes',
|
|
157
|
+
'Content-Length': chunkSize.toString(),
|
|
158
|
+
'Content-Type': videoMimeType,
|
|
159
|
+
},
|
|
160
|
+
status: 206,
|
|
161
|
+
})
|
|
162
|
+
} else {
|
|
163
|
+
const data: ReadableStream<Uint8Array> = await streamFile(pathToFile)
|
|
164
|
+
res = new NextResponse(data, {
|
|
165
|
+
headers: {
|
|
166
|
+
'Content-Length': videoSize.toString(),
|
|
167
|
+
'Content-Type': videoMimeType,
|
|
168
|
+
},
|
|
169
|
+
status: 200,
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return res
|
|
174
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
const dictionaries: Record<string, () => Promise<any>> = {
|
|
4
|
+
en: () => import('@/dictionaries/en.json').then((module) => module.default),
|
|
5
|
+
ar: () => import('@/dictionaries/ar.json').then((module) => module.default),
|
|
6
|
+
// DefaultS to Arabic
|
|
7
|
+
default: () => import('@/dictionaries/ar.json').then((module) => module.default),
|
|
8
|
+
}
|
|
9
|
+
export const getDictionary = async (locale: string) => {
|
|
10
|
+
const dictionary = dictionaries[locale]
|
|
11
|
+
if (dictionary) {
|
|
12
|
+
return dictionary()
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Inter } from 'next/font/google'
|
|
2
|
+
import '@/styles/globals.css'
|
|
3
|
+
import type { Metadata } from 'next'
|
|
4
|
+
import { cn } from 'nextjs-cms/utils'
|
|
5
|
+
import { ThemeProvider } from '@/components/ThemeProvider'
|
|
6
|
+
import Providers from '@/app/providers'
|
|
7
|
+
|
|
8
|
+
export const metadata: Metadata = {
|
|
9
|
+
title: 'LAZEMNI CMS',
|
|
10
|
+
description: 'LAZEMNI CMS',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const inter = Inter({
|
|
14
|
+
subsets: ['latin'],
|
|
15
|
+
variable: '--font-sans',
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
|
19
|
+
return (
|
|
20
|
+
<html lang='en' suppressHydrationWarning>
|
|
21
|
+
<body className={cn('min-h-screen bg-background font-sans antialiased', inter.variable)}>
|
|
22
|
+
<ThemeProvider attribute='class' defaultTheme='dark' enableSystem disableTransitionOnChange>
|
|
23
|
+
<Providers>{children}</Providers>
|
|
24
|
+
</ThemeProvider>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { QueryClient, QueryClientProvider, defaultShouldDehydrateQuery } from '@tanstack/react-query'
|
|
4
|
+
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
|
5
|
+
import { ModalProvider } from '@/context/ModalProvider'
|
|
6
|
+
import { trpc } from '@/app/_trpc/client'
|
|
7
|
+
import { httpBatchLink, loggerLink } from '@trpc/client'
|
|
8
|
+
import SuperJSON from 'superjson'
|
|
9
|
+
import { useState } from 'react'
|
|
10
|
+
import { getCsrfToken, SessionProvider, refreshTokenLink } from 'nextjs-cms/auth/react'
|
|
11
|
+
|
|
12
|
+
function MakeTrpcClient() {
|
|
13
|
+
const [trpcClient] = useState(() =>
|
|
14
|
+
trpc.createClient({
|
|
15
|
+
links: [
|
|
16
|
+
/**
|
|
17
|
+
* The refresh token link will automatically refresh the access token if it's expired.
|
|
18
|
+
* It fetches the new access token using the refresh token by calling the `/api/auth/refresh` endpoint.
|
|
19
|
+
*/
|
|
20
|
+
refreshTokenLink(),
|
|
21
|
+
/**
|
|
22
|
+
* The logger link will log all the operations that are being sent to the server.
|
|
23
|
+
* @see https://trpc.io/docs/client/links/loggerLink
|
|
24
|
+
*/
|
|
25
|
+
loggerLink({
|
|
26
|
+
enabled: (op) =>
|
|
27
|
+
process.env.NODE_ENV === 'development' ||
|
|
28
|
+
(op.direction === 'down' && op.result instanceof Error),
|
|
29
|
+
}),
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The HTTP batch link is used to send multiple operations in a single HTTP request,
|
|
33
|
+
* but doesn't wait for all the responses of the batch to be ready,
|
|
34
|
+
* and streams the responses as soon as any data is available.
|
|
35
|
+
* @see https://trpc.io/docs/client/links/httpBatchStreamLink
|
|
36
|
+
*
|
|
37
|
+
* TODO: The stream link is somehow causing empty responses before the actual response!
|
|
38
|
+
*/
|
|
39
|
+
/*unstable_httpBatchStreamLink({
|
|
40
|
+
transformer: superjson,
|
|
41
|
+
url: '/api/trpc',
|
|
42
|
+
// You can pass any HTTP headers you wish here
|
|
43
|
+
async headers() {
|
|
44
|
+
const headers = new Headers()
|
|
45
|
+
headers.set('x-trpc-source', 'nextjs-react')
|
|
46
|
+
headers.set('Authorization', `Bearer ${authStore.state.accessToken}`)
|
|
47
|
+
return headers
|
|
48
|
+
},
|
|
49
|
+
}),*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The HTTP batch link is used to send multiple operations in a single HTTP request.
|
|
53
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
54
|
+
*/
|
|
55
|
+
httpBatchLink({
|
|
56
|
+
transformer: SuperJSON,
|
|
57
|
+
url: '/api/trpc',
|
|
58
|
+
// You can pass any HTTP headers you wish here
|
|
59
|
+
async headers(op) {
|
|
60
|
+
const headers = new Headers()
|
|
61
|
+
/**
|
|
62
|
+
* Check if there are any mutations in the operations list
|
|
63
|
+
*/
|
|
64
|
+
if (op.opList.some((o) => o.type === 'mutation')) {
|
|
65
|
+
/**
|
|
66
|
+
* Get the CSRF token, and set it in the headers
|
|
67
|
+
*/
|
|
68
|
+
const csrfToken = await getCsrfToken()
|
|
69
|
+
headers.set('x-csrf-token', csrfToken)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
headers.set('x-trpc-source', 'nextjs-react')
|
|
73
|
+
|
|
74
|
+
return headers
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
}),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
return trpcClient
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function makeQueryClient() {
|
|
85
|
+
return new QueryClient({
|
|
86
|
+
defaultOptions: {
|
|
87
|
+
queries: {
|
|
88
|
+
// With SSR, we usually want to set some default staleTime
|
|
89
|
+
// above 0 to avoid refetching immediately on the client
|
|
90
|
+
/**
|
|
91
|
+
* It's better to leave the staleTime to 0 to always fetch the latest data in a cms
|
|
92
|
+
*/
|
|
93
|
+
// staleTime: 3 * 1000,
|
|
94
|
+
/**
|
|
95
|
+
* We want to refetch on window focus in development only
|
|
96
|
+
*/
|
|
97
|
+
refetchOnWindowFocus: process.env.NODE_ENV === 'development' ? true : false,
|
|
98
|
+
retry: 1, // default: 3
|
|
99
|
+
},
|
|
100
|
+
dehydrate: {
|
|
101
|
+
serializeData: SuperJSON.serialize,
|
|
102
|
+
shouldDehydrateQuery: (query) => defaultShouldDehydrateQuery(query) || query.state.status === 'pending',
|
|
103
|
+
},
|
|
104
|
+
hydrate: {
|
|
105
|
+
deserializeData: SuperJSON.deserialize,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let browserQueryClient: QueryClient | undefined = undefined
|
|
112
|
+
|
|
113
|
+
function getQueryClient() {
|
|
114
|
+
if (typeof window === 'undefined') {
|
|
115
|
+
// Server: always make a new query client
|
|
116
|
+
return makeQueryClient()
|
|
117
|
+
} else {
|
|
118
|
+
// Browser: make a new query client if we don't already have one
|
|
119
|
+
// This is very important so we don't re-make a new client if React
|
|
120
|
+
// suspends during the initial render. This may not be needed if we
|
|
121
|
+
// have a suspense boundary BELOW the creation of the query client
|
|
122
|
+
if (!browserQueryClient) browserQueryClient = makeQueryClient()
|
|
123
|
+
return browserQueryClient
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default function Providers({ children }: { children: React.ReactNode }) {
|
|
128
|
+
// NOTE: Avoid useState when initializing the query client if you don't
|
|
129
|
+
// have a suspense boundary between this and the code that may
|
|
130
|
+
// suspend because React will throw away the client on the initial
|
|
131
|
+
// render if it suspends and there is no boundary
|
|
132
|
+
const queryClient = getQueryClient()
|
|
133
|
+
// const trpcClient = getTrpcClient()
|
|
134
|
+
const trpcClient = MakeTrpcClient()
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<QueryClientProvider client={queryClient}>
|
|
138
|
+
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
139
|
+
<SessionProvider
|
|
140
|
+
refetchOnWindowFocus={false}
|
|
141
|
+
refetchInterval={0}
|
|
142
|
+
refetchWhenOffline={false}>
|
|
143
|
+
<ModalProvider>
|
|
144
|
+
{children}
|
|
145
|
+
</ModalProvider>
|
|
146
|
+
</SessionProvider>
|
|
147
|
+
<ReactQueryDevtools initialIsOpen={false} />
|
|
148
|
+
</trpc.Provider>
|
|
149
|
+
</QueryClientProvider>
|
|
150
|
+
)
|
|
151
|
+
}
|