Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments compatible with absolute path #255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/endpoints/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ pub async fn create(
};

std::fs::create_dir_all(format!(
"./{}/attachments/{}",
"{}/attachments/{}",
ARGS.data_dir,
&new_pasta.id_as_animals()
))
.unwrap();

let filepath = format!(
"./{}/attachments/{}/{}",
"{}/attachments/{}/{}",
ARGS.data_dir,
&new_pasta.id_as_animals(),
&file.name()
Expand Down Expand Up @@ -290,7 +290,7 @@ pub async fn create(

if new_pasta.file.is_some() && new_pasta.encrypt_server && !new_pasta.readonly {
let filepath = format!(
"./{}/attachments/{}/{}",
"{}/attachments/{}/{}",
ARGS.data_dir,
&new_pasta.id_as_animals(),
&new_pasta.file.as_ref().unwrap().name()
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub async fn post_secure_file(
if found {
if let Some(ref pasta_file) = pastas[index].file {
let file = File::open(format!(
"./{}/attachments/{}/data.enc",
"{}/attachments/{}/data.enc",
ARGS.data_dir,
pastas[index].id_as_animals()
))?;
Expand Down Expand Up @@ -119,7 +119,7 @@ pub async fn get_file(

// Construct the path to the file
let file_path = format!(
"./{}/attachments/{}/{}",
"{}/attachments/{}/{}",
ARGS.data_dir,
pastas[index].id_as_animals(),
pasta_file.name()
Expand Down
8 changes: 4 additions & 4 deletions src/endpoints/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpRes
// remove the file itself
if let Some(PastaFile { name, .. }) = &pasta.file {
if fs::remove_file(format!(
"./{}/attachments/{}/{}",
"{}/attachments/{}/{}",
ARGS.data_dir,
pasta.id_as_animals(),
name
Expand All @@ -50,7 +50,7 @@ pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpRes

// and remove the containing directory
if fs::remove_dir(format!(
"./{}/attachments/{}/",
"{}/attachments/{}/",
ARGS.data_dir,
pasta.id_as_animals()
))
Expand Down Expand Up @@ -113,7 +113,7 @@ pub async fn post_remove(
// remove the file itself
if let Some(PastaFile { name, .. }) = &pasta.file {
if fs::remove_file(format!(
"./{}/attachments/{}/{}",
"{}/attachments/{}/{}",
ARGS.data_dir,
pasta.id_as_animals(),
name
Expand All @@ -125,7 +125,7 @@ pub async fn post_remove(

// and remove the containing directory
if fs::remove_dir(format!(
"./{}/attachments/{}/",
"{}/attachments/{}/",
ARGS.data_dir,
pasta.id_as_animals()
))
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ async fn main() -> std::io::Result<()> {
ARGS.port.to_string()
);

match fs::create_dir_all(format!("./{}/public", ARGS.data_dir)) {
match fs::create_dir_all(format!("{}/public", ARGS.data_dir)) {
Ok(dir) => dir,
Err(error) => {
log::error!(
"Couldn't create data directory ./{}/attachments/: {:?}",
"Couldn't create data directory {}/attachments/: {:?}",
ARGS.data_dir,
error
);
panic!(
"Couldn't create data directory ./{}/attachments/: {:?}",
"Couldn't create data directory {}/attachments/: {:?}",
ARGS.data_dir, error
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn remove_expired(pastas: &mut Vec<Pasta>) {
// remove the file itself
if let Some(file) = &p.file {
if fs::remove_file(format!(
"./{}/attachments/{}/{}",
"{}/attachments/{}/{}",
ARGS.data_dir,
p.id_as_animals(),
file.name()
Expand All @@ -53,7 +53,7 @@ pub fn remove_expired(pastas: &mut Vec<Pasta>) {

// and remove the containing directory
if fs::remove_dir(format!(
"./{}/attachments/{}/",
"{}/attachments/{}/",
ARGS.data_dir,
p.id_as_animals()
))
Expand Down