fix: long uploads
This commit is contained in:
parent
d18bb4d8a8
commit
79338256df
@ -8,7 +8,7 @@ database = "mysql://root:root@localhost:3366/void_cat"
|
|||||||
storage_dir = "./data"
|
storage_dir = "./data"
|
||||||
|
|
||||||
# Maximum support filesize for uploading
|
# Maximum support filesize for uploading
|
||||||
max_upload_bytes = 104857600
|
max_upload_bytes = 5e+9
|
||||||
|
|
||||||
# Public facing url
|
# Public facing url
|
||||||
public_url = "http://localhost:8000"
|
public_url = "http://localhost:8000"
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
use std::ops::Sub;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use base64::prelude::BASE64_STANDARD;
|
use base64::prelude::BASE64_STANDARD;
|
||||||
use log::info;
|
use log::info;
|
||||||
@ -42,9 +39,6 @@ impl<'r> FromRequest<'r> for Nip98Auth {
|
|||||||
"Created timestamp is in the future",
|
"Created timestamp is in the future",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if event.created_at < Timestamp::now().sub(Duration::from_secs(60)) {
|
|
||||||
return Outcome::Error((Status::new(401), "Created timestamp is too old"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// check url tag
|
// check url tag
|
||||||
if let Some(url) = event.tags.iter().find_map(|t| {
|
if let Some(url) = event.tags.iter().find_map(|t| {
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::ops::Sub;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use log::error;
|
use log::error;
|
||||||
|
use nostr::Timestamp;
|
||||||
use rocket::{FromForm, Responder, Route, routes, State};
|
use rocket::{FromForm, Responder, Route, routes, State};
|
||||||
|
use rocket::data::ToByteUnit;
|
||||||
use rocket::form::Form;
|
use rocket::form::Form;
|
||||||
use rocket::fs::TempFile;
|
use rocket::fs::TempFile;
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
@ -123,6 +127,7 @@ impl Nip96UploadResult {
|
|||||||
],
|
],
|
||||||
vec!["x".to_string(), hex_id],
|
vec!["x".to_string(), hex_id],
|
||||||
vec!["m".to_string(), upload.mime_type.clone()],
|
vec!["m".to_string(), upload.mime_type.clone()],
|
||||||
|
vec!["size".to_string(), upload.size.to_string()],
|
||||||
];
|
];
|
||||||
if let Some(bh) = &upload.blur_hash {
|
if let Some(bh) = &upload.blur_hash {
|
||||||
tags.push(vec!["blurhash".to_string(), bh.clone()]);
|
tags.push(vec!["blurhash".to_string(), bh.clone()]);
|
||||||
@ -231,7 +236,14 @@ async fn upload(
|
|||||||
if form.alt.is_some() {
|
if form.alt.is_some() {
|
||||||
return Nip96Response::error("\"alt\" is not supported");
|
return Nip96Response::error("\"alt\" is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// account for upload speeds as slow as 1MB/s (8 Mbps)
|
||||||
|
let mbs = form.size / 1.megabytes().as_u64() as usize;
|
||||||
|
let max_time = 60.max(mbs) as u64;
|
||||||
|
if auth.event.created_at < Timestamp::now().sub(Duration::from_secs(max_time)) {
|
||||||
|
return Nip96Response::error("Auth event timestamp out of range");
|
||||||
|
}
|
||||||
|
|
||||||
// check whitelist
|
// check whitelist
|
||||||
if let Some(wl) = &settings.whitelist {
|
if let Some(wl) = &settings.whitelist {
|
||||||
if !wl.contains(&auth.event.pubkey.to_hex()) {
|
if !wl.contains(&auth.event.pubkey.to_hex()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user