From e1b011224d31aade42dce5191bb0fe6847c99a34 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 26 Aug 2020 14:22:54 -0500 Subject: [PATCH] file-server: fix %file-server by adding SPA flag and threading is-file through request --- pkg/arvo/app/chat-view.hoon | 4 +- pkg/arvo/app/contact-view.hoon | 4 +- pkg/arvo/app/file-server.hoon | 75 +++++++++++++++++++++------------- pkg/arvo/app/launch.hoon | 2 +- pkg/arvo/app/link-view.hoon | 4 +- pkg/arvo/app/publish.hoon | 6 +-- pkg/arvo/app/soto.hoon | 4 +- pkg/arvo/sur/file-server.hoon | 2 +- 8 files changed, 60 insertions(+), 41 deletions(-) diff --git a/pkg/arvo/app/chat-view.hoon b/pkg/arvo/app/chat-view.hoon index b06250fc6..15b7bdf40 100644 --- a/pkg/arvo/app/chat-view.hoon +++ b/pkg/arvo/app/chat-view.hoon @@ -61,7 +61,7 @@ :_ this :~ :* %pass /srv %agent [our.bol %file-server] %poke %file-server-action - !>([%serve-dir /'~chat' /app/landscape %.n]) + !>([%serve-dir /'~chat' /app/landscape %.n %.y]) == [%pass / %arvo %e %connect [~ /'chat-view'] %chat-view] [%pass /updates %agent [our.bol %chat-store] %watch /updates] @@ -167,7 +167,7 @@ [%pass / %arvo %e %connect [~ /'chat-view'] %chat-view] :* %pass /srv %agent [our.bol %file-server] %poke %file-server-action - !>([%serve-dir /'~chat' /app/landscape %.n]) + !>([%serve-dir /'~chat' /app/landscape %.n %.y]) == == :: diff --git a/pkg/arvo/app/contact-view.hoon b/pkg/arvo/app/contact-view.hoon index 80bd55a45..417b75452 100644 --- a/pkg/arvo/app/contact-view.hoon +++ b/pkg/arvo/app/contact-view.hoon @@ -48,7 +48,7 @@ (contact-poke:cc [%add /~/default our.bowl *contact]) :* %pass /srv %agent [our.bol %file-server] %poke %file-server-action - !>([%serve-dir /'~groups' /app/landscape %.n]) + !>([%serve-dir /'~groups' /app/landscape %.n %.y]) == == :: @@ -63,7 +63,7 @@ [%pass / %arvo %e %connect [~ /'contact-view'] %contact-view] :* %pass /srv %agent [our.bol %file-server] %poke %file-server-action - !>([%serve-dir /'~groups' /app/landscape %.n]) + !>([%serve-dir /'~groups' /app/landscape %.n %.y]) == == :: diff --git a/pkg/arvo/app/file-server.hoon b/pkg/arvo/app/file-server.hoon index 091d5815a..7969a3729 100644 --- a/pkg/arvo/app/file-server.hoon +++ b/pkg/arvo/app/file-server.hoon @@ -2,25 +2,23 @@ /+ *server, default-agent, verb, dbug |% +$ card card:agent:gall -+$ serving (map url-base=path [=content public=?]) ++$ serving (map url-base=path [=content public=? single-page=?]) +$ content $% [%clay =path] [%glob =glob:glob] == -+$ state-base - $: =configuration:srv +:: ++$ state-3 + $: %3 + =configuration:srv =serving == -+$ state-2 - $: %2 - state-base - == -- :: %+ verb | %- agent:dbug :: -=| state-2 +=| state-3 =* state - ^- agent:gall |_ =bowl:gall @@ -36,7 +34,7 @@ %+ turn ^- (list path) [/ /'~landscape' ~] - |=(pax=path [pax [clay+/app/landscape %.n]]) + |=(pax=path [pax [clay+/app/landscape %.n %.y]]) == :~ (connect /) (connect /'~landscape') @@ -68,24 +66,35 @@ - %2 serving (~(del by serving.old-state) /'~landscape'/js/index) == - ?> ?=(%2 -.old-state) + =? old-state ?=(%2 -.old-state) + %= old-state + - %3 + serving + %- ~(run by serving.old-state) + |= [=content public=?] + ^- [^content ? ?] + [content public %.y] + == + ?> ?=(%3 -.old-state) [~ this(state old-state)] :: + +$ serving-0 (map url-base=path [=clay=path public=?]) + +$ serving-1 (map url-base=path [=content public=?]) +$ versioned-state $% state-0 - state-1 - state-2 + [%1 state-1] + [%2 state-1] + state-3 == :: - +$ serving-0 (map url-base=path [=clay=path public=?]) +$ state-0 $: %0 =configuration:srv =serving-0 == +$ state-1 - $: %1 - state-base + $: =configuration:srv + serving=serving-1 == -- :: @@ -113,14 +122,17 @@ ?: (~(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 clay+clay-base.act public.act)) + %_ this + serving + (~(put by serving) url-base clay+clay-base.act public.act spa.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)) + this(serving (~(put by serving) url-base glob+glob.act public.act %.y)) :: %unserve-dir :- [%pass url-base.act %arvo %e %disconnect [~ url-base.act]]~ @@ -129,9 +141,9 @@ %toggle-permission ?. (~(has by serving) url-base.act) ~|("url is not bound" !!) - =/ [=content public=?] (~(got by serving) url-base.act) + =/ [=content public=? spa=?] (~(got by serving) url-base.act) :- ~ - this(serving (~(put by serving) url-base.act [content !public])) + this(serving (~(put by serving) url-base.act [content !public spa])) :: %set-landscape-homepage-prefix =. landscape-homepage-prefix.configuration prefix.act @@ -158,6 +170,7 @@ |= =cord ^- (unit ^cord) ?:(=(cord '') ~ `cord) + =/ is-file ?=(^ ext.req-line) =? req-line ?=(~ ext.req-line) [[[~ %html] (snoc site.req-line 'index')] args.req-line] ?~ site.req-line @@ -174,17 +187,18 @@ %- js-response:gen (as-octt:mimes:html "window.ship = '{+:(scow %p our.bowl)}';") :: - =/ [payload=simple-payload:http public=?] (get-file req-line) + =/ [payload=simple-payload:http public=?] (get-file req-line is-file) ?: public payload (require-authorization-simple:app inbound-request payload) :: ++ get-file - |= req-line=request-line + |= [req-line=request-line is-file=?] ^- [simple-payload:http ?] =/ pax=path ?~ ext.req-line site.req-line (snoc site.req-line u.ext.req-line) - =/ content=(unit [=content suffix=path public=?]) (get-content pax) + =/ content=(unit [=content suffix=path public=?]) + (get-content pax is-file) ?~ content [not-found:gen %.n] ?- -.content.u.content %clay @@ -234,23 +248,28 @@ (add char ^~((sub 'a' 'A'))) :: ++ get-content - |= pax=path + |= [pax=path is-file=?] ^- (unit [content path ?]) - =/ first-try (match-content-path pax (~(del by serving) /)) + =/ first-try (match-content-path pax (~(del by serving) /) is-file) ?^ first-try first-try =/ root (~(get by serving) /) ?~ root ~ - (match-content-path pax (~(gas by *^serving) [[/ u.root] ~])) + (match-content-path pax (~(gas by *^serving) [[/ u.root] ~]) is-file) :: ++ match-content-path - |= [pax=path =^serving] + |= [pax=path =^serving is-file=?] ^- (unit [content path ?]) %- ~(rep by serving) - |= [[url-base=path =content public=?] out=(unit [content path ?])] + |= $: [url-base=path =content public=? spa=?] + out=(unit [content path ?]) + == ?^ out out =/ suf (get-suffix url-base pax) ?~ suf ~ - `[content u.suf public] + =- `[content - public] + ?: ?&(spa !is-file) + /index/html + u.suf :: ++ get-suffix |= [a=path b=path] diff --git a/pkg/arvo/app/launch.hoon b/pkg/arvo/app/launch.hoon index 5ceb6296c..17e6fc5d1 100644 --- a/pkg/arvo/app/launch.hoon +++ b/pkg/arvo/app/launch.hoon @@ -77,7 +77,7 @@ :~ [%pass / %arvo %e %disconnect [~ /]] :* %pass /srv %agent [our.bowl %file-server] %poke %file-server-action - !>([%serve-dir / /app/landscape %.n]) + !>([%serve-dir / /app/landscape %.n %.y]) == == %+ turn ~(tap by wex.bowl) diff --git a/pkg/arvo/app/link-view.hoon b/pkg/arvo/app/link-view.hoon index 4e5fe6de7..eaeefae07 100644 --- a/pkg/arvo/app/link-view.hoon +++ b/pkg/arvo/app/link-view.hoon @@ -65,7 +65,7 @@ [%pass - %agent [our.bowl %invite-store] %watch -] :* %pass /srv %agent [our.bowl %file-server] %poke %file-server-action - !>([%serve-dir /'~link' /app/landscape %.n]) + !>([%serve-dir /'~link' /app/landscape %.n %.y]) == == :: @@ -81,7 +81,7 @@ :- [%pass /connect %arvo %e %disconnect [~ /'~link']] :~ :* %pass /srv %agent [our.bowl %file-server] %poke %file-server-action - !>([%serve-dir /'~link' /app/landscape %.n]) + !>([%serve-dir /'~link' /app/landscape %.n %.y]) == == == :: diff --git a/pkg/arvo/app/publish.hoon b/pkg/arvo/app/publish.hoon index 2ed386584..00b5075bf 100644 --- a/pkg/arvo/app/publish.hoon +++ b/pkg/arvo/app/publish.hoon @@ -96,7 +96,7 @@ == :* %pass /srv %agent [our.bol %file-server] %poke %file-server-action - !>([%serve-dir /'~publish' /app/landscape %.n]) + !>([%serve-dir /'~publish' /app/landscape %.n %.y]) == [%pass /groups %agent [our.bol %group-store] %watch /groups] == @@ -126,7 +126,7 @@ [%pass /view-bind %arvo %e %connect [~ /'publish-view'] %publish] :* %pass /srv %agent [our.bol %file-server] %poke %file-server-action - !>([%serve-dir /'~publish' /app/landscape %.n]) + !>([%serve-dir /'~publish' /app/landscape %.n %.y]) == == =+ ^- [kick-cards=(list card) old-subs=(jug @tas @p)] kick-subs @@ -197,7 +197,7 @@ [%pass /view-bind %arvo %e %connect [~ /'publish-view'] %publish] :* %pass /srving %agent [our.bol %file-server] %poke %file-server-action - !>([%serve-dir /'~publish' /app/landscape %.n]) + !>([%serve-dir /'~publish' /app/landscape %.n %.y]) == == == :: diff --git a/pkg/arvo/app/soto.hoon b/pkg/arvo/app/soto.hoon index 606cdea28..98645dafd 100644 --- a/pkg/arvo/app/soto.hoon +++ b/pkg/arvo/app/soto.hoon @@ -29,7 +29,7 @@ :_ ~ :* %pass /srv %agent [our.bol %file-server] %poke %file-server-action - !>([%serve-dir /'~dojo' /app/landscape %.n]) + !>([%serve-dir /'~dojo' /app/landscape %.n %.y]) == ++ on-save !>(state) :: @@ -43,7 +43,7 @@ :~ [%pass /bind/soto %arvo %e %disconnect [~ /'~dojo']] :* %pass /srv %agent [our.bol %file-server] %poke %file-server-action - !>([%serve-dir /'~dojo' /app/landscape %.n]) + !>([%serve-dir /'~dojo' /app/landscape %.n %.y]) == == :: diff --git a/pkg/arvo/sur/file-server.hoon b/pkg/arvo/sur/file-server.hoon index b29379c91..b2565d12e 100644 --- a/pkg/arvo/sur/file-server.hoon +++ b/pkg/arvo/sur/file-server.hoon @@ -1,7 +1,7 @@ /- glob |% +$ action - $% [%serve-dir url-base=path clay-base=path public=?] + $% [%serve-dir url-base=path clay-base=path public=? spa=?] [%serve-glob url-base=path =glob:glob public=?] [%unserve-dir url-base=path] [%toggle-permission url-base=path]