mirror of
https://github.com/Dangoware/confetti-box.git
synced 2025-04-19 15:22:57 -05:00
Compare commits
No commits in common. "main" and "0.2.2" have entirely different histories.
12 changed files with 130 additions and 179 deletions
10
README.md
10
README.md
|
@ -1,6 +1,5 @@
|
|||
# Confetti-Box 🎉
|
||||
A super simple file host. Inspired by [Catbox](https://catbox.moe) and
|
||||
[Uguu](https://uguu.se).
|
||||
A super simple file host. Inspired by [Catbox](https://catbox.moe) and [Uguu](https://uguu.se).
|
||||
|
||||
## Features
|
||||
### Current
|
||||
|
@ -8,7 +7,6 @@ A super simple file host. Inspired by [Catbox](https://catbox.moe) and
|
|||
- Customizable using a simple config file
|
||||
- Only stores one copy of a given hash on the backend
|
||||
- Chunked uploads of configurable size
|
||||
- Websocket uploads
|
||||
- Fast (enough), runs just fine on a Raspberry Pi
|
||||
- Simple API for interfacing with it programmatically
|
||||
- No database setup required, uses self-contained in memory database
|
||||
|
@ -20,10 +18,10 @@ A super simple file host. Inspired by [Catbox](https://catbox.moe) and
|
|||
|
||||
## Screenshot
|
||||
<p align="center">
|
||||
<img width="500px" src="./images/Confetti-Box Screenshot.png">
|
||||
<img width="500px" src="https://github.com/user-attachments/assets/9b12d65f-257d-448f-a7d0-43068cc3f8a3">
|
||||
<p align="center"><i>An example of a running instance</i></p>
|
||||
</p>
|
||||
|
||||
## License
|
||||
Confetti-Box is licensed under the terms of the GNU AGPL-3.0 license. Do what
|
||||
you want with it within the terms of that license.
|
||||
Confetti-Box is licensed under the terms of the GNU AGPL-3.0 license. Do what you want
|
||||
with it within the terms of that license.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "confetti_box"
|
||||
version = "0.2.2"
|
||||
version = "0.2.1"
|
||||
repository = "https://github.com/Dangoware/confetti-box"
|
||||
license = "AGPL-3.0-or-later"
|
||||
authors.workspace = true
|
||||
|
|
|
@ -35,7 +35,6 @@ pub fn home(settings: &State<Settings>) -> Markup {
|
|||
center {
|
||||
h1 { "Confetti-Box 🎉" }
|
||||
h2 { "Files up to " (settings.max_filesize.bytes()) " in size are allowed!" }
|
||||
noscript { "Javascript must be enabled for this site to function!" }
|
||||
hr;
|
||||
button.main_file_upload #fileButton onclick="document.getElementById('fileInput').click()" {
|
||||
h4 { "Upload File(s)" }
|
||||
|
@ -307,7 +306,7 @@ pub async fn websocket_upload(
|
|||
|
||||
hasher.update(&message);
|
||||
|
||||
stream.send(rocket_ws::Message::binary(offset.to_le_bytes().as_slice())).await.unwrap();
|
||||
stream.send(rocket_ws::Message::Text(json::serde_json::ser::to_string(&offset).unwrap())).await.unwrap();
|
||||
|
||||
file.write_all(&message).await.unwrap();
|
||||
|
||||
|
@ -347,7 +346,6 @@ pub async fn websocket_upload(
|
|||
file.flush().await.unwrap();
|
||||
|
||||
stream.send(rocket_ws::Message::Text(json::serde_json::ser::to_string(&constructed_file).unwrap())).await?;
|
||||
stream.close(None).await?;
|
||||
|
||||
Ok(())
|
||||
})))
|
||||
|
|
|
@ -68,8 +68,7 @@ async fn main() {
|
|||
confetti_box::home,
|
||||
pages::api_info,
|
||||
pages::about,
|
||||
resources::favicon_svg,
|
||||
resources::favicon_ico,
|
||||
resources::favicon,
|
||||
resources::form_handler_js,
|
||||
resources::stylesheet,
|
||||
resources::font_static,
|
||||
|
|
|
@ -9,7 +9,7 @@ pub fn head(page_title: &str) -> Markup {
|
|||
meta charset="UTF-8";
|
||||
meta name="viewport" content="width=device-width, initial-scale=1";
|
||||
title { (page_title) }
|
||||
link rel="icon" type="image/svg+xml" href="/favicon.svg";
|
||||
link rel="icon" type="image/svg+xml" href="/resources/favicon.svg";
|
||||
link rel="stylesheet" href="/resources/main.css";
|
||||
link rel="preload" href="/resources/fonts/Roboto.woff2" as="font" type="font/woff2" crossorigin;
|
||||
link rel="preload" href="/resources/fonts/FiraCode.woff2" as="font" type="font/woff2" crossorigin;
|
||||
|
|
|
@ -31,12 +31,7 @@ pub fn form_handler_js() -> RawJavaScript<&'static str> {
|
|||
RawJavaScript(include_str!("../web/request.js"))
|
||||
}
|
||||
|
||||
#[get("/favicon.svg")]
|
||||
pub fn favicon_svg() -> (ContentType, &'static str) {
|
||||
#[get("/resources/favicon.svg")]
|
||||
pub fn favicon() -> (ContentType, &'static str) {
|
||||
(ContentType::SVG, include_str!("../web/favicon.svg"))
|
||||
}
|
||||
|
||||
#[get("/favicon.ico")]
|
||||
pub fn favicon_ico() -> (ContentType, &'static [u8]) {
|
||||
(ContentType::Icon, include_bytes!("../web/favicon.ico"))
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.7 KiB |
|
@ -3,8 +3,6 @@
|
|||
const TOO_LARGE_TEXT = "Too large!";
|
||||
const ZERO_TEXT = "File is blank!";
|
||||
const ERROR_TEXT = "Error!";
|
||||
const USERAGENT = navigator.userAgent;
|
||||
const USE_CHUNKS_COMPAT = /Ladybird/.test(USERAGENT);
|
||||
|
||||
async function formSubmit() {
|
||||
const form = document.getElementById("uploadForm");
|
||||
|
@ -65,28 +63,27 @@ async function pasteSubmit(evt) {
|
|||
}
|
||||
|
||||
async function sendFiles(files, duration, maxSize) {
|
||||
if (USE_CHUNKS_COMPAT) {
|
||||
console.warn("This browser is known to have problems with WebSockets, falling back to chunked upload");
|
||||
}
|
||||
|
||||
const inProgressUploads = new Set();
|
||||
const concurrencyLimit = 10;
|
||||
|
||||
// Try to get a wake-lock
|
||||
// Create a reference for the Wake Lock.
|
||||
let wakeLock = null;
|
||||
|
||||
// create an async function to request a wake lock
|
||||
try {
|
||||
wakeLock = await navigator.wakeLock.request("screen");
|
||||
} catch (err) {
|
||||
console.warn("Failed to set wake-lock!");
|
||||
}
|
||||
|
||||
|
||||
let start = performance.now();
|
||||
for (const file of files) {
|
||||
console.log("Started upload for", file.name);
|
||||
|
||||
// Start the upload and add it to the set of in-progress uploads
|
||||
let uploadPromise;
|
||||
if ('WebSocket' in window && window.WebSocket.CLOSING === 2 && !USE_CHUNKS_COMPAT) {
|
||||
if ('WebSocket' in window && window.WebSocket.CLOSING === 2) {
|
||||
console.log("Uploading file using Websockets");
|
||||
uploadPromise = uploadFileWebsocket(file, duration, maxSize);
|
||||
} else {
|
||||
|
@ -220,13 +217,6 @@ async function uploadFileWebsocket(file, duration, maxSize) {
|
|||
new_uri += "//" + loc.host;
|
||||
new_uri += "/upload/websocket?name=" + file.name +"&size=" + file.size + "&duration=" + parseInt(duration);
|
||||
const socket = new WebSocket(new_uri);
|
||||
socket.binaryType = "arraybuffer";
|
||||
|
||||
// Ensure that the websocket gets closed if the page is unloaded
|
||||
window.onbeforeunload = function() {
|
||||
socket.onclose = function () {};
|
||||
socket.close();
|
||||
};
|
||||
|
||||
const chunkSize = 5_000_000;
|
||||
socket.addEventListener("open", (_event) => {
|
||||
|
@ -240,20 +230,16 @@ async function uploadFileWebsocket(file, duration, maxSize) {
|
|||
socket.send("");
|
||||
});
|
||||
|
||||
return new Promise(function(resolve, _reject) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
socket.addEventListener("message", (event) => {
|
||||
if (event.data instanceof ArrayBuffer) {
|
||||
const view = new DataView(event.data);
|
||||
console.log(view.getBigUint64(0, true));
|
||||
const progress = parseInt(view.getBigUint64(0, true));
|
||||
const response = JSON.parse(event.data);
|
||||
if (response.mmid == null) {
|
||||
const progress = parseInt(response);
|
||||
uploadProgressWebsocket(progress, progressBar, progressText, file.size);
|
||||
} else {
|
||||
// It's so over
|
||||
if (!socket.CLOSED) {
|
||||
socket.close();
|
||||
}
|
||||
socket.close();
|
||||
|
||||
const response = JSON.parse(event.data);
|
||||
uploadComplete(response, 200, progressBar, progressText, linkRow);
|
||||
resolve();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ keywords = ["selfhost", "upload", "command_line"]
|
|||
categories = ["command-line-utilities"]
|
||||
authors.workspace = true
|
||||
license = "AGPL-3.0-or-later"
|
||||
edition = "2024"
|
||||
edition = "2021"
|
||||
|
||||
[[bin]]
|
||||
name = "imu"
|
||||
|
@ -17,21 +17,17 @@ path = "src/main.rs"
|
|||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
base64 = "0.22.1"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
clap = { version = "4.5", features = ["derive", "unicode"] }
|
||||
directories = "6.0"
|
||||
futures-util = "0.3.31"
|
||||
indicatif = { version = "0.17", features = ["improved_unicode"] }
|
||||
owo-colors = { version = "4.1", features = ["supports-colors"] }
|
||||
reqwest = { version = "0.12", features = ["json", "stream"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "1.41", features = ["fs", "macros", "rt-multi-thread"] }
|
||||
tokio-tungstenite = { version = "0.26.2", features = ["native-tls"] }
|
||||
tokio-util = { version = "0.7", features = ["codec"] }
|
||||
toml = "0.8"
|
||||
url = { version = "2.5.4", features = ["serde"] }
|
||||
uuid = { version = "1.11", features = ["serde", "v4"] }
|
||||
anyhow = "1.0.92"
|
||||
chrono = { version = "0.4.38", features = ["serde"] }
|
||||
clap = { version = "4.5.20", features = ["derive", "unicode"] }
|
||||
directories = "5.0.1"
|
||||
indicatif = { version = "0.17.8", features = ["improved_unicode"] }
|
||||
owo-colors = { version = "4.1.0", features = ["supports-colors"] }
|
||||
reqwest = { version = "0.12.8", features = ["json", "stream"] }
|
||||
serde = { version = "1.0.213", features = ["derive"] }
|
||||
serde_json = "1.0.132"
|
||||
thiserror = "1.0.68"
|
||||
tokio = { version = "1.41.0", features = ["fs", "macros", "rt-multi-thread"] }
|
||||
tokio-util = { version = "0.7.12", features = ["codec"] }
|
||||
toml = "0.8.19"
|
||||
uuid = { version = "1.11.0", features = ["serde", "v4"] }
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
use std::{error::Error, fs, io::{self, Read, Write}, path::{Path, PathBuf}};
|
||||
use std::{error::Error, fs, io::{self, Read, Write}, os::unix::fs::MetadataExt, path::{Path, PathBuf}};
|
||||
|
||||
use base64::{prelude::BASE64_URL_SAFE, Engine};
|
||||
use chrono::{DateTime, Datelike, Local, Month, TimeDelta, Timelike, Utc};
|
||||
|
||||
use futures_util::{stream::FusedStream as _, SinkExt as _, StreamExt as _};
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use owo_colors::OwoColorize;
|
||||
use reqwest::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
use tokio::{fs::File, io::{AsyncReadExt, AsyncWriteExt}, join, task::JoinSet};
|
||||
use tokio_tungstenite::{connect_async, tungstenite::{client::IntoClientRequest as _, Message}};
|
||||
use url::Url;
|
||||
use tokio::{fs::{create_dir, File}, io::{AsyncReadExt, AsyncWriteExt}, task::JoinSet};
|
||||
use uuid::Uuid;
|
||||
use clap::{arg, builder::{styling::RgbColor, Styles}, Parser, Subcommand};
|
||||
use anyhow::{anyhow, bail, Context as _, Result};
|
||||
|
@ -57,7 +53,7 @@ enum Commands {
|
|||
/// Set the password for a server which requires login
|
||||
#[arg(short, long, required = false)]
|
||||
password: Option<String>,
|
||||
/// Set the URL of the server to connect to (assumes https://)
|
||||
/// Set the URL of the server to connect to
|
||||
#[arg(long, required = false)]
|
||||
url: Option<String>,
|
||||
/// Set the directory to download into by default
|
||||
|
@ -86,16 +82,17 @@ async fn main() -> Result<()> {
|
|||
|
||||
match &cli.command {
|
||||
Commands::Upload { files, duration } => {
|
||||
let Some(url) = config.url.clone() else {
|
||||
if config.url.is_empty() {
|
||||
exit_error(
|
||||
format!("URL is empty"),
|
||||
Some(format!("Please set it using the {} command", "set".truecolor(246,199,219).bold())),
|
||||
None,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
get_info_if_expired(&mut config).await?;
|
||||
|
||||
let client = Client::new();
|
||||
let duration = match parse_time_string(&duration) {
|
||||
Ok(d) => d,
|
||||
Err(e) => return Err(anyhow!("Invalid duration: {e}")),
|
||||
|
@ -128,7 +125,8 @@ async fn main() -> Result<()> {
|
|||
let response = upload_file(
|
||||
name.into_owned(),
|
||||
&path,
|
||||
&url,
|
||||
&client,
|
||||
&config.url,
|
||||
duration,
|
||||
&config.login
|
||||
).await.with_context(|| "Failed to upload").unwrap();
|
||||
|
@ -143,19 +141,11 @@ async fn main() -> Result<()> {
|
|||
println!(
|
||||
"{:>8} {}, {} (in {})\n{:>8} {}",
|
||||
"Expires:".truecolor(174,196,223).bold(), date, time, pretty_time_long(duration.num_seconds()),
|
||||
"URL:".truecolor(174,196,223).bold(), (url.to_string() + "/f/" + &response.mmid.0).underline()
|
||||
"URL:".truecolor(174,196,223).bold(), (config.url.clone() + "/f/" + &response.mmid.0).underline()
|
||||
);
|
||||
}
|
||||
}
|
||||
Commands::Download { mmids, out_directory } => {
|
||||
let Some(url) = config.url else {
|
||||
exit_error(
|
||||
format!("URL is empty"),
|
||||
Some(format!("Please set it using the {} command", "set".truecolor(246,199,219).bold())),
|
||||
None,
|
||||
);
|
||||
};
|
||||
|
||||
let out_directory = if let Some(dir) = out_directory {
|
||||
dir
|
||||
} else {
|
||||
|
@ -177,6 +167,7 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
};
|
||||
|
||||
let url = &config.url;
|
||||
for mmid in mmids {
|
||||
let mmid = if mmid.len() != 8 {
|
||||
if mmid.contains(format!("{url}/f/").as_str()) {
|
||||
|
@ -212,10 +203,10 @@ async fn main() -> Result<()> {
|
|||
};
|
||||
|
||||
let mut file_res = if let Some(login) = &config.login {
|
||||
client.get(format!("{}/f/{mmid}", url))
|
||||
client.get(format!("{}/f/{mmid}", config.url))
|
||||
.basic_auth(&login.user, Some(&login.pass))
|
||||
} else {
|
||||
client.get(format!("{}/f/{mmid}", url))
|
||||
client.get(format!("{}/f/{mmid}", config.url))
|
||||
}
|
||||
.send()
|
||||
.await
|
||||
|
@ -314,14 +305,7 @@ async fn main() -> Result<()> {
|
|||
url
|
||||
};
|
||||
|
||||
let new_url = if !url.starts_with("https://") && !url.starts_with("http://") {
|
||||
("https://".to_owned() + url).to_string()
|
||||
} else {
|
||||
url.to_string()
|
||||
};
|
||||
|
||||
config.url = Some(Url::parse(&new_url)?);
|
||||
|
||||
config.url = url.to_string();
|
||||
config.save().unwrap();
|
||||
println!("URL set to \"{url}\"");
|
||||
}
|
||||
|
@ -367,7 +351,7 @@ async fn main() -> Result<()> {
|
|||
#[derive(Error, Debug)]
|
||||
enum UploadError {
|
||||
#[error("request provided was invalid: {0}")]
|
||||
WebSocketFailed(String),
|
||||
InvalidRequest(String),
|
||||
|
||||
#[error("error on reqwest transaction: {0}")]
|
||||
Reqwest(#[from] reqwest::Error),
|
||||
|
@ -376,101 +360,104 @@ enum UploadError {
|
|||
async fn upload_file<P: AsRef<Path>>(
|
||||
name: String,
|
||||
path: &P,
|
||||
url: &Url,
|
||||
client: &Client,
|
||||
url: &String,
|
||||
duration: TimeDelta,
|
||||
login: &Option<Login>,
|
||||
) -> Result<MochiFile, UploadError> {
|
||||
let mut file = File::open(path).await.unwrap();
|
||||
let file_size = file.metadata().await.unwrap().len();
|
||||
let size = file.metadata().await.unwrap().size() as u64;
|
||||
|
||||
// Construct the URL
|
||||
let mut url = url.clone();
|
||||
if url.scheme() == "http" {
|
||||
url.set_scheme("ws").unwrap();
|
||||
} else if url.scheme() == "https" {
|
||||
url.set_scheme("wss").unwrap();
|
||||
}
|
||||
|
||||
url.set_path("/upload/websocket");
|
||||
url.set_query(Some(&format!("name={}&size={}&duration={}", name, file_size, duration.num_seconds())));
|
||||
|
||||
let mut request = url.to_string().into_client_request().unwrap();
|
||||
|
||||
if let Some(l) = login {
|
||||
request.headers_mut().insert(
|
||||
"Authorization",
|
||||
format!("Basic {}", BASE64_URL_SAFE.encode(format!("{}:{}", l.user, l.pass))).parse().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
let (stream, _response) = connect_async(request).await.map_err(|e| UploadError::WebSocketFailed(e.to_string()))?;
|
||||
let (mut write, mut read) = stream.split();
|
||||
|
||||
// Upload the file in chunks
|
||||
let upload_task = async move {
|
||||
let mut chunk = vec![0u8; 20_000];
|
||||
loop {
|
||||
let read_len = file.read(&mut chunk).await.unwrap();
|
||||
if read_len == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
write.send(Message::binary(chunk[..read_len].to_vec())).await.unwrap();
|
||||
}
|
||||
|
||||
// Close the stream because sending is over
|
||||
write.send(Message::binary(b"".as_slice())).await.unwrap();
|
||||
write.flush().await.unwrap();
|
||||
|
||||
write
|
||||
let ChunkedResponse {status, message, uuid, chunk_size} = {
|
||||
client.post(format!("{url}/upload/chunked/"))
|
||||
.json(
|
||||
&ChunkedInfo {
|
||||
name: name.clone(),
|
||||
size,
|
||||
expire_duration: duration.num_seconds() as u64,
|
||||
}
|
||||
)
|
||||
.basic_auth(&login.as_ref().unwrap().user, login.as_ref().unwrap().pass.clone().into())
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?
|
||||
};
|
||||
|
||||
if !status {
|
||||
return Err(UploadError::InvalidRequest(message));
|
||||
}
|
||||
|
||||
let mut i = 0;
|
||||
let post_url = format!("{url}/upload/chunked/{}", uuid.unwrap());
|
||||
let mut request_set = JoinSet::new();
|
||||
let bar = ProgressBar::new(100);
|
||||
bar.set_style(ProgressStyle::with_template(
|
||||
&format!("{} {{bar:40.cyan/blue}} {{pos:>3}}% {{msg}}", name)
|
||||
).unwrap());
|
||||
loop {
|
||||
// Read the next chunk into a buffer
|
||||
let mut chunk = vec![0u8; chunk_size.unwrap() as usize];
|
||||
let bytes_read = fill_buffer(&mut chunk, &mut file).await.unwrap();
|
||||
if bytes_read == 0 {
|
||||
break;
|
||||
}
|
||||
let chunk = chunk[..bytes_read].to_owned();
|
||||
|
||||
// Get the progress of the file upload
|
||||
let progress_task = async move {
|
||||
let final_json = loop {
|
||||
let Some(p) = read.next().await else {
|
||||
break String::new()
|
||||
};
|
||||
request_set.spawn({
|
||||
let post_url = post_url.clone();
|
||||
let user = login.as_ref().unwrap().user.clone();
|
||||
let pass = login.as_ref().unwrap().pass.clone();
|
||||
// Reuse the client for all the threads
|
||||
let client = Client::clone(client);
|
||||
|
||||
let p = p.unwrap();
|
||||
|
||||
// Got the final json information, return that
|
||||
if p.is_text() {
|
||||
break p.into_text().unwrap().to_string()
|
||||
async move {
|
||||
client.post(&post_url)
|
||||
.query(&[("chunk", i)])
|
||||
.basic_auth(&user, pass.into())
|
||||
.body(chunk)
|
||||
.send()
|
||||
.await
|
||||
}
|
||||
});
|
||||
|
||||
// Get the progress information
|
||||
let prog = p.into_data();
|
||||
let prog = u64::from_le_bytes(prog.to_vec().try_into().unwrap());
|
||||
let percent = f64::trunc((prog as f64 / file_size as f64) * 100.0);
|
||||
if percent <= 100. {
|
||||
bar.set_position(percent as u64);
|
||||
}
|
||||
};
|
||||
i += 1;
|
||||
|
||||
(read, final_json, bar)
|
||||
};
|
||||
// Limit the number of concurrent uploads to 5
|
||||
if request_set.len() >= 5 {
|
||||
bar.set_message("");
|
||||
request_set.join_next().await;
|
||||
bar.set_message("⏳");
|
||||
}
|
||||
|
||||
// Wait for both of the tasks to finish
|
||||
let (read, write) = join!(progress_task, upload_task);
|
||||
let (read, final_json, bar) = read;
|
||||
let mut stream = write.reunite(read).unwrap();
|
||||
|
||||
let file_info: MochiFile = serde_json::from_str(&final_json).unwrap();
|
||||
|
||||
// If the websocket isn't closed, do that
|
||||
if !stream.is_terminated() {
|
||||
stream.close(None).await.unwrap();
|
||||
let percent = f64::trunc(((i as f64 * chunk_size.unwrap() as f64) / size as f64) * 100.0);
|
||||
if percent <= 100. {
|
||||
bar.set_position(percent as u64);
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for all remaining uploads to finish
|
||||
loop {
|
||||
if let Some(t) = request_set.join_next().await {
|
||||
match t {
|
||||
Ok(_) => (),
|
||||
Err(_) => todo!(),
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
bar.finish_and_clear();
|
||||
println!("[{}] - \"{}\"", "✓".bright_green(), name);
|
||||
|
||||
Ok(file_info)
|
||||
Ok(
|
||||
client.get(format!("{url}/upload/chunked/{}?finish", uuid.unwrap()))
|
||||
.basic_auth(&login.as_ref().unwrap().user, login.as_ref().unwrap().pass.clone().into())
|
||||
.send()
|
||||
.await.unwrap()
|
||||
.json::<MochiFile>()
|
||||
.await?
|
||||
)
|
||||
}
|
||||
|
||||
async fn get_info_if_expired(config: &mut Config) -> Result<()> {
|
||||
|
@ -490,13 +477,7 @@ async fn get_info_if_expired(config: &mut Config) -> Result<()> {
|
|||
}
|
||||
|
||||
async fn get_info(config: &Config) -> Result<ServerInfo> {
|
||||
let Some(url) = config.url.clone() else {
|
||||
exit_error(
|
||||
format!("URL is empty"),
|
||||
Some(format!("Please set it using the {} command", "set".truecolor(246,199,219).bold())),
|
||||
None,
|
||||
);
|
||||
};
|
||||
let url = config.url.clone();
|
||||
let client = Client::new();
|
||||
|
||||
let get_info = client.get(format!("{url}/info"));
|
||||
|
@ -534,11 +515,9 @@ async fn fill_buffer<S: AsyncReadExt + Unpin>(buffer: &mut [u8], mut stream: S)
|
|||
let mut bytes_read = 0;
|
||||
while bytes_read < buffer.len() {
|
||||
let len = stream.read(&mut buffer[bytes_read..]).await?;
|
||||
|
||||
if len == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
bytes_read += len;
|
||||
}
|
||||
Ok(bytes_read)
|
||||
|
@ -612,7 +591,7 @@ struct Login {
|
|||
#[derive(Deserialize, Serialize, Debug, Default)]
|
||||
#[serde(default)]
|
||||
struct Config {
|
||||
url: Option<Url>,
|
||||
url: String,
|
||||
login: Option<Login>,
|
||||
/// The time when the info was last fetched
|
||||
info_fetch: Option<DateTime<Utc>>,
|
||||
|
@ -627,7 +606,7 @@ impl Config {
|
|||
str
|
||||
} else {
|
||||
let c = Config {
|
||||
url: None,
|
||||
url: String::new(),
|
||||
login: None,
|
||||
info_fetch: None,
|
||||
info: None,
|
||||
|
@ -660,7 +639,7 @@ impl Config {
|
|||
|
||||
if buf.is_empty() {
|
||||
let c = Config {
|
||||
url: None,
|
||||
url: String::new(),
|
||||
login: None,
|
||||
info: None,
|
||||
info_fetch: None,
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 102 KiB |
Loading…
Reference in a new issue