Build fixes: offline-safe fonts, Next.js API route type updates, TS strict errors resolved, MUI import cleanup, chat markdown wrapper, Azure OpenAI typing, caching key + chapter API id types, and misc error-logging typings.
This commit is contained in:
@@ -532,7 +532,7 @@ export default function BibleReaderNew() {
|
||||
return (
|
||||
<Box
|
||||
key={verse.id}
|
||||
ref={el => { if (el) verseRefs.current[verse.verseNum] = el }}
|
||||
ref={(el: HTMLDivElement | null) => { if (el) verseRefs.current[verse.verseNum] = el }}
|
||||
sx={{
|
||||
mb: 1,
|
||||
display: 'flex',
|
||||
@@ -1024,4 +1024,4 @@ export default function BibleReaderNew() {
|
||||
</Snackbar>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import {
|
||||
ListItem,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
ListItemSecondary
|
||||
} from '@mui/material'
|
||||
import {
|
||||
Bookmark,
|
||||
@@ -147,7 +146,7 @@ export default function BookmarksPage() {
|
||||
try {
|
||||
const endpoint = bookmark.type === 'chapter'
|
||||
? `/api/bookmarks/chapter?bookId=${bookmark.navigation.bookId}&chapterNum=${bookmark.navigation.chapterNum}&locale=${locale}`
|
||||
: `/api/bookmarks/verse?verseId=${bookmark.verse.id}&locale=${locale}`
|
||||
: `/api/bookmarks/verse?verseId=${bookmark.verse!.id}&locale=${locale}`
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'DELETE',
|
||||
@@ -398,4 +397,4 @@ export default function BookmarksPage() {
|
||||
</Container>
|
||||
</ProtectedRoute>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ interface SearchResult {
|
||||
verseId: string
|
||||
book: string
|
||||
bookId: string
|
||||
bookKey?: string
|
||||
chapter: number
|
||||
verse: number
|
||||
text: string
|
||||
@@ -202,7 +203,7 @@ export default function SearchPage() {
|
||||
try {
|
||||
const response = await fetch(`/api/bible/versions?locale=${locale}`)
|
||||
const data = await response.json()
|
||||
const versionList = data.versions || []
|
||||
const versionList: Array<{ id: string; name: string; abbreviation: string; isDefault: boolean }> = data.versions || []
|
||||
setVersions(versionList)
|
||||
|
||||
const defaultVersion = versionList.find(v => v.isDefault) || versionList[0]
|
||||
@@ -984,4 +985,4 @@ export default function SearchPage() {
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { 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) {
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
console.log('Books API called')
|
||||
const { searchParams } = new URL(request.url)
|
||||
|
||||
@@ -7,7 +7,7 @@ export const runtime = 'nodejs'
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const bookId = parseInt(searchParams.get('book') || '1')
|
||||
const bookId = searchParams.get('book') || ''
|
||||
const chapterNum = parseInt(searchParams.get('chapter') || '1')
|
||||
|
||||
// Check cache first
|
||||
|
||||
@@ -4,10 +4,10 @@ import { prisma } from '@/lib/db'
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const query = searchParams.get('q')
|
||||
const limit = parseInt(searchParams.get('limit') || '10')
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const query = searchParams.get('q')
|
||||
const limit = parseInt(searchParams.get('limit') || '10')
|
||||
|
||||
if (!query) {
|
||||
return NextResponse.json({ error: 'Termenul de căutare este obligatoriu' }, { status: 400 })
|
||||
@@ -34,7 +34,7 @@ export async function GET(request: Request) {
|
||||
const fallbackResults = await prisma.bibleVerse.findMany({
|
||||
where: {
|
||||
text: {
|
||||
contains: query,
|
||||
contains: query || '',
|
||||
mode: 'insensitive'
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const bookId = searchParams.get('bookId')
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const locale = (searchParams.get('locale') || 'ro').toLowerCase()
|
||||
@@ -30,4 +30,3 @@ export async function GET(request: NextRequest) {
|
||||
return NextResponse.json({ success: false, versions: [] }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ export async function POST(request: Request) {
|
||||
})
|
||||
|
||||
// Create a map of verseId -> bookmark
|
||||
const bookmarkMap = {}
|
||||
const bookmarkMap: Record<string, typeof bookmarks[number]> = {}
|
||||
bookmarks.forEach(bookmark => {
|
||||
bookmarkMap[bookmark.verseId] = bookmark
|
||||
})
|
||||
@@ -77,4 +77,4 @@ export async function POST(request: Request) {
|
||||
|
||||
return NextResponse.json({ error: messages.bookmarkError }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { z } from 'zod'
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
import { verifyToken } from '@/lib/auth'
|
||||
@@ -14,8 +14,8 @@ const updateConversationSchema = z.object({
|
||||
|
||||
// GET /api/chat/conversations/[id] - Get conversation with messages
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
request: Request,
|
||||
{ params }: any
|
||||
) {
|
||||
try {
|
||||
// Get user from authentication
|
||||
@@ -28,7 +28,7 @@ export async function GET(
|
||||
}
|
||||
|
||||
const token = authHeader.substring(7)
|
||||
const payload = verifyToken(token)
|
||||
const payload = await verifyToken(token)
|
||||
|
||||
if (!payload) {
|
||||
return NextResponse.json(
|
||||
@@ -100,8 +100,8 @@ export async function GET(
|
||||
|
||||
// PUT /api/chat/conversations/[id] - Update conversation
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
request: Request,
|
||||
{ params }: any
|
||||
) {
|
||||
try {
|
||||
// Get user from authentication
|
||||
@@ -114,7 +114,7 @@ export async function PUT(
|
||||
}
|
||||
|
||||
const token = authHeader.substring(7)
|
||||
const payload = verifyToken(token)
|
||||
const payload = await verifyToken(token)
|
||||
|
||||
if (!payload) {
|
||||
return NextResponse.json(
|
||||
@@ -198,8 +198,8 @@ export async function PUT(
|
||||
|
||||
// DELETE /api/chat/conversations/[id] - Delete conversation
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
request: Request,
|
||||
{ params }: any
|
||||
) {
|
||||
try {
|
||||
// Get user from authentication
|
||||
@@ -212,7 +212,7 @@ export async function DELETE(
|
||||
}
|
||||
|
||||
const token = authHeader.substring(7)
|
||||
const payload = verifyToken(token)
|
||||
const payload = await verifyToken(token)
|
||||
|
||||
if (!payload) {
|
||||
return NextResponse.json(
|
||||
@@ -263,4 +263,4 @@ export async function DELETE(
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { z } from 'zod'
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
import { verifyToken } from '@/lib/auth'
|
||||
@@ -19,7 +19,7 @@ const getConversationsSchema = z.object({
|
||||
})
|
||||
|
||||
// GET /api/chat/conversations - List user's conversations
|
||||
export async function GET(request: NextRequest) {
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
// Get user from authentication
|
||||
const authHeader = request.headers.get('authorization')
|
||||
@@ -31,7 +31,7 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
|
||||
const token = authHeader.substring(7)
|
||||
const payload = verifyToken(token)
|
||||
const payload = await verifyToken(token)
|
||||
|
||||
if (!payload) {
|
||||
return NextResponse.json(
|
||||
@@ -130,7 +130,7 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
|
||||
// POST /api/chat/conversations - Create new conversation
|
||||
export async function POST(request: NextRequest) {
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
// Get user from authentication
|
||||
const authHeader = request.headers.get('authorization')
|
||||
@@ -142,7 +142,7 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
const token = authHeader.substring(7)
|
||||
const payload = verifyToken(token)
|
||||
const payload = await verifyToken(token)
|
||||
|
||||
if (!payload) {
|
||||
return NextResponse.json(
|
||||
@@ -207,4 +207,4 @@ export async function POST(request: NextRequest) {
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { z } from 'zod'
|
||||
import { PrismaClient, ChatMessageRole } from '@prisma/client'
|
||||
import { searchBibleHybrid, BibleVerse } from '@/lib/vector-search'
|
||||
@@ -21,7 +21,7 @@ const chatRequestSchema = z.object({
|
||||
})).optional().default([])
|
||||
})
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { message, conversationId, locale, history } = chatRequestSchema.parse(body)
|
||||
@@ -40,7 +40,7 @@ export async function POST(request: NextRequest) {
|
||||
console.log('Chat API - userId extracted from token:', userId)
|
||||
} catch (error) {
|
||||
// Continue without authentication for backward compatibility
|
||||
console.log('Chat API - authentication failed:', error.message)
|
||||
console.log('Chat API - authentication failed:', (error as any)?.message || error)
|
||||
}
|
||||
} else {
|
||||
console.log('Chat API - no valid auth header')
|
||||
@@ -335,7 +335,7 @@ function calculateMessageRelevance(message: any, currentMessage: string, locale:
|
||||
const messageWords = msgContent.split(/\s+/)
|
||||
|
||||
for (const word of currentWords) {
|
||||
if (messageWords.some(mWord => mWord.includes(word) || word.includes(mWord))) {
|
||||
if (messageWords.some((mWord: string) => mWord.includes(word) || word.includes(mWord))) {
|
||||
score += 0.2
|
||||
}
|
||||
}
|
||||
@@ -401,7 +401,7 @@ function summarizeMessage(message: any): string {
|
||||
if (content.length <= 100) return content
|
||||
|
||||
// Extract key points and questions
|
||||
const sentences = content.split(/[.!?]+/).filter(s => s.trim().length > 10)
|
||||
const sentences = content.split(/[.!?]+/).filter((s: string) => s.trim().length > 10)
|
||||
if (sentences.length <= 2) return content
|
||||
|
||||
// Keep first and last sentence, or most important parts
|
||||
|
||||
@@ -18,7 +18,7 @@ export async function GET() {
|
||||
try {
|
||||
sampleUser = await prisma.$queryRaw`SELECT * FROM "User" LIMIT 1;`
|
||||
} catch (e) {
|
||||
sampleUser = { error: 'Could not fetch sample user: ' + e.message }
|
||||
sampleUser = { error: 'Could not fetch sample user: ' + ((e as any)?.message || e) }
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
@@ -29,7 +29,7 @@ export async function GET() {
|
||||
console.error('Schema debug error:', error)
|
||||
return NextResponse.json({
|
||||
error: 'Schema debug failed',
|
||||
details: error.message
|
||||
details: (error as any)?.message || error
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function POST(request: Request) {
|
||||
decodedWithoutVerification = jwt.decode(token, { complete: true })
|
||||
console.log('Debug: Token decoded without verification:', !!decodedWithoutVerification)
|
||||
} catch (e) {
|
||||
console.log('Debug: Token decode failed:', e.message)
|
||||
console.log('Debug: Token decode failed:', (e as any)?.message || e)
|
||||
}
|
||||
|
||||
// Try to verify
|
||||
@@ -33,8 +33,8 @@ export async function POST(request: Request) {
|
||||
verificationResult = jwt.verify(token, process.env.JWT_SECRET!)
|
||||
console.log('Debug: Token verification successful')
|
||||
} catch (e) {
|
||||
console.log('Debug: Token verification failed:', e.message)
|
||||
verificationResult = { error: e.message }
|
||||
console.log('Debug: Token verification failed:', (e as any)?.message || e)
|
||||
verificationResult = { error: (e as any)?.message || String(e) }
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
@@ -50,4 +50,4 @@ export async function POST(request: Request) {
|
||||
console.error('Debug endpoint error:', error)
|
||||
return NextResponse.json({ error: 'Debug failed' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,6 @@ export async function POST(request: Request) {
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('User debug error:', error)
|
||||
return NextResponse.json({ error: 'Debug failed', details: error.message }, { status: 500 })
|
||||
return NextResponse.json({ error: 'Debug failed', details: (error as any)?.message || error }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
request: Request,
|
||||
{ params }: any
|
||||
) {
|
||||
try {
|
||||
const prayerId = params.id
|
||||
@@ -143,4 +143,4 @@ export async function POST(
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { AzureOpenAI } from 'openai'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
@@ -11,7 +11,7 @@ const client = new AzureOpenAI({
|
||||
deployment: 'gpt-4o' // Using GPT-4 for better quality prayers
|
||||
})
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { prompt, category, locale } = await request.json()
|
||||
|
||||
@@ -120,4 +120,4 @@ export async function POST(request: NextRequest) {
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { z } from 'zod'
|
||||
import { prisma } from '@/lib/db'
|
||||
import { getServerSession } from 'next-auth'
|
||||
|
||||
const createPrayerSchema = z.object({
|
||||
title: z.string().min(1).max(200),
|
||||
@@ -10,7 +9,7 @@ const createPrayerSchema = z.object({
|
||||
isAnonymous: z.boolean().optional().default(false)
|
||||
})
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const category = searchParams.get('category')
|
||||
@@ -77,7 +76,7 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const validatedData = createPrayerSchema.parse(body)
|
||||
@@ -151,4 +150,4 @@ export async function POST(request: NextRequest) {
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const query = searchParams.get('q')
|
||||
|
||||
Reference in New Issue
Block a user