added URL to ical
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -91,12 +91,13 @@ public class ApiEndpoint extends PathHandler {
|
||||
|
||||
@Override
|
||||
public boolean doGet(String path, HttpExchange ex) throws IOException {
|
||||
String hostname = hostname(ex).split("://",2)[1];
|
||||
String prodId = "OpenCloudCal@"+hostname;
|
||||
String hostname = hostname(ex);
|
||||
String urlTemplate = hostname+"/static/event?id={}";
|
||||
String prodId = "OpenCloudCal@"+hostname.split("://",2)[1];
|
||||
return switch (path) {
|
||||
case "/event" -> sendContent(ex,getEvent(ex).map(ApiEndpoint::toJson).map(ApiEndpoint::httpError));
|
||||
case "/event/ical"-> sendContent(ex,getEvent(ex).map(event -> toIcal(event,hostname)).map(ical -> Util.wrapIcal(ical,prodId)).map(ApiEndpoint::httpError));
|
||||
case "/events/ical"-> sendContent(ex,eventList(ex).map(list -> toIcalList(list,hostname)).map(ical -> Util.wrapIcal(ical,prodId)).map(ApiEndpoint::httpError));
|
||||
case "/event/ical"-> sendContent(ex,getEvent(ex).map(event -> toIcal(event, hostname, urlTemplate)).map(ical -> Util.wrapIcal(ical,prodId)).map(ApiEndpoint::httpError));
|
||||
case "/events/ical"-> sendContent(ex,eventList(ex).map(list -> toIcalList(list, hostname, urlTemplate)).map(ical -> Util.wrapIcal(ical,prodId)).map(ApiEndpoint::httpError));
|
||||
case "/events/json" -> sendContent(ex,eventList(ex).map(ApiEndpoint::toJsonList).map(ApiEndpoint::httpError));
|
||||
case "/tags" -> listTags(ex);
|
||||
default -> unknownPath(ex, path);
|
||||
@@ -265,15 +266,15 @@ public class ApiEndpoint extends PathHandler {
|
||||
return Payload.of(event);
|
||||
}
|
||||
|
||||
private static Result<String> toIcal(Result<Appointment> res, String hostname) {
|
||||
private static Result<String> toIcal(Result<Appointment> res, String hostname, String urlTemplate) {
|
||||
var opt = res.optional();
|
||||
return opt.isEmpty() ? transform(res) : Payload.of(opt.get().ical(hostname));
|
||||
return opt.isEmpty() ? transform(res) : Payload.of(opt.get().ical(hostname, urlTemplate));
|
||||
}
|
||||
|
||||
private static Result<String> toIcalList(Result<List<Appointment>> res, String hostname) {
|
||||
private static Result<String> toIcalList(Result<List<Appointment>> res, String hostname, String urlTemplate) {
|
||||
var opt = res.optional();
|
||||
if (opt.isEmpty()) return transform(res);
|
||||
var list = opt.get().stream().map(event -> event.ical(hostname)).collect(Collectors.joining("\n"));
|
||||
var list = opt.get().stream().map(event -> event.ical(hostname, urlTemplate)).collect(Collectors.joining("\n"));
|
||||
return Payload.of(list);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user