|
|
|
|
@ -7,8 +7,7 @@ import static de.srsoftware.umbrella.core.Constants.*;
@@ -7,8 +7,7 @@ import static de.srsoftware.umbrella.core.Constants.*;
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.TOKEN; |
|
|
|
|
import static de.srsoftware.umbrella.core.Paths.*; |
|
|
|
|
import static de.srsoftware.umbrella.core.Util.request; |
|
|
|
|
import static de.srsoftware.umbrella.user.Paths.NOTIFY; |
|
|
|
|
import static de.srsoftware.umbrella.user.Paths.VALIDATE_TOKEN; |
|
|
|
|
import static de.srsoftware.umbrella.user.Paths.*; |
|
|
|
|
import static java.lang.Long.parseLong; |
|
|
|
|
import static java.lang.System.Logger.Level.*; |
|
|
|
|
import static java.lang.System.Logger.Level.DEBUG; |
|
|
|
|
@ -27,10 +26,7 @@ import de.srsoftware.umbrella.user.model.UmbrellaUser;
@@ -27,10 +26,7 @@ import de.srsoftware.umbrella.user.model.UmbrellaUser;
|
|
|
|
|
import de.srsoftware.umbrella.user.sqlite.SqliteDB; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.time.Instant; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
@ -57,6 +53,7 @@ public class LegacyApi extends BaseHandler {
@@ -57,6 +53,7 @@ public class LegacyApi extends BaseHandler {
|
|
|
|
|
} |
|
|
|
|
case LOGIN -> getLogin(ex); |
|
|
|
|
case LOGOUT-> logout(ex); |
|
|
|
|
case MODULES -> getModules(ex); |
|
|
|
|
case SEARCH -> sendRedirect(ex,url(ex).replaceAll("/legacy/","/")); |
|
|
|
|
default -> super.doGet(path,ex); |
|
|
|
|
}; |
|
|
|
|
@ -93,6 +90,17 @@ public class LegacyApi extends BaseHandler {
@@ -93,6 +90,17 @@ public class LegacyApi extends BaseHandler {
|
|
|
|
|
return sendRedirect(ex,location); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean getModules(HttpExchange ex) throws IOException { |
|
|
|
|
var optToken = SessionToken.from(ex).map(Token::of); |
|
|
|
|
if (optToken.isEmpty()) return sendEmptyResponse(HTTP_UNAUTHORIZED,ex); |
|
|
|
|
var list = new ArrayList<Map<String,String>>(); |
|
|
|
|
for (var module : config.keys()){ |
|
|
|
|
Optional<String> url = config.get(module+".baseUrl"); |
|
|
|
|
url.ifPresent(u -> list.add(Map.of("module",module,URL,u))); |
|
|
|
|
} |
|
|
|
|
return sendContent(addCors(ex),list); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean jsonUser(HttpExchange ex) throws UmbrellaException, IOException { |
|
|
|
|
Map<String, Object> data = null; |
|
|
|
|
try { |
|
|
|
|
@ -214,42 +222,6 @@ public class LegacyApi extends BaseHandler {
@@ -214,42 +222,6 @@ public class LegacyApi extends BaseHandler {
|
|
|
|
|
return sendContent(ex,Map.of(REDIRECT,"home")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected Session requestSession(Token token) throws UmbrellaException { |
|
|
|
|
var session = users.load(token); |
|
|
|
|
session = users.extend(session); |
|
|
|
|
return session; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean getSearch(HttpExchange ex) throws IOException, UmbrellaException { |
|
|
|
|
var optToken = SessionToken.from(ex).map(Token::of); |
|
|
|
|
if (optToken.isEmpty()) return sendEmptyResponse(HTTP_UNAUTHORIZED,ex); |
|
|
|
|
var token = optToken.get(); |
|
|
|
|
var params = queryParam(ex); |
|
|
|
|
var key = params.get(KEY) instanceof String s ? s : null; |
|
|
|
|
if (key == null) throw new UmbrellaException(HTTP_BAD_REQUEST,"Missing search key"); |
|
|
|
|
var fulltext = key.contains("+") || "on".equals(params.get("fulltext")); |
|
|
|
|
StringBuilder searchResult = new StringBuilder(); |
|
|
|
|
if (fulltext){ |
|
|
|
|
for (var module : config.keys()){ |
|
|
|
|
var baseUrl = config.get(module + ".baseUrl"); |
|
|
|
|
if (baseUrl.isEmpty()) continue; |
|
|
|
|
|
|
|
|
|
var res = request(baseUrl.get()+"/search",token.asMap().plus(KEY,key),MIME_FORM_URL,token.asBearer()); |
|
|
|
|
if (!(res instanceof String content) || content.isBlank()) continue; |
|
|
|
|
searchResult.append("<fieldset><label>").append(module).append("</label>"); |
|
|
|
|
searchResult.append(content).append("</fieldset>\n"); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
var bookmark = config.get("bookmark.baseUrl"); |
|
|
|
|
if (bookmark.isEmpty()) throw new UmbrellaException(500,"Tag search not available: Bookmark module not configured!"); |
|
|
|
|
var res = request(bookmark.get()+"/search",token.asMap().plus(KEY,key),MIME_FORM_URL,null); |
|
|
|
|
if (!(res instanceof String content)) throw new UmbrellaException(500,"Search did not return html content!"); |
|
|
|
|
searchResult.append(content); |
|
|
|
|
} |
|
|
|
|
addCors(ex); |
|
|
|
|
return sendContent(ex,searchResult.toString()); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
private boolean postSearch(HttpExchange ex) throws IOException, UmbrellaException { |
|
|
|
|
var optToken = SessionToken.from(ex).map(Token::of); |
|
|
|
|
if (optToken.isEmpty()) return sendEmptyResponse(HTTP_UNAUTHORIZED,ex); |
|
|
|
|
@ -279,6 +251,12 @@ public class LegacyApi extends BaseHandler {
@@ -279,6 +251,12 @@ public class LegacyApi extends BaseHandler {
|
|
|
|
|
return sendContent(ex,searchResult.toString()); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
protected Session requestSession(Token token) throws UmbrellaException { |
|
|
|
|
var session = users.load(token); |
|
|
|
|
session = users.extend(session); |
|
|
|
|
return session; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String stripTrailingSlash(Object o){ |
|
|
|
|
String url = o.toString(); |
|
|
|
|
if (url.endsWith("/")) return url.substring(0,url.length()-1); |
|
|
|
|
|