2020-07-15 22:26:55 +03:00
|
|
|
/- srv=file-server, glob
|
2020-04-30 03:41:31 +03:00
|
|
|
/+ *server, default-agent, verb, dbug
|
|
|
|
|%
|
|
|
|
+$ card card:agent:gall
|
|
|
|
+$ versioned-state
|
|
|
|
$% state-zero
|
|
|
|
==
|
|
|
|
::
|
2020-07-15 22:26:55 +03:00
|
|
|
+$ serving (map url-base=path [=content public=?])
|
|
|
|
+$ content
|
|
|
|
$% [%clay =path]
|
|
|
|
[%glob =glob:glob]
|
|
|
|
==
|
2020-05-19 22:56:07 +03:00
|
|
|
+$ state-zero
|
|
|
|
$: %0
|
2020-06-01 21:28:05 +03:00
|
|
|
=configuration:srv
|
2020-05-28 01:00:40 +03:00
|
|
|
=serving
|
2020-05-19 22:56:07 +03:00
|
|
|
==
|
2020-04-30 03:41:31 +03:00
|
|
|
--
|
2020-06-01 21:28:05 +03:00
|
|
|
::
|
2020-04-30 03:41:31 +03:00
|
|
|
%+ verb |
|
|
|
|
%- agent:dbug
|
2020-06-01 21:28:05 +03:00
|
|
|
::
|
2020-04-30 03:41:31 +03:00
|
|
|
=| state-zero
|
|
|
|
=* state -
|
|
|
|
^- agent:gall
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
def ~(. (default-agent this %|) bowl)
|
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
2020-05-28 01:40:32 +03:00
|
|
|
|^
|
2020-05-28 01:00:40 +03:00
|
|
|
:_ %_ this
|
|
|
|
serving
|
|
|
|
%- ~(gas by *^serving)
|
|
|
|
%+ turn
|
|
|
|
^- (list path)
|
2020-05-28 21:47:34 +03:00
|
|
|
[/ /'~landscape' ~]
|
2020-07-15 22:26:55 +03:00
|
|
|
|=(pax=path [pax [clay+/app/landscape %.n]])
|
2020-05-28 01:00:40 +03:00
|
|
|
==
|
2020-05-28 01:40:32 +03:00
|
|
|
:~ (connect /)
|
|
|
|
(connect /'~landscape')
|
2020-05-28 01:00:40 +03:00
|
|
|
==
|
2020-05-28 01:40:32 +03:00
|
|
|
::
|
|
|
|
++ connect
|
|
|
|
|= =path
|
|
|
|
^- card
|
2020-05-28 21:36:31 +03:00
|
|
|
[%pass path %arvo %e %connect [~ path] %file-server]
|
2020-05-28 01:40:32 +03:00
|
|
|
--
|
2020-05-06 01:27:39 +03:00
|
|
|
::
|
2020-04-30 03:41:31 +03:00
|
|
|
++ on-save !>(state)
|
|
|
|
++ on-load
|
|
|
|
|= old-vase=vase
|
|
|
|
^- (quip card _this)
|
|
|
|
[~ this(state !<(state-zero old-vase))]
|
|
|
|
::
|
|
|
|
++ on-poke
|
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
|
|
|
|^
|
2020-05-28 01:56:20 +03:00
|
|
|
?> (team:title our.bowl src.bowl)
|
2020-04-30 03:41:31 +03:00
|
|
|
?+ mark (on-poke:def mark vase)
|
2020-06-01 21:28:05 +03:00
|
|
|
%file-server-action (file-server-action !<(action:srv vase))
|
2020-04-30 03:41:31 +03:00
|
|
|
%handle-http-request
|
|
|
|
=+ !<([id=@ta req=inbound-request:eyre] vase)
|
|
|
|
:_ this
|
2020-05-19 22:56:07 +03:00
|
|
|
%+ give-simple-payload:app id
|
|
|
|
(handle-http-request req)
|
2020-04-30 03:41:31 +03:00
|
|
|
==
|
|
|
|
::
|
2020-05-28 21:36:31 +03:00
|
|
|
++ file-server-action
|
2020-06-01 21:28:05 +03:00
|
|
|
|= act=action:srv
|
2020-05-19 22:56:07 +03:00
|
|
|
^- (quip card _this)
|
2020-05-28 01:40:32 +03:00
|
|
|
|^
|
2020-05-19 22:56:07 +03:00
|
|
|
?- -.act
|
|
|
|
%serve-dir
|
2020-05-28 01:00:40 +03:00
|
|
|
=* url-base url-base.act
|
2020-05-29 19:57:51 +03:00
|
|
|
?: (~(has by serving) url-base)
|
|
|
|
~|("url already bound to {<(~(got by serving) url-base.act)>}" !!)
|
2020-05-28 21:36:31 +03:00
|
|
|
:- [%pass url-base %arvo %e %connect [~ url-base] %file-server]~
|
2020-07-15 22:26:55 +03:00
|
|
|
this(serving (~(put by serving) url-base clay+clay-base.act public.act))
|
|
|
|
::
|
|
|
|
%serve-glob
|
|
|
|
=* url-base url-base.act
|
|
|
|
?: (~(has by serving) url-base)
|
|
|
|
~|("url already bound to {<(~(got by serving) url-base.act)>}" !!)
|
|
|
|
:- [%pass url-base %arvo %e %connect [~ url-base] %file-server]~
|
|
|
|
this(serving (~(put by serving) url-base glob+glob.act public.act))
|
2020-05-21 00:43:15 +03:00
|
|
|
::
|
2020-05-19 22:56:07 +03:00
|
|
|
%unserve-dir
|
2020-05-28 01:40:32 +03:00
|
|
|
:- [%pass url-base.act %arvo %e %disconnect [~ url-base.act]]~
|
|
|
|
this(serving (~(del by serving) url-base.act))
|
2020-05-21 00:43:15 +03:00
|
|
|
::
|
|
|
|
%toggle-permission
|
|
|
|
?. (~(has by serving) url-base.act)
|
|
|
|
~|("url is not bound" !!)
|
2020-07-15 22:26:55 +03:00
|
|
|
=/ [=content public=?] (~(got by serving) url-base.act)
|
2020-05-19 22:56:07 +03:00
|
|
|
:- ~
|
2020-07-15 22:26:55 +03:00
|
|
|
this(serving (~(put by serving) url-base.act [content !public]))
|
2020-05-28 01:40:32 +03:00
|
|
|
::
|
|
|
|
%set-landscape-homepage-prefix
|
|
|
|
=. landscape-homepage-prefix.configuration prefix.act
|
|
|
|
:_ this
|
|
|
|
(give [%configuration configuration])
|
2020-05-19 22:56:07 +03:00
|
|
|
==
|
2020-05-28 01:40:32 +03:00
|
|
|
::
|
|
|
|
++ give
|
2020-06-01 21:28:05 +03:00
|
|
|
|= =update:srv
|
2020-05-28 01:40:32 +03:00
|
|
|
^- (list card)
|
2020-05-28 21:36:31 +03:00
|
|
|
[%give %fact [/all]~ [%file-server-update !>(update)]]~
|
2020-05-28 01:40:32 +03:00
|
|
|
--
|
2020-05-19 22:56:07 +03:00
|
|
|
::
|
2020-04-30 03:41:31 +03:00
|
|
|
++ handle-http-request
|
|
|
|
|= =inbound-request:eyre
|
|
|
|
^- simple-payload:http
|
2020-05-28 01:00:40 +03:00
|
|
|
|^
|
2020-05-19 22:56:07 +03:00
|
|
|
=* req request.inbound-request
|
|
|
|
=* headers header-list.req
|
2020-04-30 03:41:31 +03:00
|
|
|
=/ req-line (parse-request-line url.req)
|
2020-05-28 01:00:40 +03:00
|
|
|
?. =(method.req %'GET') not-found:gen
|
2020-05-19 22:56:07 +03:00
|
|
|
=? req-line ?=(~ ext.req-line)
|
2020-05-28 01:00:40 +03:00
|
|
|
[[[~ %html] ~['index']] args.req-line]
|
2020-05-19 22:56:07 +03:00
|
|
|
?> ?=(^ ext.req-line)
|
|
|
|
?~ site.req-line
|
|
|
|
not-found:gen
|
2020-05-28 01:40:32 +03:00
|
|
|
=* url-prefix landscape-homepage-prefix.configuration
|
2020-05-28 22:28:02 +03:00
|
|
|
?. ?| ?=(~ url-prefix)
|
|
|
|
=(u.url-prefix i.site.req-line)
|
2020-04-30 03:41:31 +03:00
|
|
|
==
|
|
|
|
not-found:gen
|
2020-05-19 22:56:07 +03:00
|
|
|
::
|
2020-05-21 00:43:15 +03:00
|
|
|
?: ?=([%'~landscape' %js %session ~] site.req-line)
|
2020-05-19 22:56:07 +03:00
|
|
|
%+ require-authorization-simple:app
|
|
|
|
inbound-request
|
|
|
|
%- js-response:gen
|
|
|
|
(as-octt:mimes:html "window.ship = '{+:(scow %p our.bowl)}';")
|
|
|
|
::
|
2020-05-21 00:43:15 +03:00
|
|
|
=/ [payload=simple-payload:http public=?] (get-file req-line)
|
2020-05-28 01:00:40 +03:00
|
|
|
?: public payload
|
2020-05-21 00:43:15 +03:00
|
|
|
(require-authorization-simple:app inbound-request payload)
|
2020-05-28 01:00:40 +03:00
|
|
|
::
|
|
|
|
++ get-file
|
|
|
|
|= req-line=request-line
|
|
|
|
^- [simple-payload:http ?]
|
|
|
|
=/ pax=path (snoc site.req-line (need ext.req-line))
|
2020-07-15 22:26:55 +03:00
|
|
|
=/ content=(unit [=content suffix=path public=?]) (get-content pax)
|
|
|
|
?~ content [not-found:gen %.n]
|
|
|
|
?- -.content.u.content
|
|
|
|
%clay
|
|
|
|
=/ scry-path
|
|
|
|
:* (scot %p our.bowl)
|
|
|
|
q.byk.bowl
|
|
|
|
(scot %da now.bowl)
|
|
|
|
(lowercase (weld path.content.u.content suffix.u.content))
|
|
|
|
==
|
|
|
|
?. .^(? %cu scry-path) [not-found:gen %.n]
|
|
|
|
=/ file (as-octs:mimes:html .^(@ %cx scry-path))
|
|
|
|
:_ public.u.content
|
|
|
|
?+ ext.req-line not-found:gen
|
|
|
|
[~ %html] (html-response:gen file)
|
|
|
|
[~ %js] (js-response:gen file)
|
|
|
|
[~ %css] (css-response:gen file)
|
|
|
|
[~ %png] (png-response:gen file)
|
2020-05-28 01:00:40 +03:00
|
|
|
==
|
2020-07-15 22:26:55 +03:00
|
|
|
::
|
|
|
|
%glob
|
|
|
|
=/ data=(unit mime)
|
|
|
|
(~(get by glob.content.u.content) suffix.u.content)
|
|
|
|
?~ data
|
|
|
|
[not-found:gen %.n]
|
|
|
|
:_ public.u.content
|
|
|
|
=/ mime-type=@t (rsh 3 1 (crip <p.u.data>))
|
|
|
|
:: Should maybe inspect to see how long cache should hold
|
|
|
|
::
|
|
|
|
[[200 ['content-type' mime-type] max-1-da:gen ~] `q.u.data]
|
2020-04-30 03:41:31 +03:00
|
|
|
==
|
2020-05-28 01:00:40 +03:00
|
|
|
::
|
2020-06-20 00:52:18 +03:00
|
|
|
++ lowercase
|
|
|
|
|= upper=(list @t)
|
|
|
|
%+ turn upper
|
|
|
|
|= word=@t
|
|
|
|
%- crip
|
|
|
|
%+ turn (rip 3 word)
|
|
|
|
|= char=@t
|
|
|
|
?. &((gte char 'A') (lte char 'Z'))
|
|
|
|
char
|
|
|
|
(add char ^~((sub 'a' 'A')))
|
|
|
|
::
|
2020-07-15 22:26:55 +03:00
|
|
|
++ get-content
|
2020-05-28 01:00:40 +03:00
|
|
|
|= pax=path
|
2020-07-15 22:26:55 +03:00
|
|
|
^- (unit [content path ?])
|
|
|
|
=/ first-try (match-content-path pax (~(del by serving) /))
|
2020-05-28 01:00:40 +03:00
|
|
|
?^ first-try first-try
|
|
|
|
=/ root (~(get by serving) /)
|
|
|
|
?~ root ~
|
2020-07-15 22:26:55 +03:00
|
|
|
(match-content-path pax (~(gas by *^serving) [[/ u.root] ~]))
|
2020-05-28 01:00:40 +03:00
|
|
|
::
|
2020-07-15 22:26:55 +03:00
|
|
|
++ match-content-path
|
2020-05-28 01:00:40 +03:00
|
|
|
|= [pax=path =^serving]
|
2020-07-15 22:26:55 +03:00
|
|
|
^- (unit [content path ?])
|
2020-05-28 01:00:40 +03:00
|
|
|
%- ~(rep by serving)
|
2020-07-15 22:26:55 +03:00
|
|
|
|= [[url-base=path =content public=?] out=(unit [content path ?])]
|
2020-05-28 01:00:40 +03:00
|
|
|
?^ out out
|
|
|
|
=/ suf (get-suffix url-base pax)
|
|
|
|
?~ suf ~
|
2020-07-15 22:26:55 +03:00
|
|
|
`[content u.suf public]
|
2020-05-28 01:00:40 +03:00
|
|
|
::
|
|
|
|
++ get-suffix
|
|
|
|
|= [a=path b=path]
|
|
|
|
^- (unit path)
|
|
|
|
?: (gth (lent a) (lent b)) ~
|
|
|
|
|-
|
|
|
|
?~ a `b
|
|
|
|
?~ b ~
|
|
|
|
?. =(i.a i.b) ~
|
|
|
|
%= $
|
|
|
|
a t.a
|
|
|
|
b t.b
|
|
|
|
==
|
|
|
|
--
|
2020-04-30 03:41:31 +03:00
|
|
|
--
|
|
|
|
::
|
|
|
|
++ on-watch
|
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
2020-05-28 01:40:32 +03:00
|
|
|
|^
|
2020-05-28 01:56:20 +03:00
|
|
|
?> (team:title our.bowl src.bowl)
|
2020-04-30 03:41:31 +03:00
|
|
|
?+ path (on-watch:def path)
|
|
|
|
[%http-response *] [~ this]
|
2020-05-28 01:40:32 +03:00
|
|
|
[%all ~] [(give [%configuration configuration]) this]
|
2020-04-30 03:41:31 +03:00
|
|
|
==
|
2020-05-28 01:40:32 +03:00
|
|
|
::
|
|
|
|
++ give
|
2020-06-01 21:28:05 +03:00
|
|
|
|= =update:srv
|
2020-05-28 01:40:32 +03:00
|
|
|
^- (list card)
|
2020-05-28 21:36:31 +03:00
|
|
|
[%give %fact ~ [%file-server-update !>(update)]]~
|
2020-05-28 01:40:32 +03:00
|
|
|
--
|
2020-04-30 03:41:31 +03:00
|
|
|
::
|
|
|
|
++ on-arvo
|
|
|
|
|= [=wire sign=sign-arvo]
|
|
|
|
^- (quip card _this)
|
|
|
|
?+ +<.sign (on-arvo:def wire sign)
|
2020-05-28 01:00:40 +03:00
|
|
|
%bound
|
2020-05-28 01:40:32 +03:00
|
|
|
?: accepted.sign [~ this]
|
|
|
|
[~ this(serving (~(del by serving) path.binding.sign))]
|
2020-04-30 03:41:31 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-peek on-peek:def
|
|
|
|
++ on-agent on-agent:def
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|