|
|
|
|
@ -3,11 +3,7 @@ use image::{imageops::FilterType, GenericImageView};
@@ -3,11 +3,7 @@ use image::{imageops::FilterType, GenericImageView};
|
|
|
|
|
|
|
|
|
|
use crate::{utils, Error, Result}; |
|
|
|
|
use std::mem; |
|
|
|
|
use tokio::{ |
|
|
|
|
fs::{self, File}, |
|
|
|
|
io::AsyncReadExt, |
|
|
|
|
io::AsyncWriteExt, |
|
|
|
|
}; |
|
|
|
|
use tokio::{fs::File, io::AsyncReadExt, io::AsyncWriteExt}; |
|
|
|
|
|
|
|
|
|
pub struct FileMeta { |
|
|
|
|
pub content_disposition: Option<String>, |
|
|
|
|
@ -50,7 +46,6 @@ impl Media {
@@ -50,7 +46,6 @@ impl Media {
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
let path = globals.get_media_file(&key); |
|
|
|
|
fs::create_dir_all(path.parent().unwrap()).await?; |
|
|
|
|
let mut f = File::create(path).await?; |
|
|
|
|
f.write_all(file).await?; |
|
|
|
|
|
|
|
|
|
@ -89,7 +84,6 @@ impl Media {
@@ -89,7 +84,6 @@ impl Media {
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
let path = globals.get_media_file(&key); |
|
|
|
|
fs::create_dir_all(path.parent().unwrap()).await?; |
|
|
|
|
let mut f = File::create(path).await?; |
|
|
|
|
f.write_all(file).await?; |
|
|
|
|
|
|
|
|
|
@ -195,7 +189,12 @@ impl Media {
@@ -195,7 +189,12 @@ impl Media {
|
|
|
|
|
original_prefix.extend_from_slice(&0_u32.to_be_bytes()); // Height = 0 if it's not a thumbnail
|
|
|
|
|
original_prefix.push(0xff); |
|
|
|
|
|
|
|
|
|
if let Some(r) = self.mediaid_file.scan_prefix(&thumbnail_prefix).keys().next() { |
|
|
|
|
if let Some(r) = self |
|
|
|
|
.mediaid_file |
|
|
|
|
.scan_prefix(&thumbnail_prefix) |
|
|
|
|
.keys() |
|
|
|
|
.next() |
|
|
|
|
{ |
|
|
|
|
// Using saved thumbnail
|
|
|
|
|
let key = r?; |
|
|
|
|
let path = globals.get_media_file(&key); |
|
|
|
|
@ -231,7 +230,12 @@ impl Media {
@@ -231,7 +230,12 @@ impl Media {
|
|
|
|
|
content_type, |
|
|
|
|
file: file.to_vec(), |
|
|
|
|
})) |
|
|
|
|
} else if let Some(r) = self.mediaid_file.scan_prefix(&original_prefix).keys().next() { |
|
|
|
|
} else if let Some(r) = self |
|
|
|
|
.mediaid_file |
|
|
|
|
.scan_prefix(&original_prefix) |
|
|
|
|
.keys() |
|
|
|
|
.next() |
|
|
|
|
{ |
|
|
|
|
// Generate a thumbnail
|
|
|
|
|
|
|
|
|
|
let key = r?; |
|
|
|
|
@ -336,7 +340,6 @@ impl Media {
@@ -336,7 +340,6 @@ impl Media {
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
let path = globals.get_media_file(&thumbnail_key); |
|
|
|
|
fs::create_dir_all(path.parent().unwrap()).await?; |
|
|
|
|
let mut f = File::create(path).await?; |
|
|
|
|
f.write_all(&thumbnail_bytes).await?; |
|
|
|
|
|
|
|
|
|
|