peparing for file upload on server side
This commit is contained in:
@@ -42,7 +42,8 @@ subprojects {
|
|||||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||||
implementation("de.srsoftware:configuration.api:1.0.2")
|
implementation("de.srsoftware:configuration.api:1.0.2")
|
||||||
implementation("de.srsoftware:tools.jdbc:2.0.0")
|
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.logging:1.3.2")
|
||||||
implementation("de.srsoftware:tools.optionals:1.0.0")
|
implementation("de.srsoftware:tools.optionals:1.0.0")
|
||||||
implementation("de.srsoftware:tools.util:2.0.4")
|
implementation("de.srsoftware:tools.util:2.0.4")
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("de.srsoftware:tools.mime:1.1.2")
|
|
||||||
implementation("de.srsoftware:tools.util:2.0.4")
|
implementation("de.srsoftware:tools.util:2.0.4")
|
||||||
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
|
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
|
||||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||||
|
|||||||
@@ -9,6 +9,4 @@ dependencies{
|
|||||||
implementation("de.srsoftware:document.file:1.0.1")
|
implementation("de.srsoftware:document.file:1.0.1")
|
||||||
implementation("de.srsoftware:document.processor:1.0.3")
|
implementation("de.srsoftware:document.processor:1.0.3")
|
||||||
implementation("de.srsoftware:document.zugferd:1.0.5")
|
implementation("de.srsoftware:document.zugferd:1.0.5")
|
||||||
|
|
||||||
implementation("de.srsoftware:tools.mime:1.1.2")
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
/* © SRSoftware 2025 */
|
/* © SRSoftware 2025 */
|
||||||
package de.srsoftware.umbrella.files;
|
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.ConnectionProvider.connect;
|
||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
import static de.srsoftware.umbrella.core.ModuleRegistry.*;
|
import static de.srsoftware.umbrella.core.ModuleRegistry.*;
|
||||||
@@ -220,6 +221,13 @@ public class FileModule extends BaseHandler implements FileService {
|
|||||||
if (!path.empty()) filename += "/"+URLDecoder.decode(path.toString(),UTF_8);
|
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);
|
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 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);
|
if (file.exists()) throw unprocessable("{0} already exists!",filename);
|
||||||
try {
|
try {
|
||||||
file.mkdirs();
|
file.mkdirs();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
const router = useTinyRouter();
|
const router = useTinyRouter();
|
||||||
let children = $state({});
|
let children = $state({});
|
||||||
let new_dir = $state(null);
|
let new_dir = $state(null);
|
||||||
|
let files = $state();
|
||||||
let parent = $state(false);
|
let parent = $state(false);
|
||||||
let form = $state(false);
|
let form = $state(false);
|
||||||
let path = $state(null)
|
let path = $state(null)
|
||||||
@@ -95,6 +96,26 @@
|
|||||||
return false;
|
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));
|
onMount(() => loadChildren(window.location.pathname));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -134,10 +155,10 @@ parent: {parent}
|
|||||||
{/if}
|
{/if}
|
||||||
{#if form}
|
{#if form}
|
||||||
<li class="action">
|
<li class="action">
|
||||||
<form>
|
<form onsubmit={upload_file}>
|
||||||
<span class="symbol">+</span>
|
<span class="symbol">+</span>
|
||||||
<input type="file" />
|
<input type="file" bind:files />
|
||||||
<button>{t('upload_file')}</button>
|
<button disabled={!files}>{t('upload_file')}</button>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ description = "Umbrella : Legacy API"
|
|||||||
dependencies{
|
dependencies{
|
||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
implementation(project(":user"))
|
implementation(project(":user"))
|
||||||
implementation("de.srsoftware:tools.mime:1.1.2")
|
|
||||||
implementation("de.srsoftware:tools.web:1.3.16")
|
implementation("de.srsoftware:tools.web:1.3.16")
|
||||||
implementation("org.bitbucket.b_c:jose4j:0.9.6")
|
implementation("org.bitbucket.b_c:jose4j:0.9.6")
|
||||||
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
|
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
|
||||||
|
|||||||
@@ -2,5 +2,4 @@ description = "Umbrella : MarkdownCompanies renderer"
|
|||||||
|
|
||||||
dependencies{
|
dependencies{
|
||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
implementation("de.srsoftware:tools.mime:1.1.2")
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ description = "Umbrella : Message subsystem"
|
|||||||
dependencies{
|
dependencies{
|
||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
implementation("com.sun.mail:jakarta.mail:2.0.1")
|
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.bitbucket.b_c:jose4j:0.9.6")
|
||||||
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
|
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ description = "Umbrella : User"
|
|||||||
dependencies{
|
dependencies{
|
||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
implementation(project(":messages"))
|
implementation(project(":messages"))
|
||||||
implementation("de.srsoftware:tools.mime:1.1.2")
|
|
||||||
implementation("org.bitbucket.b_c:jose4j:0.9.6")
|
implementation("org.bitbucket.b_c:jose4j:0.9.6")
|
||||||
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
|
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user