Skip to content

Commit

Permalink
update compression
Browse files Browse the repository at this point in the history
  • Loading branch information
stackdump committed Mar 9, 2024
1 parent 5e86b02 commit 1fbdbe8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::error::Error;

use clap::Parser;
use tokio::task;

Expand Down
44 changes: 2 additions & 42 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use tower_http::trace::TraceLayer;

use crate::storage::{Storage, Zblob};


async fn src_handler(
Path(ipfs_cid): Path<String>,
state: State<Arc<Mutex<Storage>>>,
Expand Down Expand Up @@ -162,6 +161,7 @@ async fn index_handler(
}

const STATIC_DIR: Dir = include_dir!("static");

async fn serve_static(filepath: Path<String>) -> impl IntoResponse {
let filepath = if filepath.as_str().is_empty() {
"index.html".to_string()
Expand Down Expand Up @@ -193,44 +193,4 @@ pub fn app() -> Router {
.route("/", get(|| async { Redirect::to("/p/") }))
.layer(TraceLayer::new_for_http())
.with_state(state)
}

#[cfg(test)]
mod tests {
use pflow_metamodel::compression::unzip_encoded;
use pflow_metamodel::petri_net::PetriNet;
use crate::fixtures::INHIBIT_TEST;
use crate::server::string_to_zblob;
use crate::storage::Storage;

#[test]
fn test_serve_by_ipfs_cid() {
let p = string_to_zblob(Option::from(&INHIBIT_TEST.to_string()));
let net = PetriNet::from_json(unzip_encoded(&p.base64_zipped, "model.json").unwrap()).unwrap();
let store = Storage::new("pflow.db").unwrap();
store.reset_db(true).unwrap();
let z = string_to_zblob(Option::from(&INHIBIT_TEST.to_string()));
assert_eq!(z.ipfs_cid, "zb2rhjSDP7JbLBEjfeThBdnE2va1sTahmDkooKB9VYGD67tf5");
let store = Storage::new("pflow.db").unwrap();

for i in 0..3 {
match store.create_or_retrieve(
"pflow_models",
&z.ipfs_cid,
&z.base64_zipped,
&z.title,
&z.description,
&z.keywords,
&z.referrer,
) {
Ok(zblob) => {
assert_eq!(zblob.ipfs_cid, z.ipfs_cid);
assert_eq!(zblob.id, 1);
}
Err(e) => {
panic!("Failed to create zblob: {}", e);
}
}
}
}
}
}
7 changes: 3 additions & 4 deletions src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::str;

use rusqlite::{Connection, params, Result};
use serde::{Serialize, Serializer};

use pflow_metamodel::oid::Oid;
use pflow_metamodel::compression::decompress_brotli_decode;
use pflow_metamodel::oid::Oid;
use pflow_metamodel::petri_net::PetriNet;
use rusqlite::{Connection, params, Result};
use serde::{Serialize, Serializer};

#[derive(Debug, Clone, Serialize)]
pub struct Zblob {
Expand Down

0 comments on commit 1fbdbe8

Please sign in to comment.