Browse Source

peparing for file upload on server side

module/files
Stephan Richter 1 month ago
parent
commit
f9941bceba
  1. 3
      build.gradle.kts
  2. 1
      core/build.gradle.kts
  3. 2
      documents/build.gradle.kts
  4. 8
      files/src/main/java/de/srsoftware/umbrella/files/FileModule.java
  5. 27
      frontend/src/routes/files/Index.svelte
  6. 1
      legacy/build.gradle.kts
  7. 1
      markdown/build.gradle.kts
  8. 1
      messages/build.gradle.kts
  9. 1
      user/build.gradle.kts

3
build.gradle.kts

@ -42,7 +42,8 @@ subprojects { @@ -42,7 +42,8 @@ subprojects {
testImplementation("org.junit.jupiter:junit-jupiter")
implementation("de.srsoftware:configuration.api:1.0.2")
implementation("de.srsoftware:tools.jdbc:2.0.0")
implementation("de.srsoftware:tools.http:6.0.4")
implementation("de.srsoftware:tools.http:6.0.5")
implementation("de.srsoftware:tools.mime:1.1.3")
implementation("de.srsoftware:tools.logging:1.3.2")
implementation("de.srsoftware:tools.optionals:1.0.0")
implementation("de.srsoftware:tools.util:2.0.4")

1
core/build.gradle.kts

@ -10,7 +10,6 @@ repositories { @@ -10,7 +10,6 @@ repositories {
}
dependencies {
implementation("de.srsoftware:tools.mime:1.1.2")
implementation("de.srsoftware:tools.util:2.0.4")
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
testImplementation(platform("org.junit:junit-bom:5.10.0"))

2
documents/build.gradle.kts

@ -9,6 +9,4 @@ dependencies{ @@ -9,6 +9,4 @@ dependencies{
implementation("de.srsoftware:document.file:1.0.1")
implementation("de.srsoftware:document.processor:1.0.3")
implementation("de.srsoftware:document.zugferd:1.0.5")
implementation("de.srsoftware:tools.mime:1.1.2")
}

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.files;
import static de.srsoftware.tools.MimeType.MIME_FORM_DATA;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.ModuleRegistry.*;
@ -220,6 +221,13 @@ public class FileModule extends BaseHandler implements FileService { @@ -220,6 +221,13 @@ public class FileModule extends BaseHandler implements FileService {
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);
var contentType = contentType(ex).orElse(null);
if (MIME_FORM_DATA.equals(contentType)) { // file upload
// TODO: create parent directory if it does not exist
// TODO: create file and write content
return false;
}
if (file.exists()) throw unprocessable("{0} already exists!",filename);
try {
file.mkdirs();

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

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
const router = useTinyRouter();
let children = $state({});
let new_dir = $state(null);
let files = $state();
let parent = $state(false);
let form = $state(false);
let path = $state(null)
@ -95,6 +96,26 @@ @@ -95,6 +96,26 @@
return false;
}
async function upload_file(ev){
ev.preventDefault();
console.log(files);
const dataArray = new FormData();
dataArray.append("uploadFile", files);
const url = api('files'+path);
const resp = fetch(url, {
credentials: 'include',
method: 'POST',
headers: [["Content-Type", "multipart/form-data"]],
body: dataArray
});
if (resp.ok){
yikes();
} else {
error(resp);
}
return false;
}
onMount(() => loadChildren(window.location.pathname));
</script>
@ -134,10 +155,10 @@ parent: {parent} @@ -134,10 +155,10 @@ parent: {parent}
{/if}
{#if form}
<li class="action">
<form>
<form onsubmit={upload_file}>
<span class="symbol">+</span>
<input type="file" />
<button>{t('upload_file')}</button>
<input type="file" bind:files />
<button disabled={!files}>{t('upload_file')}</button>
</form>
</li>
{/if}

1
legacy/build.gradle.kts

@ -3,7 +3,6 @@ description = "Umbrella : Legacy API" @@ -3,7 +3,6 @@ description = "Umbrella : Legacy API"
dependencies{
implementation(project(":core"))
implementation(project(":user"))
implementation("de.srsoftware:tools.mime:1.1.2")
implementation("de.srsoftware:tools.web:1.3.16")
implementation("org.bitbucket.b_c:jose4j:0.9.6")
implementation("org.xerial:sqlite-jdbc:3.49.0.0")

1
markdown/build.gradle.kts

@ -2,5 +2,4 @@ description = "Umbrella : MarkdownCompanies renderer" @@ -2,5 +2,4 @@ description = "Umbrella : MarkdownCompanies renderer"
dependencies{
implementation(project(":core"))
implementation("de.srsoftware:tools.mime:1.1.2")
}

1
messages/build.gradle.kts

@ -3,7 +3,6 @@ description = "Umbrella : Message subsystem" @@ -3,7 +3,6 @@ description = "Umbrella : Message subsystem"
dependencies{
implementation(project(":core"))
implementation("com.sun.mail:jakarta.mail:2.0.1")
implementation("de.srsoftware:tools.mime:1.1.2")
implementation("org.bitbucket.b_c:jose4j:0.9.6")
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
}

1
user/build.gradle.kts

@ -3,7 +3,6 @@ description = "Umbrella : User" @@ -3,7 +3,6 @@ description = "Umbrella : User"
dependencies{
implementation(project(":core"))
implementation(project(":messages"))
implementation("de.srsoftware:tools.mime:1.1.2")
implementation("org.bitbucket.b_c:jose4j:0.9.6")
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
}
Loading…
Cancel
Save