diff --git a/source/api/actions/davina_calendars.ts b/source/api/actions/davina_calendars.ts deleted file mode 100644 index 7314b0f..0000000 --- a/source/api/actions/davina_calendars.ts +++ /dev/null @@ -1,68 +0,0 @@ - -namespace _zeitbild.api -{ - - /** - */ - export function register_davina_calendars( - rest_subject : lib_plankton.rest_caldav.type_rest - ) : void - { - register< - null, - ( - null - | - Array< - { - id : int; - name : string; - access_level : string; - } - > - ) - > - ( - rest_subject, - lib_plankton.http.enum_method.get, - "/davina/calendars", - { - "input_schema": () => ({ - "nullable": true, - }), - "output_schema": () => ({ - "nullable": false, - "type": "boolean", - }), - "restriction": restriction_web_auth, - "execution": async (stuff) => { - const user : {id : _zeitbild.type_user_id; object : _zeitbild.type_user_object;} = await _zeitbild.api.user_from_web_auth(stuff); - - return ( - _zeitbild.service.calendar.overview(user.id) - .then( - (data_raw) => Promise.resolve( - data_raw - .map( - (entry) => ({ - "id": entry.id, - "name": entry.name, - "access_level": _zeitbild.value_object.access_level.to_string(entry.access_level), - }) - ) - ) - ) - .then( - (data) => Promise.resolve({ - "status_code": 200, - "data": data, - }) - ) - ); - }, - } - ); - } - -} - diff --git a/source/api/actions/davina_check.ts b/source/api/actions/davina_check.ts deleted file mode 100644 index 264f4f6..0000000 --- a/source/api/actions/davina_check.ts +++ /dev/null @@ -1,50 +0,0 @@ - -namespace _zeitbild.api -{ - - /** - */ - export function register_davina_check( - rest_subject : lib_plankton.rest_caldav.type_rest - ) : void - { - register< - null, - null - > - ( - rest_subject, - lib_plankton.http.enum_method.get, - "/davina/check", - { - "input_schema": () => ({ - "nullable": true, - }), - "output_schema": () => ({ - "nullable": true, - }), - "query_parameters": () => ([ - { - "name": "username", - "required": true, - "description": "username", - }, - { - "name": "password", - "required": true, - "description": "password", - }, - ]), - "restriction": restriction_web_auth, - "execution": async (stuff) => { - return Promise.resolve({ - "status_code": 200, - "data": null, - }); - }, - } - ); - } - -} - diff --git a/source/api/actions/davina_event_get.ts b/source/api/actions/davina_event_get.ts deleted file mode 100644 index 157c091..0000000 --- a/source/api/actions/davina_event_get.ts +++ /dev/null @@ -1,69 +0,0 @@ - -namespace _zeitbild.api -{ - - /** - */ - export function register_davina_event_get( - rest_subject : lib_plankton.rest_caldav.type_rest - ) : void - { - register< - null, - (null | lib_plankton.ical.type_vcalendar) - >( - rest_subject, - lib_plankton.http.enum_method.get, - "/davina/event_get", - { - "query_parameters": () => ([ - { - "name": "calendar_id", - "required": true, - "description": "calendar ID", - }, - { - "name": "event_id", - "required": true, - "description": "event ID", - }, - ]), - "output_schema": () => ({ - "nullable": false, - "type": "string", - }), - "response_body_mimetype": "text/calendar", - "response_body_encode": (output) => Buffer.from( - (typeof(output) === "string") - ? - output - : - ( - lib_plankton.ical.ics_encode(output) - /** - * @todo add event encoder function to plankton - */ - // .replace(new RegExp("[\\s\\S]*BEGIN:VEVENT([\\s\\S]*)END:VEVENT[\\s\\S]*", "m"), "BEGIN:VEVENT$1END:VEVENT") - ) - ), - "restriction": restriction_web_auth, - "execution": async (stuff) => { - const user : {id : _zeitbild.type_user_id; object : _zeitbild.type_user_object;} = await _zeitbild.api.user_from_web_auth(stuff); - - const calendar_id : int = parseInt(stuff.query_parameters["calendar_id"]); - const calendar_object : _zeitbild.type_calendar_object = await _zeitbild.service.calendar.get(calendar_id, user.id); - const event_id : int = parseInt(stuff.query_parameters["event_id"]); - const event_object : _zeitbild.type_event_object = await _zeitbild.service.resource.event_get(calendar_object.resource_id, event_id); - - return Promise.resolve( - { - "status_code": 200, - "data": _zeitbild.helpers.ical_vcalendar_from_own_event_list([event_object]), - } - ); - } - } - ); - } - -} diff --git a/source/api/actions/davina_event_list.ts b/source/api/actions/davina_event_list.ts deleted file mode 100644 index 447cca4..0000000 --- a/source/api/actions/davina_event_list.ts +++ /dev/null @@ -1,98 +0,0 @@ - -namespace _zeitbild.api -{ - - /** - */ - export function register_davina_event_list( - rest_subject : lib_plankton.rest_caldav.type_rest - ) : void - { - register< - null, - ( - Array< - { - event_id : (null | int); - event_name : string; - } - > - | - string - ) - >( - rest_subject, - lib_plankton.http.enum_method.get, - "/davina/event_list", - { - "output_schema": () => ({ - "type": "array", - "items": { - "nullable": false, - "type": "object", - "additionalProperties": false, - "properties": { - "event_id": { - "nullable": true, - "type": "number", - }, - "event_name": { - "nullable": false, - "type": "string", - }, - }, - "required": [ - "event_id", - "event_name", - ], - } - }), - "restriction": restriction_web_auth, - "execution": async (stuff) => { - const user : {id : _zeitbild.type_user_id; object : _zeitbild.type_user_object;} = await _zeitbild.api.user_from_web_auth(stuff); - - /** - * @todo - */ - const from : lib_plankton.pit.type_pit = 0; - const to : lib_plankton.pit.type_pit = 1800000000; - const calendar_id : int = parseInt(stuff.query_parameters["calendar_id"]); - - return ( - _zeitbild.service.calendar.gather_events( - [calendar_id], - from, - to, - user.id - ) - .then( - (data) => Promise.resolve( - { - "status_code": 200, - "data": ( - data - .map( - (entry) => ({ - "event_id": entry.event_id, - "event_name": entry.event_object.name, - }) - ) - ), - } - ) - ) - .catch( - (reason) => Promise.resolve( - { - "status_code": 403, - "data": String(reason), - } - ) - ) - ); - } - } - ); - } - -} diff --git a/source/api/actions/export_ical.ts b/source/api/actions/export_ics.ts similarity index 54% rename from source/api/actions/export_ical.ts rename to source/api/actions/export_ics.ts index b8f68d4..efc1f28 100644 --- a/source/api/actions/export_ical.ts +++ b/source/api/actions/export_ics.ts @@ -4,7 +4,7 @@ namespace _zeitbild.api /** */ - export function register_export_ical( + export function register_export_ics( rest_subject : lib_plankton.rest_caldav.type_rest ) : void { @@ -18,9 +18,9 @@ namespace _zeitbild.api >( rest_subject, lib_plankton.http.enum_method.get, - "/export/ical", + "/export/ics", { - "description": "trägt Veranstaltungen aus verschiedenen Kalendern zusammen im ical-Format", + "description": "trägt Veranstaltungen aus verschiedenen Kalendern zusammen im ics-Format", "query_parameters": () => ([ { "name": "from", @@ -37,11 +37,6 @@ namespace _zeitbild.api "required": false, "description": "comma separated", }, - { - "name": "auth", - "required": true, - "description": "", - }, ]), "output_schema": () => ({ "nullable": false, @@ -55,18 +50,9 @@ namespace _zeitbild.api : lib_plankton.ical.ics_encode(output) ), - "restriction": restriction_none, + "restriction": restriction_web_auth, "execution": async (stuff) => { - const user_id : (null | _zeitbild.type_user_id) = await ( - session_from_stuff(stuff) - .then( - (session : {key : string; value : lib_plankton.session.type_session;}) => ( - _zeitbild.service.user.identify(session.value.name) - .catch(x => Promise.resolve(null)) - ) - ) - .catch(x => Promise.resolve(null)) - ); + const user : {id : _zeitbild.type_user_id; object : _zeitbild.type_user_object;} = await _zeitbild.api.user_from_web_auth(stuff); const from : lib_plankton.pit.type_pit = ( ("from" in stuff.query_parameters) @@ -107,57 +93,32 @@ namespace _zeitbild.api null ); - const auth_hash_shall : string = lib_plankton.sha256.get( - (stuff.query_parameters["calendar_ids"] ?? ""), - _zeitbild.conf.get()["misc"]["auth_salt"] + return ( + _zeitbild.service.calendar.gather_events( + calendar_ids_wanted, + from, + to, + user.id + ) + .then( + (events_extended) => Promise.resolve( + { + "status_code": 200, + "data": _zeitbild.helpers.icalendar_vcalendar_from_own_event_list( + events_extended + ) + } + ) + ) + .catch( + (reason) => Promise.resolve( + { + "status_code": 403, + "data": String(reason), + } + ) + ) ); - const auth_hash_is : string = stuff.query_parameters["auth"]; - /** - * @todo remove - */ - lib_plankton.log.info( - "auth_hashes", - { - "shall": auth_hash_shall, - "is": auth_hash_is, - } - ); - if (! (auth_hash_is === auth_hash_shall)) { - return Promise.resolve( - { - "status_code": 403, - "data": "not authorized", - } - ); - } - else { - return ( - _zeitbild.service.calendar.gather_events( - calendar_ids_wanted, - from, - to, - user_id - ) - .then( - (data) => Promise.resolve( - { - "status_code": 200, - "data": _zeitbild.helpers.ical_vcalendar_from_own_event_list( - data.map(entry => entry.event_object) - ) - } - ) - ) - .catch( - (reason) => Promise.resolve( - { - "status_code": 403, - "data": String(reason), - } - ) - ) - ); - } } } ); diff --git a/source/api/functions.ts b/source/api/functions.ts index 18f7607..13c3c09 100644 --- a/source/api/functions.ts +++ b/source/api/functions.ts @@ -48,14 +48,7 @@ namespace _zeitbild.api } // export { - _zeitbild.api.register_export_ical(rest_subject); - } - // davina - { - _zeitbild.api.register_davina_check(rest_subject); - _zeitbild.api.register_davina_calendars(rest_subject); - _zeitbild.api.register_davina_event_list(rest_subject); - _zeitbild.api.register_davina_event_get(rest_subject); + _zeitbild.api.register_export_ics(rest_subject); } // misc { diff --git a/source/helpers.ts b/source/helpers.ts index 7cb1d69..b6cb9e0 100644 --- a/source/helpers.ts +++ b/source/helpers.ts @@ -7,7 +7,7 @@ namespace _zeitbild.helpers /** * @todo timezone */ - function ical_datetime_to_own_datetime( + function icalendar_datetime_to_own_datetime( ical_datetime : lib_plankton.ical.type_datetime ) : lib_plankton.pit.type_datetime { @@ -36,7 +36,7 @@ namespace _zeitbild.helpers /** * @todo timezone */ - export function ical_dt_to_own_datetime( + export function icalendar_dt_to_own_datetime( ical_dt: lib_plankton.ical.type_dt ) : lib_plankton.pit.type_datetime { @@ -61,7 +61,7 @@ namespace _zeitbild.helpers /** * @todo timezone */ - export function ical_dt_from_own_datetime( + export function icalendar_dt_from_own_datetime( datetime : lib_plankton.pit.type_datetime ) : lib_plankton.ical.type_dt { @@ -92,26 +92,47 @@ namespace _zeitbild.helpers /** */ - export function ical_vevent_from_own_event( - event_object : _zeitbild.type_event_object, - uid : string + export function icalendar_vevent_from_own_event( + event_extended : _zeitbild.type_event_extended, + index : int, + { + "stamp": stamp = "adhoc", + } + : + { + stamp ?: string; + } + = + { + } ) : lib_plankton.ical.type_vevent { return { - "uid": uid, - "dtstamp": ical_dt_from_own_datetime(event_object.begin).value, - "dtstart": ical_dt_from_own_datetime(event_object.begin), + "uid": lib_plankton.string.coin( + "zeitbild_{{stamp}}_{{id}}", + { + "stamp": stamp, + // "id": event_extended.event_id.toFixed(0), + "id": index.toFixed(0), + } + ), + "dtstamp": icalendar_dt_from_own_datetime(event_extended.event_object.begin).value, + "dtstart": icalendar_dt_from_own_datetime(event_extended.event_object.begin), "dtend": ( - (event_object.end === null) + (event_extended.event_object.end === null) ? undefined : - ical_dt_from_own_datetime(event_object.end) + icalendar_dt_from_own_datetime(event_extended.event_object.end) ), - "location": (event_object.location ?? undefined), - "summary": event_object.name, - "url": (event_object.link ?? undefined), - "description": (event_object.description ?? undefined), + "location": (event_extended.event_object.location ?? undefined), + "summary": event_extended.event_object.name, + "url": (event_extended.event_object.link ?? undefined), + "description": (event_extended.event_object.description ?? undefined), + /** + * @todo transform name + */ + "categories": [event_extended.calendar_name], }; } @@ -119,8 +140,8 @@ namespace _zeitbild.helpers /** * @todo assign better uids */ - export function ical_vcalendar_from_own_event_list( - events : Array<_zeitbild.type_event_object> + export function icalendar_vcalendar_from_own_event_list( + events_extended : Array<_zeitbild.type_event_extended> ) : lib_plankton.ical.type_vcalendar { const pit_now : lib_plankton.pit.type_pit = lib_plankton.pit.now(); @@ -137,18 +158,15 @@ namespace _zeitbild.helpers "version": "2.0", "prodid": "", "vevents": ( - events + events_extended .map( - (entry, index) => ical_vevent_from_own_event( - entry, - lib_plankton.string.coin( - "zeitbild_{{stamp}}_{{index}}", - { - "stamp": stamp, - "index": index.toFixed(0) - } - ) - ), + (event_extended, index) => icalendar_vevent_from_own_event( + event_extended, + index, + { + "stamp": stamp, + } + ) ) ), "method": "PUBLISH", diff --git a/source/services/calendar.ts b/source/services/calendar.ts index f2a21dc..2055515 100644 --- a/source/services/calendar.ts +++ b/source/services/calendar.ts @@ -389,11 +389,11 @@ namespace _zeitbild.service.calendar : "???" ), - "begin": _zeitbild.helpers.ical_dt_to_own_datetime(vevent.dtstart), + "begin": _zeitbild.helpers.icalendar_dt_to_own_datetime(vevent.dtstart), "end": ( (vevent.dtend !== undefined) ? - _zeitbild.helpers.ical_dt_to_own_datetime(vevent.dtend) + _zeitbild.helpers.icalendar_dt_to_own_datetime(vevent.dtend) : null ), @@ -454,19 +454,6 @@ namespace _zeitbild.service.calendar } - /** - */ - type type_gather_events_result = Array< - { - calendar_id : _zeitbild.type_calendar_id; - calendar_name : string; - access_level : _zeitbild.enum_access_level; - event_id : (null | _zeitbild.type_local_resource_event_id); - event_object : _zeitbild.type_event_object; - } - >; - - /** */ export async function gather_events( @@ -474,7 +461,7 @@ namespace _zeitbild.service.calendar from_pit : lib_plankton.pit.type_pit, to_pit : lib_plankton.pit.type_pit, user_id : (null | _zeitbild.type_user_id) - ) : Promise + ) : Promise> { const calendar_ids_allowed : Array<_zeitbild.type_calendar_id> = ( (await overview(user_id)) @@ -496,7 +483,7 @@ namespace _zeitbild.service.calendar ) ); calendar_ids.sort(); - return lib_plankton.cache.get_complex( + return lib_plankton.cache.get_complex>( _zeitbild.cache_regular, "gather_events", { diff --git a/source/types.ts b/source/types.ts index d27d7c2..181082f 100644 --- a/source/types.ts +++ b/source/types.ts @@ -119,5 +119,16 @@ namespace _zeitbild }; resource_id : type_resource_id; }; + + + /** + */ + export type type_event_extended = { + calendar_id : type_calendar_id; + calendar_name : string; + access_level : enum_access_level; + event_id : (null | type_local_resource_event_id); + event_object : type_event_object; + }; } diff --git a/tools/makefile b/tools/makefile index 31d77f3..d6c2da1 100644 --- a/tools/makefile +++ b/tools/makefile @@ -76,11 +76,7 @@ ${dir_temp}/zeitbild-unlinked.js: \ ${dir_source}/api/actions/calendar_event_change.ts \ ${dir_source}/api/actions/calendar_event_remove.ts \ ${dir_source}/api/actions/events.ts \ - ${dir_source}/api/actions/export_ical.ts \ - ${dir_source}/api/actions/davina_check.ts \ - ${dir_source}/api/actions/davina_calendars.ts \ - ${dir_source}/api/actions/davina_event_list.ts \ - ${dir_source}/api/actions/davina_event_get.ts \ + ${dir_source}/api/actions/export_ics.ts \ ${dir_source}/api/functions.ts \ ${dir_source}/main.ts @ ${cmd_log} "compile …"