From f94ae4348b7f5f2692a7b25463d01e47c4b7afe0 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Sun, 11 Oct 2015 13:32:21 +0200 Subject: [PATCH] Fix #13 --- Makefile | 2 +- lib/Lufi.pm | 4 +++- lib/Lufi/Controller/Files.pm | 4 ++-- lufi.conf.template | 9 ++++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index bc0b782..e60fa9c 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ test: clean: rm -rf lufi.db files/ dev: clean - $(CARTON) morbo $(LUFI) --listen http://0.0.0.0:3000 --watch lib/ --watch script/ --watch themes/ + $(CARTON) morbo $(LUFI) --listen http://0.0.0.0:3000 --watch lib/ --watch script/ --watch themes/ --watch lufi.conf devlog: multitail log/development.log diff --git a/lib/Lufi.pm b/lib/Lufi.pm index ff4ac39..acf2228 100644 --- a/lib/Lufi.pm +++ b/lib/Lufi.pm @@ -23,6 +23,7 @@ sub startup { }, mail_sender => 'no-reply@lufi.io', theme => 'default', + upload_dir => 'files', } }); @@ -170,7 +171,8 @@ sub startup { $self->provisioning(); # Create directory if needed - mkdir('files', 0700) unless (-d 'files'); + mkdir($self->config('upload_dir'), 0700) unless (-d $self->config('upload_dir')); + die ('The upload directory ('.$self->config('upload_dir').') is not writable') unless (-w $self->config('upload_dir')); # Default layout $self->defaults(layout => 'default'); diff --git a/lib/Lufi/Controller/Files.pm b/lib/Lufi/Controller/Files.pm index 13b33f3..2c100c1 100644 --- a/lib/Lufi/Controller/Files.pm +++ b/lib/Lufi/Controller/Files.pm @@ -44,7 +44,7 @@ sub upload { } } # Check that we have enough space (multiplying by 2 since it's encrypted, it takes more place that the original file) - elsif ($json->{part} == 0 && ($json->{size} * 2) >= dfportable('files')->{bavail}) { + elsif ($json->{part} == 0 && ($json->{size} * 2) >= dfportable($c->config('upload_dir'))->{bavail}) { $stop = 1; $c->send(sprintf('{"success": false, "msg":"'.$c->l('No enough space available on the server for this file (size: %1).', format_bytes($json->{size})).'", "sent_delay": %d, "i": %d}', $json->{delay}, $json->{i})); } @@ -94,7 +94,7 @@ sub upload { # In this case, we don't need to rewrite the file unless ($f->slices->grep(sub { $_->j == $json->{part} })->size) { # Create directory - my $dir = catdir('files', $f->short); + my $dir = catdir($c->config('upload_dir'), $f->short); mkdir($dir, 0700) unless (-d $dir); # Create slice file diff --git a/lufi.conf.template b/lufi.conf.template index ceeee68..8eb1b64 100644 --- a/lufi.conf.template +++ b/lufi.conf.template @@ -104,10 +104,17 @@ # define a path to the SQLite database # you can define it relative to lufi directory or set an absolute path - # remember that it has to be in a directory writable by Lutim user + # remember that it has to be in a directory writable by Lufi user # optional, default is lufi.db #db_path => 'lufi.db', + # define a path to the upload directory, where the uploaded files will be stored + # you can define it relative to lufi directory or set an absolute path + # remember that it has to be in a directory writable by Lufi user + # DO NOT CHANGE THIS IF FILES HAVE BEEN ALREADY UPLOADED: THEY WILL NOT BE DOWNLOADABLE ANYMORE + # optional, default is 'files' + #upload_dir => 'files', + ######################### # Lufi cron jobs settings #########################