urbit/pkg/arvo/lib/hood/write.hoon

125 lines
3.0 KiB
Plaintext

:: File writer module
::
:::: /hoon/write/hood/lib
::
/? 310
=, format
=* as-octs as-octs:mimes:html
=, space:userlib
|%
+$ part {$write $0 pith} :: no state
+$ pith ~
--
::
::::
::
|%
++ data $%({$json json} {$mime mime})
++ card $% {$build wire ? schematic:ford}
{$info wire toro:clay}
==
--
::
::::
::
|= {bowl:gall part}
=* par +<+
|_ moz/(list {bone card})
++ abet [(flop moz) `part`par]
++ emit |=(a/card %_(+> moz :_(moz [ost a])))
++ beak-now byk(r [%da now])
++ poke-wipe
|= sup/path ^+ abet :: XX determine extension, beak
=+ ext=%md
?~ (file (en-beam beak-now [ext sup]))
~|(not-found+[ext `path`(flop sup)] !!)
=- abet:(emit %info write+~ -)
(fray (en-beam beak-now [ext sup]))
::
++ poke-tree
|= {sup/path mim/mime} ^+ abet :: XX determine extension, beak
(poke--data [`%md (flop sup)] %mime mim)
::
++ poke-paste
|= {typ/?($hoon $md $txt) txt/@t} ^+ abet
(poke--data [`typ /web/paste/(scot %da now)] %mime / (as-octs txt))
::
++ poke-comment
|= {sup/path him/ship txt/@t} ^+ abet
=+ pax=(welp (flop sup) /comments/(scot %da now))
=. txt
%+ rap 3 :~
'## `' (scot %p him) '`'
'\0a' txt
==
(poke--data [`%md pax] %mime / (as-octs txt))
::
++ poke-fora-post
|= {sup/path him/ship hed/@t txt/@t} ^+ abet
=+ pax=(welp (flop sup) /posts/(cat 3 (scot %da now) '~'))
=. txt
%- crip
"""
---
type: post
date: {<now>}
title: {(trip hed)}
author: {<him>}
navsort: bump
navuptwo: true
comments: reverse
---
{(trip txt)}
"""
(poke--data [`%md pax] %mime / (as-octs txt))
::
++ ames-secret
^- @t
=- (crip +:<.^(@p %j pax)>)
pax=/(scot %p our)/code/(scot %da now)/(scot %p our)
::
++ poke-sec-atom
|= {hot/host:eyre dat/@}
?> ?=(%& -.hot)
=. p.hot (scag 2 p.hot) :: ignore subdomain
=. dat (scot %uw (en:crub:crypto ames-secret dat))
(poke--data [`%atom [%sec p.hot]] %mime / (as-octs dat))
::
++ poke--data
|= {{ext/(unit @t) pax/path} dat/data} ^+ abet
?~ ext $(ext [~ -.dat])
=+ cay=?-(-.dat $json [-.dat !>(+.dat)], $mime [-.dat !>(+.dat)])
?: =(u.ext -.dat)
(made pax now [%complete %success %$ cay])
=< abet
%- emit :*
%build
write+pax
live=%.n :: XX defer %nice
^- schematic:ford :: SYNTAX ERROR AT START OF LINE?
=/ =beak beak-now
[%cast [p q]:beak u.ext [%$ cay]]
==
::
++ made
|= [pax=wire date=@da result=made-result:ford]
^+ abet
:: |= {pax/wire @ res/gage:ford} ^+ abet
:: ?. =(our src)
:: ~|(foreign-write/[our=our src=src] !!)
?: ?=(%incomplete -.result)
(mean tang.result)
::
=/ build-result build-result.result
::
?: ?=([%error *] build-result)
(mean message.build-result)
::
=/ =cage (result-to-cage:ford build-result)
::
=- abet:(emit %info write+~ -)
::
(foal :(welp (en-beam beak-now ~) pax /[-.cage]) cage)
--