|
|
|
|
@ -2,10 +2,11 @@
@@ -2,10 +2,11 @@
|
|
|
|
|
package de.srsoftware.umbrella.wiki; |
|
|
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.VERSION; |
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FULLTEXT; |
|
|
|
|
import static de.srsoftware.umbrella.core.ModuleRegistry.userService; |
|
|
|
|
import static de.srsoftware.umbrella.core.Paths.AVAILABLE; |
|
|
|
|
import static de.srsoftware.umbrella.core.Paths.PAGE; |
|
|
|
|
import static de.srsoftware.umbrella.core.Paths.*; |
|
|
|
|
import static de.srsoftware.umbrella.core.Util.mapValues; |
|
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*; |
|
|
|
|
import static de.srsoftware.umbrella.core.model.Permission.EDIT; |
|
|
|
|
import static de.srsoftware.umbrella.wiki.Constants.*; |
|
|
|
|
@ -20,7 +21,9 @@ import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
@@ -20,7 +21,9 @@ import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
|
|
|
|
import de.srsoftware.umbrella.core.model.*; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
public class WikiModule extends BaseHandler implements WikiService { |
|
|
|
|
private final WikiDb wikiDb; |
|
|
|
|
@ -105,15 +108,25 @@ public class WikiModule extends BaseHandler implements WikiService {
@@ -105,15 +108,25 @@ public class WikiModule extends BaseHandler implements WikiService {
|
|
|
|
|
Optional<Token> token = SessionToken.from(ex).map(Token::of); |
|
|
|
|
var user = userService().loadUser(token); |
|
|
|
|
if (user.isEmpty()) return unauthorized(ex); |
|
|
|
|
var title = path.pop(); |
|
|
|
|
var head = path.pop(); |
|
|
|
|
if (!path.empty()) return super.doPost(path,ex); |
|
|
|
|
return postNewPage(title,user.get(),ex); |
|
|
|
|
if (SEARCH.equals(head)) return postSearch(user.get(),ex); |
|
|
|
|
return postNewPage(head,user.get(),ex); |
|
|
|
|
} catch (UmbrellaException e){ |
|
|
|
|
return send(ex,e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean getAvailability(Path path, HttpExchange ex) throws IOException { |
|
|
|
|
private boolean postSearch(UmbrellaUser user, HttpExchange ex) throws IOException { |
|
|
|
|
var json = json(ex); |
|
|
|
|
if (!(json.has(KEY) && json.get(KEY) instanceof String key)) throw missingFieldException(KEY); |
|
|
|
|
var keys = Arrays.asList(key.split(" ")); |
|
|
|
|
var fulltext = json.has(FULLTEXT) && json.get(FULLTEXT) instanceof Boolean val && val; |
|
|
|
|
var pages = wikiDb.find(user.id(),keys,fulltext); |
|
|
|
|
return sendContent(ex,mapValues(pages)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean getAvailability(Path path, HttpExchange ex) throws IOException { |
|
|
|
|
return sendContent(ex,wikiDb.isAvailable(path.pop())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|