Skip to content

Commit

Permalink
It works!
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Dec 29, 2023
1 parent 82934f2 commit 2f68a96
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions vstc/src/db_command.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::{io::Write, process::exit, rc::Rc};

use actix_web::{
dev::Payload, web, App, FromRequest, HttpRequest, HttpResponse, HttpServer, Responder,
};
use actix_web::{dev, web, App, FromRequest, HttpRequest, HttpResponse, HttpServer, Responder};

use storage::{storage_head_ptr, SledBackend, Storage, StorageReader};
use valuescript_compiler::{assemble, compile_str, inline_valuescript};
Expand Down Expand Up @@ -154,8 +152,8 @@ fn db_call(path: &String, args: &[String]) {
.unwrap();
}

async fn get_body(req: &HttpRequest) -> Result<Val, actix_web::Error> {
let payload = web::Payload::from_request(req, &mut Payload::None).await?;
async fn get_body(req: &HttpRequest, mut payload: dev::Payload) -> Result<Val, actix_web::Error> {
let payload = web::Payload::from_request(req, &mut payload).await?;

let body = payload
.to_bytes_limited(1_024 * 1_024)
Expand All @@ -172,12 +170,16 @@ async fn get_body(req: &HttpRequest) -> Result<Val, actix_web::Error> {
}
}

async fn handle_request(req: HttpRequest, data: web::Data<String>) -> impl Responder {
async fn handle_request(
req: HttpRequest,
payload: web::Payload,
data: web::Data<String>,
) -> impl Responder {
let path = req.path();
let method = req.method();
let mut storage = Storage::new(SledBackend::open(data.as_ref()).unwrap());

let body = match get_body(&req).await {
let body = match get_body(&req, payload.into_inner()).await {
Ok(body) => body,
Err(e) => return e.into(),
};
Expand All @@ -190,7 +192,6 @@ async fn handle_request(req: HttpRequest, data: web::Data<String>) -> impl Respo
let fn_ = inline_valuescript(
r#"
export default function(req) {
console.log('req', req.path, req.method, req.body);
if ("handleRequest" in this) {
return this.handleRequest(req);
}
Expand Down

0 comments on commit 2f68a96

Please sign in to comment.