aki-008
commited on
Commit
·
4f1509d
1
Parent(s):
bcebe14
fix: serve pdf via direct secure link to bypass brave shield
Browse files
Backend/app/api/v1/endpoints/notes.py
CHANGED
|
@@ -335,7 +335,6 @@ async def get_pdf_content(
|
|
| 335 |
db: AsyncSession = Depends(get_db),
|
| 336 |
current_user: User = Depends(get_current_user)
|
| 337 |
):
|
| 338 |
-
"""Serve the raw PDF binary data for the viewer."""
|
| 339 |
result = await db.execute(
|
| 340 |
select(PDFData).where(PDFData.id == pdf_id, PDFData.user_id == current_user.id)
|
| 341 |
)
|
|
@@ -344,8 +343,16 @@ async def get_pdf_content(
|
|
| 344 |
if not pdf:
|
| 345 |
raise HTTPException(status_code=404, detail="Note not found")
|
| 346 |
|
| 347 |
-
#
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
|
| 350 |
|
| 351 |
# -------------------------
|
|
|
|
| 335 |
db: AsyncSession = Depends(get_db),
|
| 336 |
current_user: User = Depends(get_current_user)
|
| 337 |
):
|
|
|
|
| 338 |
result = await db.execute(
|
| 339 |
select(PDFData).where(PDFData.id == pdf_id, PDFData.user_id == current_user.id)
|
| 340 |
)
|
|
|
|
| 343 |
if not pdf:
|
| 344 |
raise HTTPException(status_code=404, detail="Note not found")
|
| 345 |
|
| 346 |
+
# FIX: Add 'Content-Disposition: inline' to tell browser to render it
|
| 347 |
+
headers = {
|
| 348 |
+
"Content-Disposition": f"inline; filename={pdf.filename}"
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
return Response(
|
| 352 |
+
content=pdf.pdf_blob,
|
| 353 |
+
media_type="application/pdf",
|
| 354 |
+
headers=headers
|
| 355 |
+
)
|
| 356 |
|
| 357 |
|
| 358 |
# -------------------------
|
Frontend/src/pages/note.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import ReactMarkdown from "react-markdown";
|
| 2 |
import remarkGfm from "remark-gfm";
|
| 3 |
import React, { useEffect, useState, useRef, useCallback } from "react";
|
|
|
|
| 4 |
import {
|
| 5 |
Upload,
|
| 6 |
Menu,
|
|
@@ -186,18 +187,12 @@ const Notes: React.FC = () => {
|
|
| 186 |
const handleNoteSelect = async (note: Note) => {
|
| 187 |
if (editingNoteId === note.id) return;
|
| 188 |
setCurrentNote(note);
|
| 189 |
-
setPdfUrl(null);
|
| 190 |
setMessages([]);
|
| 191 |
setSessionId(null);
|
| 192 |
setIsChatOpen(true);
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
const url = URL.createObjectURL(blob);
|
| 197 |
-
setPdfUrl(url);
|
| 198 |
-
} catch (error) {
|
| 199 |
-
console.error("Failed to load PDF", error);
|
| 200 |
-
}
|
| 201 |
|
| 202 |
try {
|
| 203 |
const existingSessions = await fetchSessions(note.id);
|
|
|
|
| 1 |
import ReactMarkdown from "react-markdown";
|
| 2 |
import remarkGfm from "remark-gfm";
|
| 3 |
import React, { useEffect, useState, useRef, useCallback } from "react";
|
| 4 |
+
import { getNoteContentUrl } from "../api/notesService";
|
| 5 |
import {
|
| 6 |
Upload,
|
| 7 |
Menu,
|
|
|
|
| 187 |
const handleNoteSelect = async (note: Note) => {
|
| 188 |
if (editingNoteId === note.id) return;
|
| 189 |
setCurrentNote(note);
|
|
|
|
| 190 |
setMessages([]);
|
| 191 |
setSessionId(null);
|
| 192 |
setIsChatOpen(true);
|
| 193 |
|
| 194 |
+
const secureUrl = getNoteContentUrl(note.id);
|
| 195 |
+
setPdfUrl(secureUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
try {
|
| 198 |
const existingSessions = await fetchSessions(note.id);
|