Skip to content

Commit 2921079

Browse files
authored
supply document name as part of the request body rather than query (#186)
1 parent 4bd07c0 commit 2921079

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

ragna/deploy/_api/core.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Annotated, Any, Iterator, Type, cast
55

66
import aiofiles
7-
from fastapi import Depends, FastAPI, Form, HTTPException, Request, UploadFile
7+
from fastapi import Body, Depends, FastAPI, Form, HTTPException, Request, UploadFile
88
from fastapi.middleware.cors import CORSMiddleware
99
from fastapi.responses import JSONResponse
1010

@@ -112,10 +112,10 @@ def get_session() -> Iterator[database.Session]:
112112
with make_session() as session: # type: ignore[attr-defined]
113113
yield session
114114

115-
@app.get("/document")
116-
async def get_document_upload_info(
115+
@app.post("/document")
116+
async def create_document_upload_info(
117117
user: UserDependency,
118-
name: str,
118+
name: Annotated[str, Body(..., embed=True)],
119119
) -> schemas.DocumentUploadInfo:
120120
with get_session() as session:
121121
document = schemas.Document(name=name)
@@ -127,7 +127,7 @@ async def get_document_upload_info(
127127
)
128128
return schemas.DocumentUploadInfo(url=url, data=data, document=document)
129129

130-
@app.post("/document")
130+
@app.put("/document")
131131
async def upload_document(
132132
token: Annotated[str, Form()], file: UploadFile
133133
) -> schemas.Document:

ragna/deploy/_ui/resources/upload.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ function upload(files, token, informationsEndpoint, final_callback) {
77
}
88

99
async function uploadFile(file, token, informationEndpoint) {
10-
const response = await fetch(`${informationEndpoint}?name=${file.name}`, {
11-
headers: { Authorization: `Bearer ${token}` },
10+
const response = await fetch(informationEndpoint, {
11+
method: "POST",
12+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
13+
body: JSON.stringify({ name: file.name }),
1214
});
1315
const documentInfo = await response.json();
1416

@@ -19,7 +21,7 @@ async function uploadFile(file, token, informationEndpoint) {
1921
body.append("file", file);
2022

2123
await fetch(documentInfo.url, {
22-
method: "POST",
24+
method: "PUT",
2325
body: body,
2426
});
2527

scripts/add_chats.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def main():
3535
for i in range(5):
3636
name = f"document{i}.txt"
3737
document_info = (
38-
client.get("/document", params={"name": name}).raise_for_status().json()
38+
client.post("/document", json={"name": name}).raise_for_status().json()
3939
)
40-
client.post(
40+
client.put(
4141
document_info["url"],
4242
data=document_info["data"],
4343
files={"file": f"Content of {name}".encode()},

tests/deploy/api/test_e2e.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ def check_api(config):
5050
assert client.get("/chats").raise_for_status().json() == []
5151

5252
document_info = (
53-
client.get("/document", params={"name": document_path.name})
53+
client.post("/document", json={"name": document_path.name})
5454
.raise_for_status()
5555
.json()
5656
)
5757
document = document_info["document"]
5858
assert document["name"] == document_path.name
5959

6060
with open(document_path, "rb") as file:
61-
client.post(
61+
client.put(
6262
document_info["url"],
6363
data=document_info["data"],
6464
files={"file": file},

0 commit comments

Comments
 (0)