(.module: [lux #* [abstract [monad (#+ do)]] [control ["." try] [concurrency ["." promise (#+ Promise)]]] [data ["." text ["%" format (#+ format)]]] [world [program (#+ Program)] ["." file] [net ["." uri (#+ URI)]]]] ["." // ["/#" // #_ ["#." local] ["#." metadata]]]) (def: (root /) (-> Text file.Path) (text.replace_all uri.separator / ///local.repository)) (def: (path /) (-> Text (-> URI file.Path)) (text.replace_all uri.separator /)) (def: (absolute_path /) (-> Text (-> URI file.Path)) (|>> ///metadata.local_uri (..path /) (format (..root /) /))) (implementation: #export (repository program fs) (-> (Program Promise) (file.System Promise) (//.Repository Promise)) (def: description (..root (\ fs separator))) (def: download (|>> (..absolute_path (\ fs separator)) (\ fs read))) (def: (upload uri content) (do {! promise.monad} [#let [absolute_path (..absolute_path (\ fs separator) uri)] ? (\ fs file? absolute_path) _ (if ? (wrap []) (case (file.parent fs absolute_path) (#.Some parent) (file.make_directories promise.monad fs parent) _ (let [! (try.with promise.monad)] (\ ! wrap []))))] (\ fs write content absolute_path))))