factor-work/bonerbonerboner/actions/actions.factor

45 lines
1.2 KiB
Factor
Raw Normal View History

2023-09-06 15:04:55 -04:00
USING: kernel furnace.actions sequences validators accessors html.forms http.server.responses http.server.dispatchers formatting assocs ;
2023-06-16 21:37:31 -04:00
USING: bonerbonerboner.dns ;
IN: bonerbonerboner.actions
TUPLE: bbb-dispatcher < dispatcher ;
: v-valid-subdomain ( str -- subdomain )
dup get-subdomains member? [ "not a valid subdomain" throw ] unless ;
: validate-subdomain ( -- )
{
{ "name" [ v-required v-valid-subdomain ] }
} validate-params ;
: <subdomain-action> ( -- action )
<page-action>
[
validate-subdomain
"name" value "subdomain" set-value
] >>init
{ bbb-dispatcher "subdomains" } >>template ;
: <404-subdomain-action> ( -- action )
<page-action>
[ "_404" "subdomain" set-value ] >>init
{ bbb-dispatcher "subdomains" } >>template ;
: <heartbeat-action> ( -- action )
<action> [ "bonerbonerboner" <text-content> ] >>display ;
TUPLE: subdomain-link subdomain url ;
2023-09-06 15:04:55 -04:00
: get-subdomain-links ( -- subdomain-links )
2023-09-06 15:20:26 -04:00
get-subdomains [ "bbb" = ] reject
2023-09-06 15:04:55 -04:00
[ first dup "https://%s.bonerbonerboner.com" sprintf subdomain-link boa ] map ;
2023-06-16 21:37:31 -04:00
: <meta-action> ( -- action )
<page-action>
[
2023-09-06 15:04:55 -04:00
get-subdomain-links "subdomains" set-value
2023-06-16 21:37:31 -04:00
] >>init
{ bbb-dispatcher "meta" } >>template ;