Compare commits
5 commits
main
...
renovate/l
Author | SHA1 | Date | |
---|---|---|---|
557a2e834d | |||
5026fce52c | |||
ab7b5524cf | |||
d5496d0a71 | |||
8495d0ad23 |
19 changed files with 7629 additions and 19773 deletions
|
@ -1,2 +0,0 @@
|
||||||
[unstable]
|
|
||||||
bindeps = true
|
|
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1,7 +1,7 @@
|
||||||
/target
|
/target
|
||||||
.env
|
.env
|
||||||
/config.toml
|
config.toml
|
||||||
.direnv
|
.direnv
|
||||||
/target
|
target/
|
||||||
/target-bin
|
target-bin/
|
||||||
secrets/
|
secrets/
|
1228
Cargo.lock
generated
1228
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
16
Cargo.toml
16
Cargo.toml
|
@ -1,10 +1,8 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"chir-rs-castore",
|
"chir-rs-castore", "chir-rs-client",
|
||||||
"chir-rs-client",
|
|
||||||
"chir-rs-config",
|
"chir-rs-config",
|
||||||
"chir-rs-db",
|
"chir-rs-db",
|
||||||
"chir-rs-fe",
|
|
||||||
"chir-rs-gemini",
|
"chir-rs-gemini",
|
||||||
"chir-rs-http",
|
"chir-rs-http",
|
||||||
"chir-rs-http-api",
|
"chir-rs-http-api",
|
||||||
|
@ -37,11 +35,7 @@ sentry = { version = "0.34.0", default-features = false, features = [
|
||||||
] }
|
] }
|
||||||
sentry-eyre = "0.2.0"
|
sentry-eyre = "0.2.0"
|
||||||
sentry-tracing = { version = "0.34.0", features = ["backtrace"] }
|
sentry-tracing = { version = "0.34.0", features = ["backtrace"] }
|
||||||
tokio = { version = "1.41.1", features = [
|
tokio = { version = "1.41.1", features = ["macros", "rt-multi-thread", "signal"] }
|
||||||
"macros",
|
|
||||||
"rt-multi-thread",
|
|
||||||
"signal",
|
|
||||||
] }
|
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
tracing-error = "0.2.0"
|
tracing-error = "0.2.0"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
|
||||||
|
@ -100,3 +94,9 @@ codegen-units = 1
|
||||||
lto = true
|
lto = true
|
||||||
debug = "full"
|
debug = "full"
|
||||||
strip = "none"
|
strip = "none"
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 2
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 1
|
||||||
|
|
|
@ -15,7 +15,6 @@ eyre = "0.6.12"
|
||||||
stretto = { version = "0.8.4", features = ["async"] }
|
stretto = { version = "0.8.4", features = ["async"] }
|
||||||
tokio = { version = "1.41.1", features = ["fs"] }
|
tokio = { version = "1.41.1", features = ["fs"] }
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
|
|
||||||
[lints.rust]
|
[lints.rust]
|
||||||
deprecated-safe = "forbid"
|
deprecated-safe = "forbid"
|
||||||
elided_lifetimes_in_paths = "warn"
|
elided_lifetimes_in_paths = "warn"
|
||||||
|
|
|
@ -97,94 +97,100 @@ impl CaStore {
|
||||||
let string_id = lexicographic_base64::encode(id.to_be_bytes());
|
let string_id = lexicographic_base64::encode(id.to_be_bytes());
|
||||||
let source_fname = format!("temp/{string_id}");
|
let source_fname = format!("temp/{string_id}");
|
||||||
|
|
||||||
/*info!("Starting multipart upload {id}");
|
let mut buf = BytesMut::with_capacity(5_000_000);
|
||||||
let multipart_result = self
|
reader.read_buf(&mut buf).await?;
|
||||||
.client
|
|
||||||
.create_multipart_upload()
|
|
||||||
.bucket(&*self.bucket)
|
|
||||||
.key(&source_fname)
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.with_context(|| format!("Creating multipart request for Request ID{id}"))?;
|
|
||||||
|
|
||||||
let mut buf = BytesMut::with_capacity(16 * 1024 * 1024); // 16MiB byte buffer for the file
|
|
||||||
let hasher = Arc::new(Mutex::new(Hasher::new()));
|
let hasher = Arc::new(Mutex::new(Hasher::new()));
|
||||||
|
|
||||||
let mut i = 1;
|
let hash = if buf.len() >= 5_000_000 {
|
||||||
let mut completed_multipart_upload_builder = CompletedMultipartUpload::builder();
|
info!("Starting multipart upload {id}");
|
||||||
|
let multipart_result = self
|
||||||
loop {
|
|
||||||
buf.clear();
|
|
||||||
reader.read_buf(&mut buf).await.context("Reading chunk")?;
|
|
||||||
if buf.is_empty() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!("Uploading part {i} for multipart upload {id}");
|
|
||||||
|
|
||||||
let buf2 = buf.clone();
|
|
||||||
let hasher = Arc::clone(&hasher);
|
|
||||||
let hasher_job = spawn_blocking(move || {
|
|
||||||
hasher.blocking_lock().update_rayon(&buf2);
|
|
||||||
});
|
|
||||||
|
|
||||||
let part_upload_fut = self
|
|
||||||
.client
|
.client
|
||||||
.upload_part()
|
.create_multipart_upload()
|
||||||
.bucket(&*self.bucket)
|
.bucket(&*self.bucket)
|
||||||
.key(&source_fname)
|
.key(&source_fname)
|
||||||
.set_upload_id(multipart_result.upload_id.clone())
|
.send()
|
||||||
.body(ByteStream::from(buf.to_vec()))
|
.await
|
||||||
.part_number(i)
|
.with_context(|| format!("Creating multipart request for Request ID{id}"))?;
|
||||||
.send();
|
|
||||||
|
|
||||||
let ((), part_upload_result) = try_join!(
|
let mut reader = buf.chain(reader);
|
||||||
async { hasher_job.await.context("Awaiting hasher job") },
|
|
||||||
async { part_upload_fut.await.context("Awaiting uploader job") }
|
let mut buf = BytesMut::with_capacity(16 * 1024 * 1024); // 16MiB byte buffer for the file
|
||||||
)
|
let hasher = Arc::new(Mutex::new(Hasher::new()));
|
||||||
.context("Awaiting job for chunk")?;
|
|
||||||
completed_multipart_upload_builder = completed_multipart_upload_builder.parts(
|
let mut i = 1;
|
||||||
CompletedPart::builder()
|
let mut completed_multipart_upload_builder = CompletedMultipartUpload::builder();
|
||||||
.e_tag(part_upload_result.e_tag.unwrap_or_default())
|
|
||||||
|
loop {
|
||||||
|
buf.clear();
|
||||||
|
reader.read_buf(&mut buf).await.context("Reading chunk")?;
|
||||||
|
if buf.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug!("Uploading part {i} for multipart upload {id}");
|
||||||
|
|
||||||
|
let buf2 = buf.clone();
|
||||||
|
let hasher = Arc::clone(&hasher);
|
||||||
|
let hasher_job = spawn_blocking(move || {
|
||||||
|
hasher.blocking_lock().update_rayon(&buf2);
|
||||||
|
});
|
||||||
|
|
||||||
|
let part_upload_fut = self
|
||||||
|
.client
|
||||||
|
.upload_part()
|
||||||
|
.bucket(&*self.bucket)
|
||||||
|
.key(&source_fname)
|
||||||
|
.set_upload_id(multipart_result.upload_id.clone())
|
||||||
|
.body(ByteStream::from(buf.to_vec()))
|
||||||
.part_number(i)
|
.part_number(i)
|
||||||
.build(),
|
.send();
|
||||||
);
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!("Finalizing Multipart Upload {id}");
|
let ((), part_upload_result) = try_join!(
|
||||||
|
async { hasher_job.await.context("Awaiting hasher job") },
|
||||||
|
async { part_upload_fut.await.context("Awaiting uploader job") }
|
||||||
|
)
|
||||||
|
.context("Awaiting job for chunk")?;
|
||||||
|
completed_multipart_upload_builder = completed_multipart_upload_builder.parts(
|
||||||
|
CompletedPart::builder()
|
||||||
|
.e_tag(part_upload_result.e_tag.unwrap_or_default())
|
||||||
|
.part_number(i)
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
let hash = hasher.lock().await.finalize();
|
debug!("Finalizing Multipart Upload {id}");
|
||||||
self.client
|
|
||||||
.complete_multipart_upload()
|
|
||||||
.bucket(&*self.bucket)
|
|
||||||
.key(&source_fname)
|
|
||||||
.multipart_upload(completed_multipart_upload_builder.build())
|
|
||||||
.set_upload_id(multipart_result.upload_id)
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.context("Completing multipart upload")?;*/
|
|
||||||
|
|
||||||
let hasher = Arc::new(Mutex::new(Hasher::new()));
|
let hash = hasher.lock().await.finalize();
|
||||||
let mut buf = Vec::new();
|
self.client
|
||||||
reader.read_to_end(&mut buf).await?;
|
.complete_multipart_upload()
|
||||||
let buf = Bytes::from(buf);
|
.bucket(&*self.bucket)
|
||||||
let buf2 = buf.clone();
|
.key(&source_fname)
|
||||||
let hasher2 = Arc::clone(&hasher);
|
.multipart_upload(completed_multipart_upload_builder.build())
|
||||||
spawn_blocking(move || {
|
.set_upload_id(multipart_result.upload_id)
|
||||||
hasher2.blocking_lock().update_rayon(&buf2);
|
.send()
|
||||||
})
|
.await
|
||||||
.await?;
|
.context("Completing multipart upload")?;
|
||||||
self.client
|
hash
|
||||||
.put_object()
|
} else {
|
||||||
.bucket(&*self.bucket)
|
let buf = Bytes::from(buf);
|
||||||
.key(&source_fname)
|
let buf2 = buf.clone();
|
||||||
.body(ByteStream::from(buf.to_vec()))
|
let hasher2 = Arc::clone(&hasher);
|
||||||
.send()
|
spawn_blocking(move || {
|
||||||
.await
|
hasher2.blocking_lock().update_rayon(&buf2);
|
||||||
.context("Uploading file")?;
|
})
|
||||||
|
.await?;
|
||||||
|
self.client
|
||||||
|
.put_object()
|
||||||
|
.bucket(&*self.bucket)
|
||||||
|
.key(&source_fname)
|
||||||
|
.body(ByteStream::from(buf.to_vec()))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.context("Uploading file")?;
|
||||||
|
|
||||||
let hash = hasher.lock().await.finalize();
|
hasher.lock().await.finalize()
|
||||||
|
};
|
||||||
|
|
||||||
let target_fname = lexicographic_base64::encode(hash.as_bytes());
|
let target_fname = lexicographic_base64::encode(hash.as_bytes());
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,11 @@ dotenvy = "0.15.7"
|
||||||
eyre = "0.6.12"
|
eyre = "0.6.12"
|
||||||
mime = "0.3.17"
|
mime = "0.3.17"
|
||||||
mime_guess = "2.0.5"
|
mime_guess = "2.0.5"
|
||||||
reqwest = { version = "0.12.9", default-features = false, features = ["rustls-tls", "stream"] }
|
reqwest = { version = "0.12.9", default-features = false, features = [
|
||||||
|
"http2",
|
||||||
|
"rustls-tls",
|
||||||
|
"stream",
|
||||||
|
] }
|
||||||
tokio = { version = "1.41.1", features = ["fs", "macros", "rt-multi-thread"] }
|
tokio = { version = "1.41.1", features = ["fs", "macros", "rt-multi-thread"] }
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
tracing-subscriber = "0.3.19"
|
tracing-subscriber = "0.3.19"
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
use std::{collections::HashSet, future::Future, path::Path, pin::Pin};
|
use std::{
|
||||||
|
collections::HashSet, future::Future, path::PathBuf, pin::Pin, sync::Arc, time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
use chir_rs_http_api::{
|
use chir_rs_http_api::{
|
||||||
auth::{LoginRequest, PasetoToken, Scope},
|
auth::{LoginRequest, PasetoToken, Scope},
|
||||||
errors::APIError,
|
errors::APIError,
|
||||||
};
|
};
|
||||||
use clap::{arg, Parser, Subcommand};
|
use clap::{arg, Parser, Subcommand};
|
||||||
use eyre::{eyre, Context as _, OptionExt as _, Result};
|
use eyre::{eyre, Context as _, Result};
|
||||||
use mime_guess::{Mime, MimeGuess};
|
use mime_guess::MimeGuess;
|
||||||
use reqwest::Body;
|
use reqwest::Body;
|
||||||
use tokio::join;
|
use tokio::{sync::Mutex, task::JoinSet};
|
||||||
use tracing::{info, instrument};
|
use tracing::{info, instrument};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[arg(short, long, default_value = "http://localhost:5621/")]
|
#[arg(short, long, default_value = "https://lotte.chir.rs/")]
|
||||||
url: String,
|
url: String,
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Command,
|
command: Command,
|
||||||
|
@ -42,14 +44,18 @@ enum Command {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn login(url: String, username: String, password: String) -> Result<()> {
|
async fn login(
|
||||||
|
client: Arc<reqwest::Client>,
|
||||||
|
url: String,
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
) -> Result<()> {
|
||||||
let request = LoginRequest {
|
let request = LoginRequest {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
scopes: HashSet::from([Scope::Full]),
|
scopes: HashSet::from([Scope::Full]),
|
||||||
};
|
};
|
||||||
let request = bincode::encode_to_vec(request, bincode::config::standard())?;
|
let request = bincode::encode_to_vec(request, bincode::config::standard())?;
|
||||||
let client = reqwest::Client::new();
|
|
||||||
let res = client
|
let res = client
|
||||||
.post(format!("{url}.api/auth/login"))
|
.post(format!("{url}.api/auth/login"))
|
||||||
.header("Content-Type", "application/x+bincode")
|
.header("Content-Type", "application/x+bincode")
|
||||||
|
@ -74,9 +80,13 @@ async fn login(url: String, username: String, password: String) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(source))]
|
#[instrument(skip(client))]
|
||||||
async fn upload(url: String, source: impl AsRef<Path>, dest: String) -> Result<()> {
|
async fn upload_inner(
|
||||||
let client = reqwest::Client::new();
|
client: Arc<reqwest::Client>,
|
||||||
|
url: String,
|
||||||
|
source: PathBuf,
|
||||||
|
dest: String,
|
||||||
|
) -> Result<bool> {
|
||||||
let token = std::env::var("CHIR_RS_TOKEN")?;
|
let token = std::env::var("CHIR_RS_TOKEN")?;
|
||||||
let file = tokio::fs::File::open(&source).await?;
|
let file = tokio::fs::File::open(&source).await?;
|
||||||
let res = client
|
let res = client
|
||||||
|
@ -92,18 +102,55 @@ async fn upload(url: String, source: impl AsRef<Path>, dest: String) -> Result<(
|
||||||
.body(Body::from(file))
|
.body(Body::from(file))
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
info!("Finished uploading {dest}");
|
let status = res.status();
|
||||||
if !res.status().is_success() {
|
if status.is_client_error() {
|
||||||
let response = res.bytes().await?;
|
let response = res.bytes().await?;
|
||||||
let response: APIError =
|
let response: APIError =
|
||||||
bincode::decode_from_slice(&response, bincode::config::standard())?.0;
|
bincode::decode_from_slice(&response, bincode::config::standard())?.0;
|
||||||
Err(response).with_context(|| format!("Uploading to {dest}"))?;
|
Err(response).with_context(|| format!("Uploading to {dest}"))?;
|
||||||
|
} else if status.is_server_error() {
|
||||||
|
let response = res.bytes().await?;
|
||||||
|
let response: APIError =
|
||||||
|
bincode::decode_from_slice(&response, bincode::config::standard())?.0;
|
||||||
|
println!("Server error updating {dest}: {response:?}");
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
info!("Updated {dest}.");
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(client))]
|
||||||
|
async fn upload(
|
||||||
|
client: Arc<reqwest::Client>,
|
||||||
|
url: String,
|
||||||
|
source: PathBuf,
|
||||||
|
dest: String,
|
||||||
|
) -> Result<()> {
|
||||||
|
loop {
|
||||||
|
if upload_inner(
|
||||||
|
Arc::clone(&client),
|
||||||
|
url.clone(),
|
||||||
|
source.clone(),
|
||||||
|
dest.clone(),
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
println!("Uploading to {dest} failed. waiting 5s");
|
||||||
|
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(source))]
|
#[instrument(skip(client))]
|
||||||
async fn upload_dir(url: String, source: impl AsRef<Path>, dest: String) -> Result<()> {
|
async fn upload_dir(
|
||||||
|
client: Arc<reqwest::Client>,
|
||||||
|
futs: Arc<Mutex<JoinSet<Result<()>>>>,
|
||||||
|
url: String,
|
||||||
|
source: PathBuf,
|
||||||
|
dest: String,
|
||||||
|
) -> Result<()> {
|
||||||
let mut dir = tokio::fs::read_dir(source).await?;
|
let mut dir = tokio::fs::read_dir(source).await?;
|
||||||
while let Some(ent) = dir.next_entry().await? {
|
while let Some(ent) = dir.next_entry().await? {
|
||||||
let file_type = ent.file_type().await?;
|
let file_type = ent.file_type().await?;
|
||||||
|
@ -117,18 +164,39 @@ async fn upload_dir(url: String, source: impl AsRef<Path>, dest: String) -> Resu
|
||||||
format!("{dest}/{file_name_str}")
|
format!("{dest}/{file_name_str}")
|
||||||
};
|
};
|
||||||
if file_type.is_dir() {
|
if file_type.is_dir() {
|
||||||
let sub_fut: Pin<Box<dyn Future<Output = Result<()>>>> =
|
let boxed: Pin<Box<dyn Future<Output = Result<()>>>> = Box::pin(upload_dir(
|
||||||
Box::pin(upload_dir(url.clone(), ent.path(), tgt));
|
Arc::clone(&client),
|
||||||
sub_fut.await?;
|
Arc::clone(&futs),
|
||||||
|
url.clone(),
|
||||||
|
ent.path().to_path_buf(),
|
||||||
|
tgt,
|
||||||
|
));
|
||||||
|
boxed.await?;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if file_name_str == "index.html" {
|
if file_name_str == "index.html" {
|
||||||
if !dest.is_empty() {
|
if !dest.is_empty() {
|
||||||
upload(url.clone(), ent.path(), format!("{dest}/")).await?;
|
futs.lock().await.spawn(upload(
|
||||||
|
Arc::clone(&client),
|
||||||
|
url.clone(),
|
||||||
|
ent.path().to_path_buf(),
|
||||||
|
format!("{dest}/"),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
upload(url.clone(), ent.path(), dest.clone()).await?;
|
futs.lock().await.spawn(upload(
|
||||||
|
Arc::clone(&client),
|
||||||
|
url.clone(),
|
||||||
|
ent.path().to_path_buf(),
|
||||||
|
dest.clone(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
upload(url.clone(), ent.path(), tgt).await?;
|
futs.lock().await.spawn(upload(
|
||||||
|
Arc::clone(&client),
|
||||||
|
url.clone(),
|
||||||
|
ent.path().to_path_buf(),
|
||||||
|
tgt,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -139,11 +207,22 @@ async fn main() -> Result<()> {
|
||||||
dotenvy::dotenv().ok();
|
dotenvy::dotenv().ok();
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
let matches = Args::parse();
|
let matches = Args::parse();
|
||||||
|
let client = Arc::new(reqwest::Client::new());
|
||||||
|
|
||||||
match matches.command {
|
match matches.command {
|
||||||
Command::Login { username, password } => login(matches.url, username, password).await?,
|
Command::Login { username, password } => {
|
||||||
Command::Upload { source, dest } => upload(matches.url, source, dest).await?,
|
login(client, matches.url, username, password).await?
|
||||||
Command::UploadDir { source, dest } => upload_dir(matches.url, source, dest).await?,
|
}
|
||||||
|
Command::Upload { source, dest } => {
|
||||||
|
upload(client, matches.url, source.into(), dest).await?
|
||||||
|
}
|
||||||
|
Command::UploadDir { source, dest } => {
|
||||||
|
let futs = Arc::new(Mutex::new(JoinSet::new()));
|
||||||
|
upload_dir(client, Arc::clone(&futs), matches.url, source.into(), dest).await?;
|
||||||
|
while let Some(v) = futs.lock().await.join_next().await {
|
||||||
|
v??;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "chir-rs-fe"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
bincode = "2.0.0-rc.3"
|
|
||||||
chir-rs-http-api = { version = "0.1.0", path = "../chir-rs-http-api" }
|
|
||||||
console_error_panic_hook = "0.1.7"
|
|
||||||
eyre = "0.6.12"
|
|
||||||
gloo-net = "0.6.0"
|
|
||||||
gloo-storage = "0.3.0"
|
|
||||||
tracing = "0.1.41"
|
|
||||||
tracing-subscriber = "0.3.19"
|
|
||||||
unicode-normalization = "0.1.24"
|
|
||||||
wasm-bindgen = "=0.2.99"
|
|
||||||
wasm-tracing = "0.2.1"
|
|
||||||
web-sys = { version = "0.3.76", features = ["HtmlInputElement"] }
|
|
||||||
yew = { version = "0.21.0", features = ["csr"] }
|
|
||||||
yew-router = "0.18.0"
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
wasm-bindgen-cli = { version = "=0.2.99", artifact = "bin" }
|
|
||||||
|
|
||||||
[lints.rust]
|
|
||||||
deprecated-safe = "forbid"
|
|
||||||
elided_lifetimes_in_paths = "warn"
|
|
||||||
explicit_outlives_requirements = "warn"
|
|
||||||
impl-trait-overcaptures = "warn"
|
|
||||||
keyword-idents-2024 = "forbid"
|
|
||||||
let-underscore-drop = "warn"
|
|
||||||
macro-use-extern-crate = "deny"
|
|
||||||
meta-variable-misuse = "deny"
|
|
||||||
missing-abi = "forbid"
|
|
||||||
missing-copy-implementations = "warn"
|
|
||||||
missing-debug-implementations = "deny"
|
|
||||||
missing-docs = "warn"
|
|
||||||
missing-unsafe-on-extern = "deny"
|
|
||||||
non-local-definitions = "warn"
|
|
||||||
redundant-lifetimes = "warn"
|
|
||||||
single-use-lifetimes = "warn"
|
|
||||||
trivial-casts = "warn"
|
|
||||||
trivial-numeric-casts = "warn"
|
|
||||||
unit-bindings = "deny"
|
|
||||||
unnameable-types = "warn"
|
|
||||||
unreachable-pub = "warn"
|
|
||||||
unsafe-code = "forbid"
|
|
||||||
unused-crate-dependencies = "warn"
|
|
||||||
unused-extern-crates = "warn"
|
|
||||||
unused-import-braces = "warn"
|
|
||||||
unused-lifetimes = "warn"
|
|
||||||
unused-macro-rules = "warn"
|
|
||||||
unused-qualifications = "warn"
|
|
||||||
variant-size-differences = "warn"
|
|
||||||
|
|
||||||
[lints.clippy]
|
|
||||||
nursery = { level = "warn", priority = -1 }
|
|
||||||
pedantic = { level = "warn", priority = -1 }
|
|
||||||
module-name-repetitions = "allow"
|
|
||||||
alloc-instead-of-core = "warn"
|
|
||||||
allow-attributes-without-reason = "deny"
|
|
||||||
assertions-on-result-states = "forbid"
|
|
||||||
clone-on-ref-ptr = "warn"
|
|
||||||
empty-drop = "warn"
|
|
||||||
expect-used = "deny"
|
|
||||||
inline-asm-x86-att-syntax = "forbid"
|
|
||||||
missing-docs-in-private-items = "warn"
|
|
||||||
panic = "deny"
|
|
||||||
panic-in-result-fn = "forbid"
|
|
||||||
rc-buffer = "warn"
|
|
||||||
rc-mutex = "deny"
|
|
|
@ -1,17 +0,0 @@
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<script type="module">
|
|
||||||
import init from './chir_rs_fe.js';
|
|
||||||
async function run() {
|
|
||||||
await init();
|
|
||||||
}
|
|
||||||
run();
|
|
||||||
</script>
|
|
||||||
<link rel="stylesheet" href="/css/style.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body></body>
|
|
||||||
|
|
||||||
</html>
|
|
|
@ -1,19 +0,0 @@
|
||||||
//! Homepage
|
|
||||||
|
|
||||||
use gloo_storage::{SessionStorage, Storage};
|
|
||||||
use yew::prelude::*;
|
|
||||||
use yew_router::prelude::*;
|
|
||||||
|
|
||||||
use crate::Route;
|
|
||||||
|
|
||||||
/// Render the home page of the admin page
|
|
||||||
pub fn home_page() -> Html {
|
|
||||||
SessionStorage::get::<String>("api").map_or_else(
|
|
||||||
|_| {
|
|
||||||
html! {
|
|
||||||
<Redirect<Route> to={Route::Login} />
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|api_key| html! {<p>{api_key}</p>},
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
//! Management frontend for chir.rs
|
|
||||||
|
|
||||||
use std::future::Future;
|
|
||||||
|
|
||||||
use tracing::{error, instrument};
|
|
||||||
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _};
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
use wasm_tracing::{WASMLayer, WASMLayerConfigBuilder};
|
|
||||||
use yew::{platform::spawn_local, prelude::*};
|
|
||||||
use yew_router::prelude::*;
|
|
||||||
|
|
||||||
pub mod home;
|
|
||||||
pub mod login;
|
|
||||||
|
|
||||||
#[instrument(skip(fut))]
|
|
||||||
pub fn spawn<F>(fut: F)
|
|
||||||
where
|
|
||||||
F: Future<Output = eyre::Result<()>> + 'static,
|
|
||||||
{
|
|
||||||
spawn_local(async move {
|
|
||||||
if let Err(e) = fut.await {
|
|
||||||
error!("Failed to run async closure: {e:?}");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Routes defined by this SPA
|
|
||||||
#[derive(Clone, Routable, PartialEq)]
|
|
||||||
enum Route {
|
|
||||||
/// Home page
|
|
||||||
#[at("/")]
|
|
||||||
Home,
|
|
||||||
/// Login page
|
|
||||||
#[at("/login")]
|
|
||||||
Login,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Render the main site content
|
|
||||||
#[allow(clippy::needless_pass_by_value, reason = "API reasons")]
|
|
||||||
fn switch(routes: Route) -> Html {
|
|
||||||
match routes {
|
|
||||||
Route::Home => home::home_page(),
|
|
||||||
Route::Login => html! {
|
|
||||||
<login::Login />
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(App)]
|
|
||||||
fn app() -> Html {
|
|
||||||
html! {
|
|
||||||
<div class="container">
|
|
||||||
<header>
|
|
||||||
<hgroup>
|
|
||||||
<h1> {"Lotte’s Attic"} </h1>
|
|
||||||
<p> {"Super secret raccministrator portal :3c "} </p>
|
|
||||||
</hgroup>
|
|
||||||
</header>
|
|
||||||
<main id="main" role="main">
|
|
||||||
<HashRouter>
|
|
||||||
<Switch<Route> render={switch} />
|
|
||||||
</HashRouter>
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(start)]
|
|
||||||
fn main() {
|
|
||||||
console_error_panic_hook::set_once();
|
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(WASMLayer::new(WASMLayerConfigBuilder::new().build()))
|
|
||||||
.init();
|
|
||||||
|
|
||||||
yew::Renderer::<App>::new().render();
|
|
||||||
}
|
|
|
@ -1,100 +0,0 @@
|
||||||
//! Login screen
|
|
||||||
|
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use chir_rs_http_api::{
|
|
||||||
auth::{LoginRequest, PasetoToken, Scope},
|
|
||||||
errors::APIError,
|
|
||||||
};
|
|
||||||
use eyre::Context;
|
|
||||||
use gloo_net::http::Request;
|
|
||||||
use gloo_storage::{SessionStorage, Storage as _};
|
|
||||||
use tracing::info;
|
|
||||||
use unicode_normalization::UnicodeNormalization;
|
|
||||||
use wasm_bindgen::JsCast as _;
|
|
||||||
use web_sys::HtmlInputElement;
|
|
||||||
use yew::prelude::*;
|
|
||||||
use yew_router::hooks::use_navigator;
|
|
||||||
|
|
||||||
use crate::{spawn, Route};
|
|
||||||
|
|
||||||
/// Login view
|
|
||||||
#[function_component]
|
|
||||||
pub fn Login() -> Html {
|
|
||||||
let navigator = use_navigator().unwrap();
|
|
||||||
let username_handle = use_state(String::default);
|
|
||||||
let username = username_handle.clone();
|
|
||||||
let password_handle = use_state(String::default);
|
|
||||||
let password = password_handle.clone();
|
|
||||||
let on_username_input = Callback::from(move |e: InputEvent| {
|
|
||||||
let target = e.target();
|
|
||||||
let input = target.and_then(|t| t.dyn_into::<HtmlInputElement>().ok());
|
|
||||||
if let Some(input) = input {
|
|
||||||
username.set(input.value());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let on_password_input = Callback::from(move |e: InputEvent| {
|
|
||||||
let target = e.target();
|
|
||||||
let input = target.and_then(|t| t.dyn_into::<HtmlInputElement>().ok());
|
|
||||||
if let Some(input) = input {
|
|
||||||
password.set(input.value());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let onsubmit = Callback::from(move |e: SubmitEvent| {
|
|
||||||
let navigator = navigator.clone();
|
|
||||||
e.prevent_default();
|
|
||||||
let username = username_handle.trim();
|
|
||||||
let password = password_handle.trim().nfkc().collect::<String>();
|
|
||||||
let request = LoginRequest {
|
|
||||||
username: username.to_string(),
|
|
||||||
password,
|
|
||||||
scopes: HashSet::from([Scope::Full]),
|
|
||||||
};
|
|
||||||
|
|
||||||
spawn(async move {
|
|
||||||
let req_body = bincode::encode_to_vec(request, bincode::config::standard())
|
|
||||||
.context("Encoding login request")?;
|
|
||||||
let resp = Request::post("/.api/auth/login")
|
|
||||||
.header("Content-Type", "application/x+bincode")
|
|
||||||
.header("Accept", "application/x+bincode")
|
|
||||||
.body(req_body)
|
|
||||||
.context("Setting body for login request")?
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.context("Sending request for login request")?;
|
|
||||||
|
|
||||||
let status = resp.status();
|
|
||||||
let resp_body = resp
|
|
||||||
.binary()
|
|
||||||
.await
|
|
||||||
.context("Loading server response for login request")?;
|
|
||||||
|
|
||||||
if status >= 400 {
|
|
||||||
let error: APIError =
|
|
||||||
bincode::decode_from_slice(&resp_body, bincode::config::standard())
|
|
||||||
.context("Decoding error response")?
|
|
||||||
.0;
|
|
||||||
Err(error).context("While logging in")?;
|
|
||||||
} else {
|
|
||||||
let token: PasetoToken =
|
|
||||||
bincode::decode_from_slice(&resp_body, bincode::config::standard())
|
|
||||||
.context("Decoding success response")?
|
|
||||||
.0;
|
|
||||||
SessionStorage::set("api", token.to_paseto());
|
|
||||||
}
|
|
||||||
navigator.replace(&Route::Home);
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
|
|
||||||
info!("{e:?}");
|
|
||||||
});
|
|
||||||
html! {
|
|
||||||
<form accept-charset="utf-8" onsubmit={onsubmit}>
|
|
||||||
<label for="username">{"Username:"}</label>
|
|
||||||
<input id="username" type="text" placeholder="https://lotte.chir.rs/" oninput={on_username_input} />
|
|
||||||
<label for="password">{"Password:"}</label>
|
|
||||||
<input id="password" type="password" placeholder="●●●●●●●●●●●●●●●●" oninput={on_password_input} />
|
|
||||||
<input type="submit" value="Submit"/>
|
|
||||||
</form>
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,9 +22,11 @@ chrono = "0.4.38"
|
||||||
eyre = "0.6.12"
|
eyre = "0.6.12"
|
||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
mime = "0.3.17"
|
mime = "0.3.17"
|
||||||
rusty_paseto = { version = "0.7.1", default-features = false, features = ["batteries_included", "v4_local"] }
|
rusty_paseto = { version = "0.7.1", default-features = false, features = [
|
||||||
|
"batteries_included",
|
||||||
|
"v4_local",
|
||||||
|
] }
|
||||||
sentry-tower = { version = "0.34.0", features = ["axum", "axum-matched-path"] }
|
sentry-tower = { version = "0.34.0", features = ["axum", "axum-matched-path"] }
|
||||||
serde = { version = "1.0.215", features = ["derive"] }
|
|
||||||
tokio = { version = "1.41.1", features = ["fs", "net"] }
|
tokio = { version = "1.41.1", features = ["fs", "net"] }
|
||||||
tokio-util = { version = "0.7.13", features = ["compat"] }
|
tokio-util = { version = "0.7.13", features = ["compat"] }
|
||||||
tower-http = { version = "0.6.2", features = ["trace"] }
|
tower-http = { version = "0.6.2", features = ["trace"] }
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
body::Body,
|
body::Body,
|
||||||
extract::{Query, State},
|
extract::State,
|
||||||
http::{
|
http::{
|
||||||
header::{ACCEPT, CACHE_CONTROL, CONTENT_LENGTH, CONTENT_TYPE, ETAG, IF_NONE_MATCH},
|
header::{ACCEPT, CACHE_CONTROL, CONTENT_LENGTH, CONTENT_TYPE, ETAG, IF_NONE_MATCH},
|
||||||
HeaderMap, Request, StatusCode, Uri,
|
HeaderMap, Request, StatusCode, Uri,
|
||||||
|
@ -15,7 +15,6 @@ use chir_rs_misc::lexicographic_base64;
|
||||||
use eyre::Context as _;
|
use eyre::Context as _;
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use mime::MimeIter;
|
use mime::MimeIter;
|
||||||
use serde::Deserialize;
|
|
||||||
use tokio_util::compat::FuturesAsyncReadCompatExt as _;
|
use tokio_util::compat::FuturesAsyncReadCompatExt as _;
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info};
|
||||||
|
|
||||||
|
|
18
flake.lock
18
flake.lock
|
@ -14,11 +14,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1733731208,
|
"lastModified": 1726552619,
|
||||||
"narHash": "sha256-s9O/KIBhKOS49VmYJIBEiCrLK5hocJLKuvAkwAoELLQ=",
|
"narHash": "sha256-ytTBILVMnRZYvjiLYz+J6IFf/TOXdGuP6RDesMx9qgA=",
|
||||||
"owner": "DarkKirb",
|
"owner": "DarkKirb",
|
||||||
"repo": "cargo2nix",
|
"repo": "cargo2nix",
|
||||||
"rev": "37f356e1ba56e591550647c86039ffb0ca0c2201",
|
"rev": "baa12124e2de09e1cbbdac320f14809fa55af1a2",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -78,11 +78,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1733132332,
|
"lastModified": 1733682815,
|
||||||
"narHash": "sha256-8DTh3irBPko0ooHaeGJ5kPwBD8mOwiMX4eBjFuicLsA=",
|
"narHash": "sha256-8DFHnrHprF8u95VOFgMAgJe2OBD70pd1g0NFtIEElAY=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "b9ffe0d2ef589f4d75a62f908f00dfd6344b6b6e",
|
"rev": "73b9f2d20bea97d5bd6c8158f3a388ef40ac97c5",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -128,11 +128,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1733106880,
|
"lastModified": 1733625333,
|
||||||
"narHash": "sha256-aJmAIjZfWfPSWSExwrYBLRgXVvgF5LP1vaeUGOOIQ98=",
|
"narHash": "sha256-tIML2axjm4AnlKP29upVJxzBpj4Cy4ak+PKonqQtXmc=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "e66c0d43abf5bdefb664c3583ca8994983c332ae",
|
"rev": "430c8b054e45ea44fd2c9521a378306ada507a6c",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
68
flake.nix
68
flake.nix
|
@ -59,38 +59,11 @@
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system overlays;
|
inherit system overlays;
|
||||||
};
|
};
|
||||||
pkgs-wasm32 = import nixpkgs {
|
|
||||||
inherit system overlays;
|
|
||||||
crossSystem = {
|
|
||||||
system = "wasm32-wasi";
|
|
||||||
useLLVM = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
rustPkgs = pkgs.rustBuilder.makePackageSet {
|
rustPkgs = pkgs.rustBuilder.makePackageSet {
|
||||||
packageFun = import ./Cargo.nix;
|
packageFun = import ./Cargo.nix;
|
||||||
rustChannel = "nightly";
|
rustChannel = "stable";
|
||||||
rustVersion = "latest";
|
rustVersion = "latest";
|
||||||
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all;
|
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all;
|
||||||
extraConfigToml = ''
|
|
||||||
[unstable]
|
|
||||||
bindeps = true
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
rustPkgs-wasm32 = pkgs-wasm32.rustBuilder.makePackageSet {
|
|
||||||
packageFun = import ./Cargo.nix;
|
|
||||||
rustChannel = "nightly";
|
|
||||||
rustVersion = "latest";
|
|
||||||
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all;
|
|
||||||
target = "wasm32-unknown-unknown";
|
|
||||||
hostPlatform = pkgs-wasm32.stdenv.hostPlatform // {
|
|
||||||
parsed = pkgs-wasm32.stdenv.hostPlatform.parsed // {
|
|
||||||
kernel.name = "unknown";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
extraConfigToml = ''
|
|
||||||
[unstable]
|
|
||||||
bindeps = true
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
|
@ -98,13 +71,6 @@
|
||||||
with pkgs;
|
with pkgs;
|
||||||
mkShell {
|
mkShell {
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
(rust-bin.selectLatestNightlyWith (
|
|
||||||
toolchain:
|
|
||||||
toolchain.default.override {
|
|
||||||
extensions = [ "rust-src" ];
|
|
||||||
targets = [ "wasm32-unknown-unknown" ];
|
|
||||||
}
|
|
||||||
))
|
|
||||||
cargo2nix.packages.${system}.cargo2nix
|
cargo2nix.packages.${system}.cargo2nix
|
||||||
rustfilt
|
rustfilt
|
||||||
gdb
|
gdb
|
||||||
|
@ -113,39 +79,9 @@
|
||||||
sqlite
|
sqlite
|
||||||
treefmt
|
treefmt
|
||||||
nixfmt-rfc-style
|
nixfmt-rfc-style
|
||||||
wabt
|
|
||||||
trunk
|
|
||||||
(rustPkgs."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen-cli."0.2.99" { })
|
|
||||||
binaryen
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
packages =
|
packages = pkgs.lib.mapAttrs (_: v: (v { }).overrideAttrs { dontStrip = true; }) rustPkgs.workspace;
|
||||||
(pkgs.lib.mapAttrs (_: v: (v { }).overrideAttrs { dontStrip = true; }) rustPkgs.workspace)
|
|
||||||
// {
|
|
||||||
chir-rs-fe =
|
|
||||||
let
|
|
||||||
chir-rs-fe = rustPkgs-wasm32.workspace.chir-rs-fe { };
|
|
||||||
wasm-bindgen-cli =
|
|
||||||
rustPkgs."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen-cli."0.2.99"
|
|
||||||
{ };
|
|
||||||
in
|
|
||||||
pkgs.stdenvNoCC.mkDerivation {
|
|
||||||
inherit (chir-rs-fe) name version;
|
|
||||||
src = chir-rs-fe.out;
|
|
||||||
dontUnpack = true;
|
|
||||||
dontBuild = true;
|
|
||||||
nativeBuildInputs = [
|
|
||||||
wasm-bindgen-cli
|
|
||||||
pkgs.binaryen
|
|
||||||
];
|
|
||||||
installPhase = ''
|
|
||||||
mkdir $out
|
|
||||||
wasm-opt $src/lib/chir_rs_fe.wasm -o chir_rs_fe.wasm
|
|
||||||
wasm-bindgen chir_rs_fe.wasm --out-dir $out --target web
|
|
||||||
cp ${./chir-rs-fe/index.html} $out/index.html
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
nixosModules.default = import ./nixos {
|
nixosModules.default = import ./nixos {
|
||||||
inherit inputs system;
|
inherit inputs system;
|
||||||
};
|
};
|
||||||
|
|
1
result
1
result
|
@ -1 +0,0 @@
|
||||||
/nix/store/navjjbwfm21p9z8c9f62zpislxhbn1xb-chir-rs-fe
|
|
Loading…
Reference in a new issue