sky: interpret POST requests as pokes

on hearing a POST, the hawk will:

- find a poke-stud in the requesting url
- build a converstion from node to that poke-stud
- convert the body of the request (content-type=html) to the
  poke
- attempt to find a conversion from poke-stud to htmx
  - if none is found, a default refresher is returned
- "apply" the poke and return some html
This commit is contained in:
Will Hanlen 2024-05-30 16:00:21 +02:00 committed by SuperCoolYun
parent 10279f7f66
commit 79794cc20b
2 changed files with 452 additions and 471 deletions

View File

@ -1,15 +1,50 @@
/@ htmx-type=htmx
/@ htmx-type=htmx
/@ htmx-type=htmx
/- feather-icons
/- serv=sky-server
/- serv=server
/> htmx
/< node
=>
|%
++ manx-to-octs
|%
++ main
^- curb:neo
[%or rol/[%ui-main pro/%htmx] pro/%htmx ~]
:: rol/[%ui-main pro/%htmx]
++ kids-curb
^- curb:neo
any/~
:: rol/[%ui-list pro/%htmx]
++ manx-to-octs
|= man=manx
(as-octt:mimes:html (en-xml:html man))
++ eyre-cards
::
++ render
|= [main=manx kids=marl]
;div
;+ main
;div
;* kids
==
==
++ parse-url
|= =request:http
^- [pax=path pam=(map @t @t)]
=/ parsed
%+ rash url.request
;~ plug
;~(pfix fas (more fas smeg:de-purl:html))
yque:de-purl:html
==
:- (slag 2 -.parsed) :: strip first 2 segments (/neo/hawk)
(malt +.parsed)
++ parse-body
|= =request:http
^- manx
%+ fall
(de-xml:html q:(fall body.request [p=0 q='']))
*manx
++ eyre-cards
|= [eyre-id=@ta =bowl:neo status=@ud =manx]
^- (list card:neo)
=/ =pith:neo #/[p/our.bowl]/$/eyre
@ -21,7 +56,7 @@
[pith %poke eyre-sign/!>(done)]
[here.bowl %cull ~]
==
++ default-refresher
++ default-refresher
|= =pith
=/ tath (en-tape:pith:neo pith)
;div
@ -32,13 +67,11 @@
=hx-swap "outerHTML"
;
==
++ hawk
|_ [here=pith main=manx raw=manx has-app=?]
++ hawk
|_ [here=pith main=manx raw=manx]
++ id *@da
++ our-tape
=/ f (snag 0 here)
?@(f (trip f) (scow f))
++ idt `tape`(zing (scan +:(scow %da id) (most dot (star ;~(less dot prn)))))
++ has-app %.y :: XX : switch on it. make it real. etc
++ slot 0 :: XX fix sky positional saving
++ lift
;div.hawk.fc.wf.hf
@ -46,10 +79,7 @@
=hx-params "id,slot"
=hx-vals "\{\"id\": \"{<id>}\", \"slot\": \"{<slot>}\"}"
;+ header
;div
=class "raw p-page wf hf b0 scroll-y scroll-x {(trip ?:(has-app 'hidden' ''))}"
;+ raw
==
::;+ raw
;div
=class "rendered wf hf b0 scroll-y scroll-x {(trip ?:(has-app '' 'hidden'))}"
=id "hawk-rendered-{idt}"
@ -130,7 +160,7 @@
=id "hawk-actions-{idt}"
;button.p1.hover.b2.br1.loader.s-1
=id "hawk-slide-up-{idt}"
=hx-post "/neo/hawk/{our-tape}/sky?stud=sky-diff"
=hx-post "/neo/hawk/sky?stud=sky-diff"
=hx-target "find .loading"
=hx-swap "outerHTML"
=head "slide-up"
@ -144,7 +174,7 @@
==
;button.p1.hover.b2.br1.loader.s-1
=id "hawk-slide-down-{idt}"
=hx-post "/neo/hawk/{our-tape}/sky?stud=sky-diff"
=hx-post "/neo/hawk/sky?stud=sky-diff"
=hx-target "find .loading"
=hx-swap "outerHTML"
=head "slide-down"
@ -158,7 +188,7 @@
==
;button.p1.hover.b2.br1.loader.s-1
=id "hawk-close-{idt}"
=hx-post "/neo/hawk/{our-tape}/sky?stud=sky-diff"
=hx-post "/neo/hawk/sky?stud=sky-diff"
=hx-target "find .loading"
=hx-swap "outerHTML"
=head "minimize"
@ -183,7 +213,7 @@
==
==
--
--
--
^- kook:neo
|%
++ state pro/%eyre-task
@ -219,14 +249,13 @@
=/ [=stud:neo =vase] (need pal)
=+ !<([eyre-id=@ta req=inbound-request:eyre] vase)
:_ [stud vase]
::XX revive when auth
::?. authenticated.req
:: %: eyre-cards
:: eyre-id
:: bowl
:: 403
:: ;div: 403
:: ==
?. authenticated.req
%: eyre-cards
eyre-id
bowl
403
;div: 40
==
?~ src=(~(get by deps.bowl) %src)
%: eyre-cards
eyre-id
@ -234,12 +263,6 @@
404
;div: 404
==
%: eyre-cards
eyre-id
bowl
200
~(lift hawk #/[p/our.bowl] main raw |)
==
=/ here p.u.src
^- (list card:neo)
?+ method.request.req ~|(%unsupported-http-method !!)
@ -255,54 +278,22 @@
:: XX src.bowl
=/ main (!<(htmx-type q.pail.root) bol)
=/ raw *manx
=/ raw *manx
%: eyre-cards
eyre-id
bowl
200
~(lift hawk here.bol main raw)
==
%: eyre-cards
eyre-id
bowl
200
~(lift hawk here.bol main raw &)
==
::
%'POST'
=/ purl (parse-url:serv request.req)
=/ body (parse-body:serv request.req)
=/ purl (parse-url request.req)
=/ body (parse-body request.req)
=/ poke-stud
^- stud:neo
~| %no-stud-specified
(~(got by pam.purl) 'stud')
=/ mul (mule |.((node [poke-stud body])))
?- -.mul
%.n
%: eyre-cards
eyre-id
bowl
400
;div
;*
%+ turn (tang p.mul)
|= =tank
;div: {(of-wall:format (~(win re tank) 0 55))}
==
==
%: eyre-cards
eyre-id
bowl
400
;div
;*
%+ turn (tang p.mul)
|= =tank
;div: {(of-wall:format (~(win re tank) 0 55))}
==
==
::
%.y
=/ =pail:neo [poke-stud p.mul]
=/ =pail:neo [poke-stud (node [poke-stud body])]
=/ bol *bowl:neo
=. here.bol here
=. our.bol our.bowl
@ -311,13 +302,8 @@
=/ =manx
?~ converter=(mole |.((htmx pail)))
(default-refresher here)
=/ mul
%- mule
|.((u.converter bol))
?- -.mul
%.y p.mul
%.n ;div: error
==
:: XX virtualize
(u.converter bol)
:- [here %poke pail]
%: eyre-cards
eyre-id
@ -325,13 +311,6 @@
200
manx
==
%: eyre-cards
eyre-id
bowl
200
manx
==
==
==
--
--

View File

@ -12,70 +12,29 @@
=<
^- kook:neo
|%
++ state pro/%eyre-task
++ poke *(set stud:neo)
++ kids
:+ ~ %y
%- ~(gas by *lads:neo)
~
++ deps
%- ~(gas by *band:neo)
:~ :- %src
^- fief:neo
:- req=|
^- quay:neo
:- [pro/%htmx ~]
^- (unit port:neo)
:+ ~ %y
%- ~(gas by *lads:neo)
:~ :- &
`lash:neo`[any/~ ~]
==
==
::
++ form
|_ [=bowl:neo =aeon:neo =pail:neo]
++ poke
|= [=stud:neo vax=vase]
^- (quip card:neo pail:neo)
`pail
++ init
|= pal=(unit pail:neo)
=/ [=stud:neo =vase] (need pal)
=+ !<([eyre-id=@ta req=inbound-request:eyre] vase)
:_ [stud vase]
=/ =pith:neo #/[p/our.bowl]/$/eyre
=; =manx
=/ head=sign:eyre:neo [eyre-id %head [200 [['content-type' 'text/html'] ~]]]
=/ data=sign:eyre:neo [eyre-id %data `(manx-to-octs manx)]
=/ done=sign:eyre:neo [eyre-id %done ~]
:~ [pith %poke eyre-sign/!>(head)]
[pith %poke eyre-sign/!>(data)]
[pith %poke eyre-sign/!>(done)]
[here.bowl %cull ~]
==
?~ src=(~(get by deps.bowl) %src)
;div: 404
=/ root=idea:neo (~(got of:neo q.u.src) /)
?> =(%htmx p.pail.root)
=/ bol *bowl:neo
=. here.bol p.u.src
=. our.bol our.bowl
=. now.bol now.bowl
=. eny.bol eny.bowl
=. kids.bol q.u.src
:: XX src.bowl
(lift (!<(htmx q.pail.root) bol))
--
--
|%
++ manx-to-octs
++ main
^- curb:neo
[%or rol/[%ui-main pro/%htmx] pro/%htmx ~]
:: rol/[%ui-main pro/%htmx]
++ kids-curb
^- curb:neo
any/~
:: rol/[%ui-list pro/%htmx]
++ manx-to-octs
|= man=manx
%- as-octt:mimes:html
%+ welp "<!DOCTYPE html>"
(en-xml:html man)
::
++ icon-url
::
++ render
|= [main=manx kids=marl]
;div
;+ main
;div
;* kids
==
==
++ icon-url
^~
%- trip
%^ cat
@ -83,7 +42,7 @@
'data:image/png;base64,'
%- ~(en base64:mimes:html & |)
(as-octs:mimes:html hawk-icon)
++ favicon
++ favicon
^~
=; m m(a.g [[%href icon-url] a.g.m])
^- manx
@ -92,7 +51,7 @@
=type "image/png"
;
==
++ manifest-url
++ manifest-url
^~
%- trip
%^ cat
@ -116,7 +75,7 @@
==
==
==
++ manifest
++ manifest
^~
=; m m(a.g [[%href manifest-url] a.g.m])
^- manx
@ -124,7 +83,7 @@
=rel "manifest"
;
==
++ htmx-extensions
++ htmx-extensions
:: htmx extension which encodes the request
:: as the serialized HTML of the calling element
%- trip
@ -164,8 +123,8 @@
}
}
'''
::
++ lift
::
++ lift
|= in=manx
^- manx
;html
@ -206,27 +165,12 @@
;style: {(trip reset)}
;style: {(trip feather)}
;script
;+ ;/ %- trip
'''
window.log = function() {
if (this.console) {
console.log(Array.prototype.slice.call(arguments));
}
};
jQuery.fn.log = function (msg) {
console.log(msg, this);
return this;
};
jQuery.fn.emit = function (name) {
(this[0]).dispatchEvent(
new Event(
name,
{ bubbles: true, cancelable: true, composed: true }
)
);
return this;
};
'''
;+ ;/
"""
window.log=function()\{if(this.console)\{console.log(Array.prototype.slice.call(arguments));}};
jQuery.fn.log=function (msg)\{console.log(msg, this); return this;};
jQuery.fn.emit=function (name)\{(this[0]).dispatchEvent(new Event(name, \{ bubbles: true, cancelable: true, composed: true })); return this;};
"""
==
;script: {(trip a-i-r)}
;script: {(trip date-now)}
@ -250,4 +194,62 @@
;+ in
==
==
--
^- kook:neo
|%
++ state pro/%eyre-task
++ poke *(set stud:neo)
++ kids
:+ ~ %y
%- ~(gas by *lads:neo)
~
++ deps
%- ~(gas by *band:neo)
:~ :- %src
^- fief:neo
:- req=|
^- quay:neo
:- [main ~]
^- (unit port:neo)
:+ ~ %y
%- ~(gas by *lads:neo)
:~ :- &
`lash:neo`[kids-curb ~]
==
==
::
++ form
|_ [=bowl:neo =aeon:neo =pail:neo]
++ poke
|= [=stud:neo vax=vase]
^- (quip card:neo pail:neo)
`pail
++ init
|= pal=(unit pail:neo)
=/ [=stud:neo =vase] (need pal)
=+ !<([eyre-id=@ta req=inbound-request:eyre] vase)
:_ [stud vase]
=/ =pith:neo #/[p/our.bowl]/$/eyre
=; =manx
=/ head=sign:eyre:neo [eyre-id %head [200 [['content-type' 'text/html'] ~]]]
=/ data=sign:eyre:neo [eyre-id %data `(manx-to-octs manx)]
=/ done=sign:eyre:neo [eyre-id %done ~]
:~ [pith %poke eyre-sign/!>(head)]
[pith %poke eyre-sign/!>(data)]
[pith %poke eyre-sign/!>(done)]
[here.bowl %cull ~]
==
?~ src=(~(get by deps.bowl) %src)
;div: 404
=/ root=idea:neo (~(got of:neo q.u.src) /)
?> =(%htmx p.pail.root)
=/ bol *bowl:neo
=. here.bol p.u.src
=. our.bol our.bowl
=. now.bol now.bowl
=. eny.bol eny.bowl
=. kids.bol q.u.src
:: XX src.bowl
(lift (!<(htmx q.pail.root) bol))
--
--