mirror of
https://github.com/amigan/rustypaste-pretty.git
synced 2024-11-21 11:59:48 -05:00
refactor(paste): use timestamp for expiring one shot files
This commit is contained in:
parent
92c35fe6df
commit
13126e79ce
3 changed files with 7 additions and 10 deletions
|
@ -15,7 +15,7 @@ async fn main() -> IoResult<()> {
|
|||
.expect("failed to parse config");
|
||||
let server_config = config.server.clone();
|
||||
fs::create_dir_all(&server_config.upload_path)?;
|
||||
for paste_type in &[PasteType::Url, PasteType::Oneshot, PasteType::Trash] {
|
||||
for paste_type in &[PasteType::Url, PasteType::Oneshot] {
|
||||
fs::create_dir_all(paste_type.get_path(&server_config.upload_path))?;
|
||||
}
|
||||
let mut http_server = HttpServer::new(move || {
|
||||
|
|
|
@ -16,8 +16,6 @@ pub enum PasteType {
|
|||
Oneshot,
|
||||
/// A file that only contains an URL.
|
||||
Url,
|
||||
/// A file that is expired or deleted.
|
||||
Trash,
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a ContentDisposition> for PasteType {
|
||||
|
@ -42,7 +40,6 @@ impl PasteType {
|
|||
Self::File => String::new(),
|
||||
Self::Oneshot => String::from("oneshot"),
|
||||
Self::Url => String::from("url"),
|
||||
Self::Trash => String::from("trash"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,10 +57,12 @@ async fn serve(
|
|||
.into_response(&request)?;
|
||||
if paste_type.is_oneshot() {
|
||||
fs::rename(
|
||||
path,
|
||||
PasteType::Trash
|
||||
.get_path(&config.server.upload_path)
|
||||
.join(&*file),
|
||||
&path,
|
||||
path.with_file_name(format!(
|
||||
"{}.{}",
|
||||
file,
|
||||
util::get_system_time()?.as_millis()
|
||||
)),
|
||||
)?;
|
||||
}
|
||||
Ok(response)
|
||||
|
@ -68,7 +70,6 @@ async fn serve(
|
|||
PasteType::Url => Ok(HttpResponse::Found()
|
||||
.header("Location", fs::read_to_string(&path)?)
|
||||
.finish()),
|
||||
PasteType::Trash => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +111,6 @@ async fn upload(
|
|||
paste.store_file(content.get_file_name()?, expiry_date, &config)?
|
||||
}
|
||||
PasteType::Url => paste.store_url(expiry_date, &config)?,
|
||||
PasteType::Trash => unreachable!(),
|
||||
};
|
||||
log::info!("{} ({}) is uploaded from {}", file_name, bytes_unit, host);
|
||||
urls.push(format!(
|
||||
|
|
Loading…
Reference in a new issue