Fix Edge-incompatible middleware; set Node runtime on Prisma/pg routes; add full Romanian Bible import + converter; import data JSON; resync RO bookKeys; stabilize /api/bible/books locale fallback; restart dev server.
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
Share,
|
||||
} from '@mui/icons-material'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useTranslations, useLocale } from 'next-intl'
|
||||
|
||||
interface BibleVerse {
|
||||
id: string
|
||||
@@ -44,26 +45,33 @@ interface BibleChapter {
|
||||
}
|
||||
|
||||
interface BibleBook {
|
||||
id: number
|
||||
id: string
|
||||
name: string
|
||||
testament: string
|
||||
orderNum: number
|
||||
bookKey: string
|
||||
chapters: BibleChapter[]
|
||||
}
|
||||
|
||||
export default function BiblePage() {
|
||||
const theme = useTheme()
|
||||
const t = useTranslations('pages.bible')
|
||||
const locale = useLocale()
|
||||
const [books, setBooks] = useState<BibleBook[]>([])
|
||||
const [selectedBook, setSelectedBook] = useState<number>(1)
|
||||
const [selectedBook, setSelectedBook] = useState<string>('')
|
||||
const [selectedChapter, setSelectedChapter] = useState<number>(1)
|
||||
const [verses, setVerses] = useState<BibleVerse[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
// Fetch available books
|
||||
useEffect(() => {
|
||||
fetch('/api/bible/books')
|
||||
fetch(`/api/bible/books?locale=${locale}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
setBooks(data.books || [])
|
||||
if (data.books && data.books.length > 0) {
|
||||
setSelectedBook(data.books[0].id)
|
||||
}
|
||||
setLoading(false)
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -120,7 +128,7 @@ export default function BiblePage() {
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 2 }}>
|
||||
<CircularProgress size={48} />
|
||||
<Typography variant="h6" color="text.secondary">
|
||||
Se încarcă cărțile...
|
||||
{t('loading')}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Container>
|
||||
@@ -136,10 +144,10 @@ export default function BiblePage() {
|
||||
<Box sx={{ mb: 4, textAlign: 'center' }}>
|
||||
<Typography variant="h3" component="h1" gutterBottom>
|
||||
<MenuBook sx={{ fontSize: 40, mr: 2, verticalAlign: 'middle' }} />
|
||||
Citește Biblia
|
||||
{t('title')}
|
||||
</Typography>
|
||||
<Typography variant="body1" color="text.secondary">
|
||||
Explorează Scriptura cu o interfață modernă și intuitivă
|
||||
{t('subtitle')}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
@@ -149,16 +157,16 @@ export default function BiblePage() {
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
Selectează cartea
|
||||
{t('selectBook')}
|
||||
</Typography>
|
||||
|
||||
<FormControl fullWidth sx={{ mb: 2 }}>
|
||||
<InputLabel>Cartea</InputLabel>
|
||||
<InputLabel>{t('book')}</InputLabel>
|
||||
<Select
|
||||
value={selectedBook}
|
||||
label="Cartea"
|
||||
label={t('book')}
|
||||
onChange={(e) => {
|
||||
setSelectedBook(Number(e.target.value))
|
||||
setSelectedBook(e.target.value)
|
||||
setSelectedChapter(1)
|
||||
}}
|
||||
>
|
||||
@@ -171,15 +179,15 @@ export default function BiblePage() {
|
||||
</FormControl>
|
||||
|
||||
<FormControl fullWidth>
|
||||
<InputLabel>Capitolul</InputLabel>
|
||||
<InputLabel>{t('chapter')}</InputLabel>
|
||||
<Select
|
||||
value={selectedChapter}
|
||||
label="Capitolul"
|
||||
label={t('chapter')}
|
||||
onChange={(e) => setSelectedChapter(Number(e.target.value))}
|
||||
>
|
||||
{Array.from({ length: maxChapters }, (_, i) => (
|
||||
<MenuItem key={i + 1} value={i + 1}>
|
||||
Capitolul {i + 1}
|
||||
{t('chapter')} {i + 1}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
@@ -208,7 +216,7 @@ export default function BiblePage() {
|
||||
{currentBook?.name || 'Geneza'} {selectedChapter}
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{verses.length} versete
|
||||
{verses.length} {t('verses')}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
@@ -218,14 +226,14 @@ export default function BiblePage() {
|
||||
variant="outlined"
|
||||
size="small"
|
||||
>
|
||||
Salvează
|
||||
{t('save')}
|
||||
</Button>
|
||||
<Button
|
||||
startIcon={<Share />}
|
||||
variant="outlined"
|
||||
size="small"
|
||||
>
|
||||
Partajează
|
||||
{t('share')}
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -280,7 +288,7 @@ export default function BiblePage() {
|
||||
</Box>
|
||||
) : (
|
||||
<Typography textAlign="center" color="text.secondary">
|
||||
Nu s-au găsit versete pentru această selecție.
|
||||
{t('noVerses')}
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
@@ -291,7 +299,7 @@ export default function BiblePage() {
|
||||
onClick={handlePreviousChapter}
|
||||
disabled={selectedBook === 1 && selectedChapter === 1}
|
||||
>
|
||||
Capitolul anterior
|
||||
{t('previousChapter')}
|
||||
</Button>
|
||||
|
||||
<Typography variant="body2" color="text.secondary" sx={{ alignSelf: 'center' }}>
|
||||
@@ -303,7 +311,7 @@ export default function BiblePage() {
|
||||
onClick={handleNextChapter}
|
||||
disabled={selectedBook === books.length && selectedChapter === maxChapters}
|
||||
>
|
||||
Capitolul următor
|
||||
{t('nextChapter')}
|
||||
</Button>
|
||||
</Box>
|
||||
</CardContent>
|
||||
|
||||
@@ -2,6 +2,8 @@ import { NextResponse } from 'next/server'
|
||||
import { validateUser, generateToken } from '@/lib/auth'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { email, password } = await request.json()
|
||||
@@ -43,4 +45,4 @@ export async function POST(request: Request) {
|
||||
console.error('Login error:', error)
|
||||
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { getUserFromToken } from '@/lib/auth'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const authHeader = request.headers.get('authorization')
|
||||
@@ -20,4 +22,4 @@ export async function GET(request: Request) {
|
||||
console.error('User validation error:', error)
|
||||
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import { prisma } from '@/lib/db'
|
||||
import { userRegistrationSchema } from '@/lib/validation'
|
||||
import { z } from 'zod'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
@@ -47,4 +49,4 @@ export async function POST(request: Request) {
|
||||
}
|
||||
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,64 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
// Ensure this route runs on the Node.js runtime (Prisma requires Node)
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
console.log('Books API called')
|
||||
const { searchParams } = new URL(request.url)
|
||||
const locale = searchParams.get('locale') || 'ro'
|
||||
const versionAbbr = searchParams.get('version') // Optional specific version
|
||||
console.log('Locale:', locale, 'Version:', versionAbbr)
|
||||
|
||||
// Get the appropriate Bible version
|
||||
let bibleVersion
|
||||
const langCandidates = Array.from(new Set([locale, locale.toLowerCase(), locale.toUpperCase()]))
|
||||
if (versionAbbr) {
|
||||
// Use specific version if provided
|
||||
bibleVersion = await prisma.bibleVersion.findFirst({
|
||||
where: {
|
||||
abbreviation: versionAbbr,
|
||||
language: { in: langCandidates }
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// Try default version for the language
|
||||
bibleVersion = await prisma.bibleVersion.findFirst({
|
||||
where: {
|
||||
language: { in: langCandidates },
|
||||
isDefault: true
|
||||
}
|
||||
})
|
||||
// Fallback: any version for the language
|
||||
if (!bibleVersion) {
|
||||
bibleVersion = await prisma.bibleVersion.findFirst({
|
||||
where: { language: { in: langCandidates } },
|
||||
orderBy: { createdAt: 'asc' }
|
||||
})
|
||||
}
|
||||
// Fallback: use English default if requested locale not found
|
||||
if (!bibleVersion && locale !== 'en') {
|
||||
bibleVersion = await prisma.bibleVersion.findFirst({
|
||||
where: { language: 'en', isDefault: true }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (!bibleVersion) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: `No Bible version found for language: ${locale}`,
|
||||
books: []
|
||||
}, { status: 404 })
|
||||
}
|
||||
|
||||
// Get books for this version
|
||||
const books = await prisma.bibleBook.findMany({
|
||||
where: {
|
||||
versionId: bibleVersion.id
|
||||
},
|
||||
orderBy: {
|
||||
orderNum: 'asc'
|
||||
},
|
||||
@@ -11,6 +66,13 @@ export async function GET(request: NextRequest) {
|
||||
chapters: {
|
||||
orderBy: {
|
||||
chapterNum: 'asc'
|
||||
},
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
verses: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +80,24 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
books: books
|
||||
version: {
|
||||
id: bibleVersion.id,
|
||||
name: bibleVersion.name,
|
||||
abbreviation: bibleVersion.abbreviation,
|
||||
language: bibleVersion.language
|
||||
},
|
||||
books: books.map(book => ({
|
||||
id: book.id,
|
||||
name: book.name,
|
||||
testament: book.testament,
|
||||
orderNum: book.orderNum,
|
||||
bookKey: book.bookKey,
|
||||
chapters: book.chapters.map(chapter => ({
|
||||
id: chapter.id,
|
||||
chapterNum: chapter.chapterNum,
|
||||
verseCount: chapter._count.verses
|
||||
}))
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching books:', error)
|
||||
@@ -31,4 +110,4 @@ export async function GET(request: NextRequest) {
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
import { CacheManager } from '@/lib/cache'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
@@ -57,4 +59,4 @@ export async function GET(request: Request) {
|
||||
console.error('Chapter fetch error:', error)
|
||||
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
@@ -64,4 +66,4 @@ export async function GET(request: Request) {
|
||||
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
@@ -18,18 +20,27 @@ export async function GET(request: NextRequest) {
|
||||
)
|
||||
}
|
||||
|
||||
// Find the chapter
|
||||
// Find the chapter (bookId is now a string UUID)
|
||||
const chapterRecord = await prisma.bibleChapter.findFirst({
|
||||
where: {
|
||||
bookId: parseInt(bookId),
|
||||
bookId: bookId,
|
||||
chapterNum: parseInt(chapter)
|
||||
},
|
||||
include: {
|
||||
book: {
|
||||
include: {
|
||||
version: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (!chapterRecord) {
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
verses: []
|
||||
verses: [],
|
||||
book: null,
|
||||
chapter: null
|
||||
})
|
||||
}
|
||||
|
||||
@@ -45,6 +56,22 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
book: {
|
||||
id: chapterRecord.book.id,
|
||||
name: chapterRecord.book.name,
|
||||
testament: chapterRecord.book.testament,
|
||||
orderNum: chapterRecord.book.orderNum
|
||||
},
|
||||
chapter: {
|
||||
id: chapterRecord.id,
|
||||
chapterNum: chapterRecord.chapterNum
|
||||
},
|
||||
version: {
|
||||
id: chapterRecord.book.version.id,
|
||||
name: chapterRecord.book.version.name,
|
||||
abbreviation: chapterRecord.book.version.abbreviation,
|
||||
language: chapterRecord.book.version.language
|
||||
},
|
||||
verses: verses.map(verse => ({
|
||||
id: verse.id,
|
||||
verseNum: verse.verseNum,
|
||||
@@ -62,4 +89,4 @@ export async function GET(request: NextRequest) {
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
import { getUserFromToken } from '@/lib/auth'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const authHeader = request.headers.get('authorization')
|
||||
@@ -98,4 +100,4 @@ export async function POST(request: Request) {
|
||||
console.error('Bookmark creation error:', error)
|
||||
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import { z } from 'zod'
|
||||
import { searchBibleHybrid, BibleVerse } from '@/lib/vector-search'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
const chatRequestSchema = z.object({
|
||||
message: z.string().min(1),
|
||||
locale: z.string().optional().default('ro'),
|
||||
@@ -158,4 +160,4 @@ Current question: ${message}`
|
||||
|
||||
return fallbackResponses[locale as keyof typeof fallbackResponses] || fallbackResponses.en
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
// Check database connection
|
||||
@@ -26,4 +28,4 @@ export async function GET() {
|
||||
{ status: 503 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
@@ -168,4 +170,4 @@ export async function GET(request: NextRequest) {
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user