Skip to content

Commit

Permalink
Cleanup fetch endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed Sep 19, 2023
1 parent 2c02328 commit 6d6e0fe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugin/src/ApiContext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function ApiContext:open(id)
end

function ApiContext:fetch(ids: { string })
local url = ("%s/api/fetch/%s"):format(self.__baseUrl, table.concat(ids, ","))
local url = ("%s/api/fetch"):format(self.__baseUrl)
local requestBody = {
sessionId = self.__sessionId,
idList = ids,
Expand Down
6 changes: 2 additions & 4 deletions src/web/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ pub async fn call(serve_session: Arc<ServeSession>, request: Request<Body>) -> R

(&Method::POST, "/api/write") => service.handle_api_write(request).await,

(&Method::POST, path) if path.starts_with("/api/fetch/") => {
service.handle_api_fetch_get(request).await
}
(&Method::POST, "/api/fetch") => service.handle_api_fetch_post(request).await,

(_method, path) => json(
ErrorResponse::not_found(format!("Route not found: {}", path)),
Expand Down Expand Up @@ -288,7 +286,7 @@ impl ApiService {
})
}

async fn handle_api_fetch_get(&self, request: Request<Body>) -> Response<Body> {
async fn handle_api_fetch_post(&self, request: Request<Body>) -> Response<Body> {
let body = body::to_bytes(request.into_body()).await.unwrap();

let request: FetchRequest = match serde_json::from_slice(&body) {
Expand Down
3 changes: 2 additions & 1 deletion src/web/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,15 @@ pub struct OpenResponse {
pub session_id: SessionId,
}

/// A request POSTed to /api/fetch
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FetchRequest {
pub session_id: SessionId,
pub id_list: Vec<Ref>,
}

/// Response body from GET /api/fetch/{ids}
/// Response body from POST /api/fetch
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FetchResponse<'a> {
Expand Down

0 comments on commit 6d6e0fe

Please sign in to comment.