Browse Source

implemented creation of directory within user folder

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/files
Stephan Richter 1 month ago
parent
commit
06118365b8
  1. 1
      backend/build.gradle.kts
  2. 29
      files/src/main/java/de/srsoftware/umbrella/files/FileModule.java
  3. 6
      frontend/src/routes/files/Index.svelte

1
backend/build.gradle.kts

@ -49,6 +49,7 @@ tasks.jar {
":contact:jar", ":contact:jar",
":core:jar", ":core:jar",
":documents:jar", ":documents:jar",
":files:jar",
":items:jar", ":items:jar",
":legacy:jar", ":legacy:jar",
":markdown:jar", ":markdown:jar",

29
files/src/main/java/de/srsoftware/umbrella/files/FileModule.java

@ -199,15 +199,36 @@ public class FileModule extends BaseHandler implements FileService {
return getFile(ex, file); return getFile(ex, file);
} }
private boolean postCompanyDirectory(Path path, HttpExchange ex, UmbrellaUser umbrellaUser) { private boolean postCompanyDirectory(Path path, HttpExchange ex, UmbrellaUser user) throws IOException {
return false; return false;
} }
private boolean postProjectDirectory(Path path, HttpExchange ex, UmbrellaUser umbrellaUser) { private boolean postProjectDirectory(Path path, HttpExchange ex, UmbrellaUser user) throws IOException {
return false; return false;
} }
private boolean postUserDirectory(Path path, HttpExchange ex, UmbrellaUser umbrellaUser) { private boolean postUserDirectory(Path path, HttpExchange ex, UmbrellaUser user) throws IOException {
return false; var userId = path.pop();
if (userId == null) throw missingFieldException(USER_ID);
long uid;
try {
uid = Long.parseLong(userId);
} catch (NumberFormatException e) {
throw invalidFieldException(PROJECT_ID,"Long");
}
var filename = "/user/"+uid;
if (!path.empty()) filename += "/"+URLDecoder.decode(path.toString(),UTF_8);
if (uid != user.id() && !fileDb.isPermitted(user,filename)) throw forbidden("You are not allowed to access {0}",filename);
var file = new File(baseDir+filename);
if (file.exists()) throw unprocessable("{0} already exists!",filename);
try {
file.mkdirs();
} catch (Exception e) {
throw unprocessable("Failed to create {0}",filename);
}
Map<String,Object> map = getDirectory(file.getParentFile());
map.put("title",filename);
return sendContent(ex,map);
} }
} }

6
frontend/src/routes/files/Index.svelte

@ -35,15 +35,15 @@
async function create_dir(ev){ async function create_dir(ev){
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
const url = api('files/'+path+'/'+new_dir); const url = api('files'+path+'/'+new_dir);
alert(url);
const res = await fetch(url,{ const res = await fetch(url,{
credentials: 'include', credentials: 'include',
method: 'POST' method: 'POST'
}); });
if (res.ok) { if (res.ok) {
yikes(); yikes();
loadChildren(window.location.pathname) loadChildren(window.location.pathname);
new_dir = null;
} else { } else {
error(res); error(res);
} }

Loading…
Cancel
Save