shrub/pkg/arvo/app/lens.hoon

275 lines
6.9 KiB
Plaintext
Raw Normal View History

2019-11-19 06:28:59 +03:00
/- lens, *sole
/+ *server, default-agent
/= lens-mark /mar/lens/command :: TODO: ask clay to build a $tube
=, format
|%
:: +lens-out: json or named octet-stream
::
+$ lens-out
$% [%json =json]
[%mime =mime]
==
+$ state
$% $: %0
2019-11-19 06:28:59 +03:00
job=(unit [eyre-id=@ta com=command:lens])
==
==
::
++ export-app
|= [app=@tas our=@p now=@da]
2020-12-01 11:15:05 +03:00
.^(* %gx /(scot %p our)/[app]/(scot %da now)/export/noun)
++ export-all
|= [our=@p now=@da]
2020-12-01 11:15:05 +03:00
^- (list [@tas *])
%+ turn
^- (list @tas)
:~ %group-store
%metadata-store
%contact-store
%contact-hook
%invite-store
%graph-store
==
|= app=@tas
[app (export-app app our now)]
--
::
2019-11-19 06:28:59 +03:00
=| =state
2019-11-19 07:36:21 +03:00
|_ =bowl:gall
2019-11-19 06:28:59 +03:00
+* this .
def ~(. (default-agent this %|) bowl)
::
++ on-init on-init:def
++ on-save !>(state)
++ on-load
|= old=vase
`this(state !<(^state old))
::
++ on-poke
|= [=mark =vase]
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
::
?: &(?=(%noun mark) ?=(%cancel q.vase))
~& %lens-cancel
[~ this(job.state ~)]
::
2019-11-19 06:28:59 +03:00
?. ?=(%handle-http-request mark)
(on-poke:def mark vase)
=+ !<([eyre-id=@ta =inbound-request:eyre] vase)
?> ?=(~ job.state)
::
=/ request-line (parse-request-line url.request.inbound-request)
=/ site (flop site.request-line)
::
2020-12-04 09:50:45 +03:00
=/ body=@t q:(need body.request.inbound-request)
?: =('#import_' (end [3 8] body))
~& %import-all
=/ by-app ;;((list [@tas *]) (cue (rsh [3 8] body)))
:_ this
%+ weld (give-simple-payload:app eyre-id not-found:gen)
%+ turn by-app
|= [app=@tas data=*]
^- card:agent:gall
[%pass /import-all %agent [our.bowl app] %poke %import !>(data)]
=/ jon=json
2020-12-04 09:50:45 +03:00
(need (de-json:html body))
=/ com=command:lens
(json:grab:lens-mark jon)
::
?+ -.source.com
:_ this(job.state (some [eyre-id com]))
[%pass /sole %agent [our.bowl %dojo] %watch /sole/[eyre-id]]~
::
%export
2019-11-19 06:28:59 +03:00
:_ this(job.state (some [eyre-id com]))
[%pass /export %agent [our.bowl app.source.com] %watch /export]~
2019-07-16 23:52:42 +03:00
::
%import
2020-12-08 13:36:11 +03:00
?~ enc=(de:base64:mimes:html base64-jam.source.com)
2019-11-19 06:28:59 +03:00
!!
2019-07-16 23:52:42 +03:00
::
=/ c=* (cue q.u.enc)
::
2019-11-19 06:28:59 +03:00
:_ this(job.state (some [eyre-id com]))
[%pass /import %agent [our.bowl app.source.com] %poke %import !>(c)]~
::
%export-all
=/ output (crip "{<our.bowl>}-export/atom")
=/ jon
=/ =atom (jam (export-all our.bowl now.bowl))
=/ =octs [(met 3 atom) atom]
2020-12-08 13:36:11 +03:00
=/ enc (en:base64:mimes:html octs)
(pairs:enjs:format file+s+output data+s+enc ~)
:_ this
%+ give-simple-payload:app eyre-id
(json-response:gen jon)
::
%import-all
2020-12-02 05:22:03 +03:00
~& %import-all
2020-12-08 13:36:11 +03:00
=/ enc (de:base64:mimes:html base64-jam.source.com)
?~ enc !!
2020-12-02 05:22:03 +03:00
=/ by-app ;;((list [@tas *]) (cue q.u.enc))
:_ this
%+ weld (give-simple-payload:app eyre-id not-found:gen)
%+ turn by-app
2020-12-02 05:22:03 +03:00
|= [app=@tas data=*]
^- card:agent:gall
[%pass /import-all %agent [our.bowl app] %poke %import !>(data)]
==
2019-11-19 06:28:59 +03:00
::
++ on-watch
|= =path
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
2019-11-19 06:28:59 +03:00
?: ?=([%http-response *] path)
`this
(on-watch:def path)
::
++ on-leave on-leave:def
++ on-peek
|= =path
^- (unit (unit cage))
?+ path (on-peek:def path)
[%x %export-all ~]
``noun+!>((jam (export-all our.bowl now.bowl)))
==
2019-11-19 06:28:59 +03:00
++ on-agent
2019-11-19 07:36:21 +03:00
|= [=wire =sign:agent:gall]
^- (quip card:agent:gall _this)
2019-11-19 06:28:59 +03:00
|^
?+ wire (on-agent:def wire sign)
[%import ~]
?> ?=(%poke-ack -.sign)
?> ?=(^ job.state)
:_ this(job.state ~)
%+ give-simple-payload:app eyre-id.u.job.state
[[200 ~] `(as-octt:mimes:html "\"Imported data\"")]
::
2020-01-04 00:06:42 +03:00
[%export ~]
2019-11-19 06:28:59 +03:00
?+ -.sign (on-agent:def wire sign)
%watch-ack
?~ p.sign
`this
?> ?=(^ job.state)
:_ this(job.state ~)
(give-simple-payload:app eyre-id.u.job.state not-found:gen)
::
2019-11-19 06:28:59 +03:00
%fact
=^ cards this (take-export !<(* q.cage.sign))
2020-01-10 23:55:58 +03:00
:_ this(job.state ~)
:_ cards
2019-11-19 06:28:59 +03:00
?> ?=(^ job.state)
?> ?=(%export -.source.com.u.job.state)
[%pass /export %agent [our.bowl app.source.com.u.job.state] %leave ~]
==
::
[%sole ~]
?+ -.sign (on-agent:def wire sign)
%watch-ack
?> ?=(^ job.state)
?^ p.sign
:_ this(job.state ~)
(give-simple-payload:app eyre-id.u.job.state not-found:gen)
:_ this :_ ~
:* %pass /sole
%agent [our.bowl %dojo]
%poke %lens-command !>
[eyre-id.u.job.state com.u.job.state]
==
::
2019-11-19 06:28:59 +03:00
%fact
?> ?=(%sole-effect p.cage.sign)
=^ cards this (take-sole-effect !<(sole-effect q.cage.sign))
[[[%pass /sole %agent [our.bowl %dojo] %leave ~] cards] this]
==
==
::
++ take-export
|= data=*
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
2019-11-19 06:28:59 +03:00
?> ?=(^ job.state)
?> ?=(%export -.source.com.u.job.state)
=/ app-name=tape (trip app.source.com.u.job.state)
=/ output=@t (crip "/{app-name}/jam")
::
2019-11-19 06:28:59 +03:00
=/ jon=json
=/ =atom (jam data)
=/ =octs [(met 3 atom) atom]
2020-12-08 13:36:11 +03:00
=/ enc (en:base64:mimes:html octs)
2019-11-19 06:28:59 +03:00
(pairs:enjs:format file+s+output data+s+enc ~)
::
2020-01-10 23:55:58 +03:00
:_ this
2019-11-19 06:28:59 +03:00
%+ give-simple-payload:app eyre-id.u.job.state
(json-response:gen jon)
2019-11-19 06:28:59 +03:00
::
++ take-sole-effect
|= fec=sole-effect
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
2019-11-19 06:28:59 +03:00
=/ out
|- ^- (unit lens-out)
=* loop $
?+ -.fec
~
::
%tan
%- some
:- %json
%- wall:enjs:format
(turn (flop p.fec) |=(=tank ~(ram re tank)))
::
%txt
(some %json s+(crip p.fec))
::
2019-11-19 06:28:59 +03:00
%sag
%- some
[%mime p.fec (as-octs:mimes:html (jam q.fec))]
::
%sav
%- some
:- %json
%- pairs:enjs:format
:~ file+s+(crip <`path`p.fec>)
2020-12-08 13:36:11 +03:00
data+s+(en:base64:mimes:html (met 3 q.fec) q.fec)
2019-11-19 06:28:59 +03:00
==
::
%mor
=/ all `(list lens-out)`(murn p.fec |=(a=sole-effect loop(fec a)))
?~ all ~
~| [%multiple-effects all]
?> ?=(~ t.all)
(some i.all)
==
::
2019-11-19 06:28:59 +03:00
?~ out
[~ this]
::
?> ?=(^ job.state)
:_ this(job.state ~)
%+ give-simple-payload:app eyre-id.u.job.state
?- -.u.out
%json
(json-response:gen json.u.out)
2019-11-19 06:28:59 +03:00
::
%mime
=/ headers
:~ ['content-type' 'application/octet-stream']
?> ?=([@ @ ~] p.mime.u.out)
:- 'content-disposition'
^- @t
%^ cat 3
'attachment; filename='
(rap 3 '"' i.p.mime.u.out '.' i.t.p.mime.u.out '"' ~)
==
2019-11-19 06:28:59 +03:00
[[200 headers] (some q.mime.u.out)]
2019-07-16 23:52:42 +03:00
==
2019-11-19 06:28:59 +03:00
--
::
2019-11-19 06:28:59 +03:00
++ on-arvo
|= [=wire =sign-arvo]
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
2019-11-19 06:28:59 +03:00
?. ?=(%bound +<.sign-arvo)
(on-arvo:def wire sign-arvo)
[~ this]
::
2019-11-19 06:28:59 +03:00
++ on-fail on-fail:def
--