2024-09-12 00:03:29 +02:00
|
|
|
|
|
|
|
namespace _zeitbild.api
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo zu plankton auslagern?
|
|
|
|
*/
|
|
|
|
type type_stuff = {
|
|
|
|
version: (null | string);
|
|
|
|
headers: Record<string, string>;
|
|
|
|
path_parameters: Record<string, string>;
|
|
|
|
query_parameters: Record<string, string>;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function session_from_stuff(
|
|
|
|
stuff : {headers : Record<string, string>;}
|
|
|
|
) : Promise<{key : string; value : lib_plankton.session.type_session}>
|
|
|
|
{
|
|
|
|
const key : string = (stuff.headers["X-Session-Key"] || stuff.headers["X-Session-Key".toLowerCase()]);
|
|
|
|
const value : lib_plankton.session.type_session = await lib_plankton.session.get(key);
|
|
|
|
return {"key": key, "value": value};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-13 17:49:32 +02:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export const restriction_logged_in : lib_plankton.rest.type_restriction<any> = (
|
|
|
|
(stuff) => (
|
|
|
|
session_from_stuff(stuff)
|
|
|
|
.then(() => Promise.resolve<boolean>(true))
|
|
|
|
.catch(() => Promise.resolve<boolean>(false))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2024-09-12 00:03:29 +02:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export const restriction_none : lib_plankton.rest.type_restriction<any> = (
|
|
|
|
(stuff) => Promise.resolve<boolean>(true)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export function register<type_input, type_output>(
|
|
|
|
rest_subject : lib_plankton.rest.type_rest,
|
|
|
|
http_method : lib_plankton.http.enum_method,
|
|
|
|
path : string,
|
|
|
|
options : {
|
|
|
|
active ?: ((version : string) => boolean);
|
|
|
|
restriction ?: (null | lib_plankton.rest.type_restriction<type_input>);
|
|
|
|
execution ?: lib_plankton.rest.type_execution<type_input, type_output>;
|
|
|
|
title ?: (null | string);
|
|
|
|
description ?: (null | string);
|
2024-09-19 13:34:07 +02:00
|
|
|
query_parameters ?: ((version : (null | string)) => Array<
|
2024-09-12 00:03:29 +02:00
|
|
|
{
|
|
|
|
name : string;
|
|
|
|
description : (null | string);
|
|
|
|
required : boolean;
|
|
|
|
}
|
2024-09-19 13:34:07 +02:00
|
|
|
>);
|
2024-09-12 00:03:29 +02:00
|
|
|
input_schema ?: ((version: (null | string)) => lib_plankton.rest.type_oas_schema);
|
|
|
|
output_schema ?: ((version: (null | string)) => lib_plankton.rest.type_oas_schema);
|
|
|
|
request_body_mimetype ?: string;
|
|
|
|
request_body_decode ?: ((http_request_body : Buffer, http_request_header_content_type : (null | string)) => any);
|
|
|
|
response_body_mimetype ?: string;
|
|
|
|
response_body_encode ?: ((output : any) => Buffer);
|
|
|
|
} = {}
|
|
|
|
) : void
|
|
|
|
{
|
|
|
|
options = Object.assign(
|
|
|
|
{
|
|
|
|
},
|
|
|
|
options
|
|
|
|
);
|
|
|
|
lib_plankton.rest.register<type_input, type_output>(
|
|
|
|
rest_subject,
|
|
|
|
http_method,
|
|
|
|
(_zeitbild.conf.get().server.path_base + path),
|
|
|
|
options
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|