mirror of
https://github.com/0x5eal/sealz.git
synced 2024-12-12 04:50:35 +00:00
Commit committed....
This commit is contained in:
parent
0c4dff1695
commit
90679afadb
3 changed files with 25 additions and 22 deletions
|
@ -1,7 +1,8 @@
|
|||
use rand::Rng;
|
||||
use serde_json::Value;
|
||||
use std::{fs, string::String};
|
||||
use tide::{prelude::*, Body, Request, Response, Result};
|
||||
use tide::{prelude::*, Request, Result};
|
||||
use crate::utils::{build_response, ResponseOptions};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(default)]
|
||||
|
@ -31,27 +32,6 @@ fn get_random_seal(seal_type: String) -> std::result::Result<String, std::io::Er
|
|||
Ok((&seals_vec[rand::thread_rng().gen_range(0..seals_vec.len())]).clone())
|
||||
}
|
||||
|
||||
struct ResponseOptions<T>
|
||||
where
|
||||
T: Into<Body>,
|
||||
{
|
||||
status: u16,
|
||||
content_type: &'static str,
|
||||
contents: T,
|
||||
}
|
||||
|
||||
fn build_response<T>(opts: ResponseOptions<T>) -> Response
|
||||
where
|
||||
T: Into<Body>,
|
||||
{
|
||||
let mut resp = Response::new(opts.status);
|
||||
|
||||
resp.append_header("Content-Type", opts.content_type);
|
||||
resp.set_body(opts.contents);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
pub async fn handler(req: Request<()>) -> Result {
|
||||
let value_type = req.query::<Params>().unwrap().r#type;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
use framework::{setup_server, ServerOptions, Server};
|
||||
|
||||
mod api;
|
||||
pub mod utils;
|
||||
|
||||
pub async fn init() -> tide::Result<Server> {
|
||||
let server = setup_server(ServerOptions {
|
||||
|
|
22
backend/src/utils.rs
Normal file
22
backend/src/utils.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use tide::{Response, Body};
|
||||
|
||||
pub struct ResponseOptions<T>
|
||||
where
|
||||
T: Into<Body>,
|
||||
{
|
||||
pub status: u16,
|
||||
pub content_type: &'static str,
|
||||
pub contents: T,
|
||||
}
|
||||
|
||||
pub fn build_response<T>(opts: ResponseOptions<T>) -> Response
|
||||
where
|
||||
T: Into<Body>,
|
||||
{
|
||||
let mut resp = Response::new(opts.status);
|
||||
|
||||
resp.append_header("Content-Type", opts.content_type);
|
||||
resp.set_body(opts.contents);
|
||||
|
||||
return resp;
|
||||
}
|
Loading…
Reference in a new issue