added URL to ical
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -39,9 +39,10 @@ public interface Appointment {
|
||||
/**
|
||||
* represent this event as ical entry
|
||||
* @param calendarIdentifier used to generate a unique id. pass something that is unique, but stable over time, e.g. a hostname
|
||||
* @param urlTemplate the url to put into the ical, with "{}" being replaced by the appointment id
|
||||
* @return the ical string
|
||||
*/
|
||||
String ical(String calendarIdentifier);
|
||||
String ical(String calendarIdentifier,String urlTemplate);
|
||||
|
||||
/**
|
||||
* ID of the appointment – unique within this system
|
||||
|
||||
@@ -125,7 +125,7 @@ public class BaseAppointment implements Appointment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String ical(String calendarIdentifier) { // TODO: implement
|
||||
public String ical(String calendarIdentifier,String urlTemplate) { // TODO: implement
|
||||
var sb = new StringBuilder();
|
||||
sb.append(contentLine(BEGIN,VEVENT));
|
||||
if (calendarIdentifier != null) sb.append(contentLine(UID,"%s@%s".formatted(id(),calendarIdentifier)));
|
||||
@@ -133,6 +133,7 @@ public class BaseAppointment implements Appointment {
|
||||
end().map(end -> contentLine(DTEND,end.format(ICAL_DATE_FORMAT).replace(" ","T"))).ifPresent(sb::append);
|
||||
sb.append(contentLine(SUMMARY,title()));
|
||||
sb.append(contentLine(DESCRIPTION,description()));
|
||||
sb.append(contentLine(URL,urlTemplate.replace("{}",""+id())));
|
||||
coords().map(Coords::icalFormat).map(geo -> contentLine(GEO,geo)).ifPresent(sb::append);
|
||||
location().map(loc -> contentLine(LOCATION,loc)).ifPresent(sb::append);
|
||||
for (var attachment : attachments()) sb.append(contentLine("ATTACH;FMTYPE=%s".formatted(attachment.mime()),attachment.url().toString()));
|
||||
|
||||
@@ -36,6 +36,7 @@ public class Util {
|
||||
public static final String PRODID = "PRODID";
|
||||
public static final String SUMMARY = "SUMMARY";
|
||||
public static final String UID = "UID";
|
||||
public static final String URL = "URL";
|
||||
public static final String VERSION = "VERSION";
|
||||
public static final String VEVENT = "VEVENT";
|
||||
public static final String VCALENDAR = "VCALENDAR";
|
||||
|
||||
@@ -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