| 760 | * access is granted. |
| 761 | */ |
| 762 | export async function assertToolFileAccess( |
| 763 | key: unknown, |
| 764 | userId: string, |
| 765 | requestId: string, |
| 766 | routeLogger: ReturnType<typeof createLogger> |
| 767 | ): Promise<NextResponse | null> { |
| 768 | if (typeof key !== 'string' || key.length === 0) { |
| 769 | routeLogger.warn(`[${requestId}] File access check rejected: missing key`) |
| 770 | return NextResponse.json({ success: false, error: 'File not found' }, { status: 404 }) |
| 771 | } |
| 772 | const hasAccess = await verifyFileAccess(key, userId) |
| 773 | if (!hasAccess) { |
| 774 | routeLogger.warn(`[${requestId}] File access denied for user`, { userId, key }) |
| 775 | return NextResponse.json({ success: false, error: 'File not found' }, { status: 404 }) |
| 776 | } |
| 777 | return null |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Get chat storage configuration based on current storage provider |