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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const query = searchParams.get('q')
|
||||
const limit = parseInt(searchParams.get('limit') || '10')
|
||||
try {
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -4,18 +4,7 @@ import React, { createContext, useContext, useEffect, useState, ReactNode } from
|
||||
import { useLocale } from 'next-intl'
|
||||
import { useStore } from '@/lib/store'
|
||||
import { isTokenExpired, clearExpiredToken } from '@/lib/auth/client'
|
||||
|
||||
interface User {
|
||||
id: string
|
||||
email: string
|
||||
name?: string
|
||||
role: string
|
||||
theme: string
|
||||
fontSize: string
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
lastLoginAt?: Date
|
||||
}
|
||||
import type { User } from '@/types'
|
||||
|
||||
interface AuthContextType {
|
||||
user: User | null
|
||||
|
||||
@@ -84,9 +84,11 @@ export function ChatInterface() {
|
||||
}`}
|
||||
>
|
||||
{msg.role === 'assistant' ? (
|
||||
<ReactMarkdown className="prose prose-sm max-w-none">
|
||||
<div className="prose prose-sm max-w-none">
|
||||
<ReactMarkdown>
|
||||
{msg.content}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
) : (
|
||||
<p>{msg.content}</p>
|
||||
)}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AzureOpenAI } from 'openai'
|
||||
import type { ChatCompletionMessageParam } from 'openai/resources/chat/completions'
|
||||
|
||||
const client = new AzureOpenAI({
|
||||
apiKey: process.env.AZURE_OPENAI_KEY!,
|
||||
@@ -7,7 +8,7 @@ const client = new AzureOpenAI({
|
||||
})
|
||||
|
||||
export async function generateChatResponse(
|
||||
messages: Array<{ role: string; content: string }>,
|
||||
messages: Array<{ role: 'user' | 'assistant'; content: string }>,
|
||||
verseContext?: string
|
||||
) {
|
||||
try {
|
||||
@@ -17,7 +18,7 @@ export async function generateChatResponse(
|
||||
model: process.env.AZURE_OPENAI_DEPLOYMENT || 'gpt-4',
|
||||
messages: [
|
||||
{ role: 'system', content: systemPrompt },
|
||||
...messages
|
||||
...messages as unknown as ChatCompletionMessageParam[]
|
||||
],
|
||||
temperature: 0.7,
|
||||
max_tokens: 1000
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function verifyToken(token: string) {
|
||||
console.log('Server: Token verification successful, userId:', payload.userId)
|
||||
return payload
|
||||
} catch (error) {
|
||||
console.log('Server: Token verification failed:', error.message)
|
||||
console.log('Server: Token verification failed:', (error as any)?.message || error)
|
||||
throw new Error('Invalid token')
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ export async function getUserFromToken(token: string) {
|
||||
}
|
||||
return user
|
||||
} catch (error) {
|
||||
console.log('Server: getUserFromToken error:', error.message)
|
||||
console.log('Server: getUserFromToken error:', (error as any)?.message || error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
2
lib/cache/index.ts
vendored
2
lib/cache/index.ts
vendored
@@ -57,7 +57,7 @@ export class CacheManager {
|
||||
}
|
||||
|
||||
// Helper methods for specific cache patterns
|
||||
static getChapterKey(bookId: number, chapterNum: number): string {
|
||||
static getChapterKey(bookId: string, chapterNum: number): string {
|
||||
return `chapter:${bookId}:${chapterNum}`
|
||||
}
|
||||
|
||||
|
||||
36
lib/fonts.ts
36
lib/fonts.ts
@@ -1,15 +1,25 @@
|
||||
import { Merriweather, Lato } from 'next/font/google'
|
||||
// Offline-safe font shim for builds without network access.
|
||||
// Provides the minimal shape used by the app: `.style.fontFamily` and `.variable`.
|
||||
|
||||
export const merriweather = Merriweather({
|
||||
subsets: ['latin'],
|
||||
weight: ['300', '400', '700', '900'],
|
||||
variable: '--font-merriweather',
|
||||
display: 'swap',
|
||||
})
|
||||
type FontShim = {
|
||||
style: { fontFamily: string }
|
||||
variable: string
|
||||
}
|
||||
|
||||
export const lato = Lato({
|
||||
subsets: ['latin'],
|
||||
weight: ['300', '400', '700', '900'],
|
||||
variable: '--font-lato',
|
||||
display: 'swap',
|
||||
})
|
||||
export const merriweather: FontShim = {
|
||||
// Prefer Merriweather if available on the system, otherwise common serif fallbacks
|
||||
style: {
|
||||
fontFamily: 'Merriweather, Georgia, "Times New Roman", Times, serif',
|
||||
},
|
||||
// Not using next/font CSS variable when offline
|
||||
variable: '',
|
||||
}
|
||||
|
||||
export const lato: FontShim = {
|
||||
// Prefer Lato if available on the system, otherwise robust system sans fallbacks
|
||||
style: {
|
||||
fontFamily:
|
||||
'Lato, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
|
||||
},
|
||||
variable: '',
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
".next/types/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
"node_modules",
|
||||
"scripts"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user