backend/source/api/actions/caldav_projects.ts

108 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-11-28 23:08:24 +01:00
namespace _zeitbild.api
{
/**
*/
export function register_caldav_projects(
rest_subject : lib_plankton.rest_caldav.type_rest
) : void
{
register<
2024-12-01 15:21:20 +01:00
lib_plankton.xml.type_node_data,
2024-11-28 23:08:24 +01:00
(
null
|
lib_plankton.xml.type_node_data
2024-12-01 15:21:20 +01:00
)
2024-11-28 23:08:24 +01:00
>(
rest_subject,
lib_plankton.caldav.enum_method.propfind,
"/caldav/project",
{
"output_schema": () => ({
"nullable": false,
"type": "string",
}),
"request_body_mimetype": () => "text/xml",
"request_body_decode": () => async (body, header_content_type) => (
(
(header_content_type !== null)
&&
(
(header_content_type.startsWith("text/xml"))
||
(header_content_type.startsWith("application/xml"))
)
)
?
lib_plankton.xml.parse(body.toString())
:
Promise.resolve<any>(null)
),
"response_body_mimetype": "text/xml",
"response_body_encode": output => Promise.resolve<Buffer>(
Buffer.from(
lib_plankton.xml.get_node_logic(output).compile(0)
)
),
// "restriction": restriction_basic_auth,
"restriction": restriction_none,
2024-12-01 15:21:20 +01:00
/**
* @todo heed stuff.input
*/
2024-11-28 23:08:24 +01:00
"execution": async (stuff) => {
const user_id : (null | type_user_id) = await _zeitbild.api.web_auth(
stuff.headers["Authorization"]
??
stuff.headers["authorization"]
??
null
);
if (user_id === null) {
return Promise.resolve(
{
"status_code": 401,
"data": {
"kind": "text",
"data": ""
},
"extra_headers": {
"WWW-Authenticate": "Basic realm=Restricted",
}
}
);
}
else {
2024-12-01 15:21:20 +01:00
if (stuff.input === null) {
return Promise.resolve(
{
"status_code": 400,
"data": null,
}
);
}
else {
return (
_zeitbild.service.caldav.projects(
stuff.input,
user_id
2024-11-28 23:08:24 +01:00
)
2024-12-01 15:21:20 +01:00
.then(
(output) => Promise.resolve(
{
"status_code": 207,
"data": output,
}
)
)
);
}
2024-11-28 23:08:24 +01:00
}
}
}
);
}
}