2019-11-20 00:56:29 +03:00
|
|
|
:: link-server: accessing link-store via eyre
|
|
|
|
::
|
|
|
|
:: only accepts requests authenticated as the host ship.
|
|
|
|
::
|
|
|
|
:: GET requests:
|
|
|
|
:: /~link/local-pages/[some-path].json?p=0
|
|
|
|
:: our submissions on path, with optional pagination
|
|
|
|
::
|
|
|
|
:: POST requests:
|
|
|
|
:: /~link/add/[some-path]
|
|
|
|
:: send {title url} json, will save link at path
|
|
|
|
::
|
|
|
|
/+ *link, *server, default-agent, verb
|
|
|
|
::
|
|
|
|
|%
|
|
|
|
+$ state-0
|
|
|
|
$: %0
|
|
|
|
~
|
|
|
|
::NOTE this means we could get away with just producing cards everywhere,
|
|
|
|
:: never producing new state outside of the agent interface core.
|
|
|
|
:: we opt to keep ^-(quip card _state) in place for most logic arms
|
|
|
|
:: because it doesn't cost much, results in unsurprising code, and
|
|
|
|
:: makes adding any state in the future easier.
|
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ card card:agent:gall
|
|
|
|
--
|
|
|
|
::
|
|
|
|
=| state-0
|
|
|
|
=* state -
|
|
|
|
::
|
2019-12-11 23:16:20 +03:00
|
|
|
%+ verb |
|
2019-11-20 00:56:29 +03:00
|
|
|
^- agent:gall
|
|
|
|
=<
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
do ~(. +> bowl)
|
|
|
|
def ~(. (default-agent this %|) bowl)
|
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
2020-01-23 02:14:57 +03:00
|
|
|
:- [start-serving:do launch-tile:do ~]
|
|
|
|
this
|
2019-11-20 00:56:29 +03:00
|
|
|
::
|
|
|
|
++ on-save !>(state)
|
|
|
|
++ on-load
|
|
|
|
|= old=vase
|
|
|
|
^- (quip card _this)
|
|
|
|
[~ this(state !<(state-0 old))]
|
|
|
|
::
|
|
|
|
++ on-watch
|
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
?: ?=([%http-response *] path)
|
|
|
|
[~ this]
|
2020-01-23 02:14:57 +03:00
|
|
|
?: =(/primary path)
|
|
|
|
[~ this]
|
2019-11-20 00:56:29 +03:00
|
|
|
(on-watch:def path)
|
|
|
|
::
|
|
|
|
++ on-poke
|
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
|
|
|
?. ?=(%handle-http-request mark)
|
|
|
|
(on-poke:def mark vase)
|
|
|
|
:_ this
|
|
|
|
=+ !<([eyre-id=@ta =inbound-request:eyre] vase)
|
|
|
|
(handle-http-request:do eyre-id inbound-request)
|
|
|
|
::
|
|
|
|
++ on-arvo
|
|
|
|
|= [=wire =sign-arvo]
|
|
|
|
^- (quip card _this)
|
|
|
|
?. ?=(%bound +<.sign-arvo)
|
|
|
|
(on-arvo:def wire sign-arvo)
|
|
|
|
[~ this]
|
|
|
|
::
|
|
|
|
++ on-agent
|
|
|
|
|= [=wire =sign:agent:gall]
|
|
|
|
^- (quip card _this)
|
|
|
|
?. ?=(%poke-ack -.sign)
|
|
|
|
(on-agent:def wire sign)
|
|
|
|
?~ p.sign [~ this]
|
|
|
|
=/ =tank
|
|
|
|
leaf+"{(trip dap.bowl)} failed writing to %link-store"
|
|
|
|
%- (slog tank u.p.sign)
|
|
|
|
[~ this]
|
|
|
|
::
|
|
|
|
++ on-peek on-peek:def
|
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|
|
|
|
::
|
|
|
|
|_ =bowl:gall
|
|
|
|
::
|
|
|
|
++ start-serving
|
|
|
|
^- card
|
|
|
|
[%pass / %arvo %e %connect [~ /'~link'] dap.bowl]
|
|
|
|
::
|
2020-01-23 02:14:57 +03:00
|
|
|
++ launch-tile
|
|
|
|
^- card
|
|
|
|
(launch-poke [%link-server-hook /primary '/~link/js/tile.js'])
|
|
|
|
::
|
|
|
|
::
|
|
|
|
++ launch-poke
|
|
|
|
|= act=[@tas path @t]
|
|
|
|
^- card
|
|
|
|
[%pass / %agent [our.bowl %launch] %poke %launch-action !>(act)]
|
|
|
|
::
|
2019-11-20 00:56:29 +03:00
|
|
|
++ do-action
|
|
|
|
|= =action
|
|
|
|
^- card
|
|
|
|
[%pass / %agent [our.bowl %link-store] %poke %link-action !>(action)]
|
|
|
|
::
|
2020-01-15 02:32:32 +03:00
|
|
|
++ do-save
|
2019-11-20 00:56:29 +03:00
|
|
|
|= [=path title=@t =url]
|
|
|
|
^- card
|
2019-12-20 17:58:32 +03:00
|
|
|
(do-action %save path title url)
|
2019-11-20 00:56:29 +03:00
|
|
|
::
|
2020-01-15 02:32:32 +03:00
|
|
|
++ do-note
|
|
|
|
|= [=path =url udon=@t]
|
|
|
|
^- card
|
|
|
|
(do-action %note path url udon)
|
|
|
|
::
|
2019-11-20 00:56:29 +03:00
|
|
|
++ handle-http-request
|
|
|
|
|= [eyre-id=@ta =inbound-request:eyre]
|
|
|
|
^- (list card)
|
|
|
|
::NOTE we don't use +require-authorization because it's too restrictive
|
|
|
|
:: on the flow we want here.
|
|
|
|
::
|
|
|
|
?. ?& authenticated.inbound-request
|
|
|
|
=(src.bowl our.bowl)
|
|
|
|
==
|
2019-12-18 01:32:41 +03:00
|
|
|
(give-simple-payload:app eyre-id [[403 ~] ~])
|
2019-11-20 00:56:29 +03:00
|
|
|
:: request-line: parsed url + params
|
|
|
|
::
|
|
|
|
=/ =request-line
|
|
|
|
%- parse-request-line
|
|
|
|
url.request.inbound-request
|
|
|
|
=* req-head header-list.request.inbound-request
|
2019-12-18 03:48:08 +03:00
|
|
|
=; [cards=(list card) =simple-payload:http]
|
2019-11-20 00:56:29 +03:00
|
|
|
%+ weld cards
|
|
|
|
(give-simple-payload:app eyre-id simple-payload)
|
|
|
|
?+ method.request.inbound-request [~ not-found:gen]
|
|
|
|
%'OPTIONS'
|
2019-12-18 01:32:41 +03:00
|
|
|
[~ (include-cors-headers req-head [[200 ~] ~])]
|
2019-11-20 00:56:29 +03:00
|
|
|
::
|
|
|
|
%'GET'
|
|
|
|
[~ (handle-get req-head request-line)]
|
|
|
|
::
|
|
|
|
%'POST'
|
|
|
|
(handle-post req-head request-line body.request.inbound-request)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-post
|
|
|
|
|= [request-headers=header-list:http =request-line body=(unit octs)]
|
|
|
|
^- [(list card) simple-payload:http]
|
2019-12-18 03:48:08 +03:00
|
|
|
=; [success=? cards=(list card)]
|
2019-11-20 00:56:29 +03:00
|
|
|
:- cards
|
|
|
|
%+ include-cors-headers
|
|
|
|
request-headers
|
|
|
|
::TODO it would be more correct to wait for the %poke-ack instead of
|
|
|
|
:: sending this response right away... but link-store pokes can't
|
|
|
|
:: actually fail right now, so it's fine.
|
|
|
|
[[?:(success 200 400) ~] `*octs]
|
|
|
|
?~ body [| ~]
|
2020-01-15 02:32:32 +03:00
|
|
|
=/ jon=(unit json) (de-json:html q.u.body)
|
|
|
|
?~ jon [| ~]
|
2019-11-20 00:56:29 +03:00
|
|
|
?+ request-line [| ~]
|
2020-01-15 02:32:32 +03:00
|
|
|
[[~ [%'~link' %save ~]] ~]
|
2019-11-20 00:56:29 +03:00
|
|
|
^- [? (list card)]
|
2020-01-15 02:32:32 +03:00
|
|
|
=/ page=(unit [=path title=@t =url])
|
2019-11-20 00:56:29 +03:00
|
|
|
%. u.jon
|
2020-01-15 02:32:32 +03:00
|
|
|
=, dejs-soft:format
|
|
|
|
=+ (su ;~(pfix net (more net urs:ab)))
|
|
|
|
(ot path+- title+so url+so ~)
|
2019-11-20 00:56:29 +03:00
|
|
|
?~ page [| ~]
|
2020-01-15 02:32:32 +03:00
|
|
|
[& [(do-save u.page) ~]]
|
|
|
|
::
|
|
|
|
[[~ [%'~link' %note ~]] ~]
|
|
|
|
^- [? (list card)]
|
|
|
|
=/ note=(unit [=path =url udon=@t])
|
|
|
|
%. u.jon
|
|
|
|
=, dejs-soft:format
|
|
|
|
=+ (su ;~(pfix net (more net urs:ab)))
|
|
|
|
(ot path+- url+so udon+so ~)
|
|
|
|
?~ note [| ~]
|
|
|
|
[& [(do-note u.note) ~]]
|
2019-11-20 00:56:29 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-get
|
|
|
|
|= [request-headers=header-list:http =request-line]
|
2020-01-23 02:14:57 +03:00
|
|
|
:: if we request base path, return index.html
|
|
|
|
::
|
|
|
|
?: ?=([[~ [%'~link' ~]] *] request-line)
|
|
|
|
$(request-line request-line(ext `%html, site [%'~link' /index]))
|
2019-11-20 00:56:29 +03:00
|
|
|
%+ include-cors-headers
|
|
|
|
request-headers
|
|
|
|
^- simple-payload:http
|
|
|
|
:: args: map of params
|
|
|
|
:: p: pagination index
|
|
|
|
::
|
|
|
|
=/ args
|
|
|
|
%- ~(gas by *(map @t @t))
|
|
|
|
args.request-line
|
|
|
|
=/ p=(unit @ud)
|
|
|
|
%+ biff (~(get by args) 'p')
|
|
|
|
(curr rush dim:ag)
|
2019-12-18 22:35:50 +03:00
|
|
|
?+ request-line
|
|
|
|
:: for the default case, try to load file from clay
|
|
|
|
::
|
2020-01-10 23:08:13 +03:00
|
|
|
?~ ext.request-line
|
|
|
|
:: for extension-less requests, always just serve the index.html.
|
|
|
|
:: that way the js can load and figure out how to deal with that route.
|
|
|
|
::
|
|
|
|
$(request-line [[`%html ~[%'~link' 'index']] args.request-line])
|
2019-12-18 22:35:50 +03:00
|
|
|
=/ file=(unit octs)
|
|
|
|
?. ?=([%'~link' *] site.request-line) ~
|
|
|
|
(get-file-at /app/link [t.site u.ext]:request-line)
|
|
|
|
?~ file not-found:gen
|
|
|
|
?+ u.ext.request-line not-found:gen
|
|
|
|
%html (html-response:gen u.file)
|
|
|
|
%js (js-response:gen u.file)
|
|
|
|
%css (css-response:gen u.file)
|
2020-01-23 02:14:57 +03:00
|
|
|
%png (png-response:gen u.file)
|
2019-12-18 22:35:50 +03:00
|
|
|
==
|
2020-01-11 01:46:38 +03:00
|
|
|
:: submissions by recency as json, including comment counts
|
2019-12-18 18:19:03 +03:00
|
|
|
::
|
|
|
|
[[[~ %json] [%'~link' %submissions ^]] *]
|
|
|
|
%- json-response:gen
|
|
|
|
%- json-to-octs ::TODO include in +json-response:gen
|
2020-01-08 04:23:30 +03:00
|
|
|
%+ page-to-json
|
2019-12-18 18:19:03 +03:00
|
|
|
(get-submissions t.t.site.request-line p)
|
2020-01-11 01:46:38 +03:00
|
|
|
|= [=submission comments=@ud]
|
|
|
|
^- json
|
|
|
|
=+ s=(submission:en-json submission)
|
|
|
|
?> ?=([%o *] s)
|
|
|
|
o+(~(put by p.s) 'commentCount' (numb:enjs:format comments))
|
2019-11-20 00:56:29 +03:00
|
|
|
:: local links by recency as json
|
|
|
|
::
|
|
|
|
[[[~ %json] [%'~link' %local-pages ^]] *]
|
|
|
|
%- json-response:gen
|
|
|
|
%- json-to-octs ::TODO include in +json-response:gen
|
2020-01-08 04:23:30 +03:00
|
|
|
%+ page-to-json
|
2019-12-18 18:19:03 +03:00
|
|
|
(get-local-pages t.t.site.request-line p)
|
|
|
|
page:en-json
|
2019-12-21 02:51:49 +03:00
|
|
|
:: comments by recency as json
|
|
|
|
::
|
|
|
|
[[[~ %json] [%'~link' %discussions @ ^]] *]
|
|
|
|
%- json-response:gen
|
|
|
|
%- json-to-octs ::TODO include in +json-response:gen
|
2020-01-08 04:23:30 +03:00
|
|
|
%+ page-to-json
|
2019-12-21 02:51:49 +03:00
|
|
|
(get-discussions t.t.site.request-line p)
|
|
|
|
comment:en-json
|
2019-11-20 00:56:29 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ include-cors-headers
|
|
|
|
|= [request-headers=header-list:http =simple-payload:http]
|
|
|
|
^+ simple-payload
|
|
|
|
=* out-heads headers.response-header.simple-payload
|
|
|
|
=; =header-list:http
|
|
|
|
|-
|
|
|
|
?~ header-list simple-payload
|
|
|
|
=* new-head i.header-list
|
|
|
|
=. out-heads
|
|
|
|
(set-header:http key.new-head value.new-head out-heads)
|
|
|
|
$(header-list t.header-list)
|
|
|
|
=/ origin=@t
|
|
|
|
=/ headers=(map @t @t)
|
|
|
|
(~(gas by *(map @t @t)) request-headers)
|
|
|
|
(~(gut by headers) 'origin' '*')
|
|
|
|
:~ 'Access-Control-Allow-Origin'^origin
|
|
|
|
'Access-Control-Allow-Credentials'^'true'
|
|
|
|
'Access-Control-Request-Method'^'OPTIONS, GET, POST'
|
|
|
|
'Access-Control-Allow-Methods'^'OPTIONS, GET, POST'
|
|
|
|
'Access-Control-Allow-Headers'^'content-type'
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ page-size 25
|
2019-12-18 18:19:03 +03:00
|
|
|
++ get-paginated
|
|
|
|
|* [l=(list) p=(unit @ud)]
|
2020-01-11 01:25:17 +03:00
|
|
|
^- [total=@ud pages=@ud page=_l]
|
|
|
|
:+ (lent l)
|
|
|
|
+((div (lent l) page-size))
|
2019-12-18 18:19:03 +03:00
|
|
|
?~ p l
|
|
|
|
%+ scag page-size
|
|
|
|
%+ slag (mul u.p page-size)
|
|
|
|
l
|
|
|
|
::
|
2020-01-08 04:23:30 +03:00
|
|
|
++ page-to-json
|
|
|
|
=, enjs:format
|
2020-01-11 01:25:17 +03:00
|
|
|
|* $: [total-items=@ud total-pages=@ud page=(list)]
|
|
|
|
item-to-json=$-(* json)
|
|
|
|
==
|
2020-01-08 04:23:30 +03:00
|
|
|
^- json
|
|
|
|
%- pairs
|
2020-01-11 01:25:17 +03:00
|
|
|
:~ 'total-items'^(numb total-items)
|
|
|
|
'total-pages'^(numb total-pages)
|
2020-01-08 04:23:30 +03:00
|
|
|
'page'^a+(turn page item-to-json)
|
|
|
|
==
|
|
|
|
::
|
2019-12-18 18:19:03 +03:00
|
|
|
++ get-submissions
|
|
|
|
|= [=path p=(unit @ud)]
|
2020-01-11 01:46:38 +03:00
|
|
|
^- [@ud @ud (list [submission comments=@ud])]
|
2019-12-18 18:19:03 +03:00
|
|
|
=- (get-paginated - p)
|
2020-01-11 01:46:38 +03:00
|
|
|
%+ turn
|
2020-01-11 01:51:14 +03:00
|
|
|
%+ scry-for submissions
|
|
|
|
[%submissions path]
|
2020-01-11 01:46:38 +03:00
|
|
|
|= =submission
|
|
|
|
:- submission
|
|
|
|
%- lent
|
2020-01-11 01:51:14 +03:00
|
|
|
%+ scry-for comments
|
|
|
|
:- %discussions
|
|
|
|
%+ snoc path
|
|
|
|
%- crip
|
|
|
|
(en-base64:mimes:html url.submission)
|
2019-12-18 18:19:03 +03:00
|
|
|
::
|
|
|
|
++ get-local-pages
|
2019-11-20 00:56:29 +03:00
|
|
|
|= [=path p=(unit @ud)]
|
2020-01-11 01:25:17 +03:00
|
|
|
^- [@ud @ud pages]
|
2019-12-18 18:19:03 +03:00
|
|
|
=- (get-paginated - p)
|
2020-01-11 01:51:14 +03:00
|
|
|
%+ scry-for pages
|
|
|
|
[%local-pages path]
|
2019-12-18 22:35:50 +03:00
|
|
|
::
|
2019-12-21 02:51:49 +03:00
|
|
|
++ get-discussions
|
|
|
|
|= [=path p=(unit @ud)]
|
2020-01-11 01:25:17 +03:00
|
|
|
^- [@ud @ud comments]
|
2019-12-21 02:51:49 +03:00
|
|
|
=- (get-paginated - p)
|
2020-01-11 01:51:14 +03:00
|
|
|
%+ scry-for comments
|
|
|
|
[%discussions path]
|
2019-12-21 02:51:49 +03:00
|
|
|
::
|
2019-12-18 22:35:50 +03:00
|
|
|
++ get-file-at
|
|
|
|
|= [base=path file=path ext=@ta]
|
|
|
|
^- (unit octs)
|
|
|
|
:: only expose html, css and js files for now
|
|
|
|
::
|
2020-01-23 02:14:57 +03:00
|
|
|
?. ?=(?(%html %css %js %png) ext)
|
2019-12-18 22:35:50 +03:00
|
|
|
~
|
|
|
|
=/ =path
|
|
|
|
:* (scot %p our.bowl)
|
|
|
|
q.byk.bowl
|
|
|
|
(scot %da now.bowl)
|
|
|
|
(snoc (weld base file) ext)
|
|
|
|
==
|
|
|
|
?. .^(? %cu path)
|
|
|
|
~
|
|
|
|
%- some
|
|
|
|
%- as-octs:mimes:html
|
|
|
|
.^(@ %cx path)
|
2020-01-11 01:51:14 +03:00
|
|
|
::
|
|
|
|
++ scry-for
|
|
|
|
|* [=mold =path]
|
|
|
|
.^ mold
|
|
|
|
%gx
|
|
|
|
(scot %p our.bowl)
|
|
|
|
%link-store
|
|
|
|
(scot %da now.bowl)
|
|
|
|
(snoc `^path`path %noun)
|
|
|
|
==
|
2019-11-20 00:56:29 +03:00
|
|
|
--
|