49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
|
namespace _aum.api
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
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};
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
export const restriction_none : lib_plankton.rest.type_restriction<any> = (
|
||
|
(stuff) => Promise.resolve<boolean>(true)
|
||
|
);
|
||
|
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
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))
|
||
|
)
|
||
|
);
|
||
|
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
export function restriction_verification(
|
||
|
extract_data : ((stuff) => any)
|
||
|
) : lib_plankton.rest.type_restriction<any>
|
||
|
{
|
||
|
return (
|
||
|
(stuff) => _aum.helpers.verification_check(
|
||
|
extract_data(stuff),
|
||
|
stuff.query_parameters["verification"]
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|