implemented markdown renderer in backend and frontend
This commit is contained in:
@@ -16,6 +16,7 @@ dependencies{
|
|||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
implementation(project(":documents"))
|
implementation(project(":documents"))
|
||||||
implementation(project(":legacy"))
|
implementation(project(":legacy"))
|
||||||
|
implementation(project(":markdown"))
|
||||||
implementation(project(":messages"))
|
implementation(project(":messages"))
|
||||||
implementation(project(":translations"))
|
implementation(project(":translations"))
|
||||||
implementation(project(":user"))
|
implementation(project(":user"))
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import de.srsoftware.umbrella.core.Util;
|
|||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
import de.srsoftware.umbrella.documents.DocumentApi;
|
import de.srsoftware.umbrella.documents.DocumentApi;
|
||||||
import de.srsoftware.umbrella.legacy.LegacyApi;
|
import de.srsoftware.umbrella.legacy.LegacyApi;
|
||||||
|
import de.srsoftware.umbrella.markdown.MarkdownApi;
|
||||||
import de.srsoftware.umbrella.message.MessageApi;
|
import de.srsoftware.umbrella.message.MessageApi;
|
||||||
import de.srsoftware.umbrella.message.MessageSystem;
|
import de.srsoftware.umbrella.message.MessageSystem;
|
||||||
import de.srsoftware.umbrella.translations.Translations;
|
import de.srsoftware.umbrella.translations.Translations;
|
||||||
@@ -57,14 +58,16 @@ public class Application {
|
|||||||
var companyModule = new CompanyModule(config, userModule);
|
var companyModule = new CompanyModule(config, userModule);
|
||||||
var documentApi = new DocumentApi(companyModule, config);
|
var documentApi = new DocumentApi(companyModule, config);
|
||||||
var legacyApi = new LegacyApi(userModule.userDb(),config);
|
var legacyApi = new LegacyApi(userModule.userDb(),config);
|
||||||
|
var markdownApi = new MarkdownApi(userModule);
|
||||||
var messageApi = new MessageApi(messageSystem);
|
var messageApi = new MessageApi(messageSystem);
|
||||||
var webHandler = new WebHandler();
|
var webHandler = new WebHandler();
|
||||||
|
|
||||||
documentApi .bindPath("/api/document") .on(server);
|
documentApi .bindPath("/api/document") .on(server);
|
||||||
legacyApi .bindPath("/legacy") .on(server);
|
markdownApi .bindPath("/api/markdown") .on(server);
|
||||||
messageApi .bindPath("/api/messages") .on(server);
|
messageApi .bindPath("/api/messages") .on(server);
|
||||||
translationModule.bindPath("/api/translations").on(server);
|
translationModule.bindPath("/api/translations").on(server);
|
||||||
userModule .bindPath("/api/user") .on(server);
|
userModule .bindPath("/api/user") .on(server);
|
||||||
|
legacyApi .bindPath("/legacy") .on(server);
|
||||||
webHandler .bindPath("/") .on(server);
|
webHandler .bindPath("/") .on(server);
|
||||||
|
|
||||||
server.setExecutor(Executors.newFixedThreadPool(threads));
|
server.setExecutor(Executors.newFixedThreadPool(threads));
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.sun.net.httpserver.HttpExchange;
|
|||||||
import de.srsoftware.tools.Path;
|
import de.srsoftware.tools.Path;
|
||||||
import de.srsoftware.tools.PathHandler;
|
import de.srsoftware.tools.PathHandler;
|
||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
let { editable = false, value = $bindable(null) } = $props();
|
let { editable = false, value = $bindable(null) } = $props();
|
||||||
let editing = $state(false);
|
let editing = $state(false);
|
||||||
|
|
||||||
let editValue = {source:value.source,rendered:value.rendered};
|
let editValue = $state({source:value.source,rendered:value.rendered});
|
||||||
|
|
||||||
|
let timer = null;
|
||||||
function applyEdit(){
|
function applyEdit(){
|
||||||
value.source = editValue.source;
|
value.source = editValue.source;
|
||||||
value.rendered = editValue.rendered;
|
value.rendered = editValue.rendered;
|
||||||
@@ -19,10 +20,22 @@
|
|||||||
editing = editable;
|
editing = editable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function render(){
|
||||||
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/markdown/render`;
|
||||||
|
const resp = await fetch(url,{
|
||||||
|
credentials: 'include',
|
||||||
|
method: 'POST',
|
||||||
|
body: editValue.source
|
||||||
|
});
|
||||||
|
editValue.rendered = await resp.text();
|
||||||
|
}
|
||||||
|
|
||||||
function typed(ev){
|
function typed(ev){
|
||||||
if (ev.keyCode == 13 && ev.ctrlKey) applyEdit();
|
if (ev.keyCode == 13 && ev.ctrlKey) applyEdit();
|
||||||
if (ev.keyCode == 27) resetEdit();
|
if (ev.keyCode == 27) resetEdit();
|
||||||
|
|
||||||
|
if (timer) clearTimeout(timer);
|
||||||
|
timer = setTimeout(render,1000);
|
||||||
// TODO: start timer, send text to renderer, update editValue.rendered
|
// TODO: start timer, send text to renderer, update editValue.rendered
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -37,4 +50,4 @@
|
|||||||
{#if editable && editing}
|
{#if editable && editing}
|
||||||
<textarea bind:value={editValue.source} onkeyup={typed} autofocus></textarea>
|
<textarea bind:value={editValue.source} onkeyup={typed} autofocus></textarea>
|
||||||
{/if}
|
{/if}
|
||||||
<div onclick={startEdit}>{@html value.rendered}</div>
|
<div onclick={startEdit}>{@html editValue.rendered}</div>
|
||||||
|
|||||||
6
markdown/build.gradle.kts
Normal file
6
markdown/build.gradle.kts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
description = "Umbrella : MarkdownCompanies renderer"
|
||||||
|
|
||||||
|
dependencies{
|
||||||
|
implementation(project(":core"))
|
||||||
|
implementation("de.srsoftware:tools.mime:1.1.2")
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package de.srsoftware.umbrella.markdown;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
import de.srsoftware.tools.Path;
|
||||||
|
import de.srsoftware.tools.SessionToken;
|
||||||
|
import de.srsoftware.umbrella.core.BaseHandler;
|
||||||
|
import de.srsoftware.umbrella.core.Util;
|
||||||
|
import de.srsoftware.umbrella.core.api.UserService;
|
||||||
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
|
import de.srsoftware.umbrella.core.model.Token;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static de.srsoftware.tools.MimeType.MIME_HTML;
|
||||||
|
|
||||||
|
public class MarkdownApi extends BaseHandler {
|
||||||
|
|
||||||
|
private final UserService users;
|
||||||
|
|
||||||
|
public MarkdownApi(UserService userService) {
|
||||||
|
users = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doPost(Path path, HttpExchange ex) throws IOException {
|
||||||
|
try {
|
||||||
|
addCors(ex);
|
||||||
|
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||||
|
var user = users.loadUser(token);
|
||||||
|
|
||||||
|
if (user.isEmpty()) throw UmbrellaException.forbidden("You must be logged in to use the markdown renderer!");
|
||||||
|
var rendered = Util.markdown(body(ex));
|
||||||
|
ex.getResponseHeaders().add(CONTENT_TYPE,MIME_HTML);
|
||||||
|
return sendContent(ex,rendered);
|
||||||
|
} catch (UmbrellaException e){
|
||||||
|
return send(ex,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,3 +11,5 @@ include("web")
|
|||||||
|
|
||||||
include("company")
|
include("company")
|
||||||
include("contact")
|
include("contact")
|
||||||
|
|
||||||
|
include("markdown")
|
||||||
Reference in New Issue
Block a user