Merge branch 'os1-avatar' (#2776)

* origin/os1-avatar:
  contact-view: redirect upon url case of avatar
  contact: finish %octt implementation
  contacts: added "url" avatar support and finished "octet" avatar fetching support

Signed-off-by: Matilde Park <matilde@tlon.io>
This commit is contained in:
Matilde Park 2020-04-22 18:31:51 -04:00
commit 28c9141f94
5 changed files with 114 additions and 56 deletions

View File

@ -5,18 +5,33 @@
+$ card card:agent:gall +$ card card:agent:gall
+$ versioned-state +$ versioned-state
$% state-zero $% state-zero
state-one
==
::
+$ rolodex-0 (map path contacts-0)
+$ contacts-0 (map ship contact-0)
+$ avatar-0 [content-type=@t octs=[p=@ud q=@t]]
+$ contact-0
$: nickname=@t
email=@t
phone=@t
website=@t
notes=@t
color=@ux
avatar=(unit avatar-0)
== ==
:: ::
+$ state-zero +$ state-zero
$: %0 $: %0
=rolodex rolodex=rolodex-0
== ==
+$ diff +$ state-one
$% [%contact-update contact-update] $: %1
=rolodex
== ==
-- --
:: ::
=| state-zero =| state-one
=* state - =* state -
%- agent:dbug %- agent:dbug
^- agent:gall ^- agent:gall
@ -30,8 +45,26 @@
++ on-init on-init:def ++ on-init on-init:def
++ on-save !>(state) ++ on-save !>(state)
++ on-load ++ on-load
|= old=vase |= old-vase=vase
`this(state !<(state-zero old)) =/ old !<(versioned-state old-vase)
?: ?=(%1 -.old)
[~ this(state old)]
=/ new-rolodex=^rolodex
%- ~(run by rolodex.old)
|= cons=contacts-0
^- contacts
%- ~(run by cons)
|= con=contact-0
^- contact
:* nickname.con
email.con
phone.con
website.con
notes.con
color.con
~
==
[~ this(state [%1 new-rolodex])]
:: ::
++ on-poke ++ on-poke
|= [=mark =vase] |= [=mark =vase]

View File

@ -181,21 +181,19 @@
:: ::
:: avatar images :: avatar images
:: ::
:: [%'~groups' %avatar @ *] [%'~groups' %avatar @ *]
:: =/ pax=path `path`t.t.site.url =/ =path (flop t.t.site.url)
:: ?~ pax not-found:gen ?~ path not-found:gen
:: =/ pas `path`(flop pax) =/ contact (contact-scry `^path`(snoc (flop t.path) name))
:: ?~ pas not-found:gen ?~ contact not-found:gen
:: =/ pav `path`(flop t.pas) ?~ avatar.u.contact not-found:gen
:: ~& pav+pav ?- -.u.avatar.u.contact
:: ~& name+name %url [[307 ['location' url.u.avatar.u.contact]~] ~]
:: =/ contact (contact-scry `path`(weld pav [name]~)) %octt
:: ?~ contact not-found:gen =/ max-3-days ['cache-control' 'max-age=259200']
:: ?~ avatar.u.contact not-found:gen =/ content-type ['content-type' content-type.u.avatar.u.contact]
:: =* avatar u.avatar.u.contact [[200 [content-type max-3-days ~]] `octs.u.avatar.u.contact]
:: =/ decoded (de:base64 q.octs.avatar) ==
:: ?~ decoded not-found:gen
:: [[200 ['content-type' content-type.avatar]~] `u.decoded]
:: ::
[%'~groups' *] (html-response:gen index) [%'~groups' *] (html-response:gen index)
== ==

View File

@ -1,4 +1,5 @@
/- *contact-view, *contact-hook /- *contact-view, *contact-hook
/+ base64
|% |%
++ nu :: parse number as hex ++ nu :: parse number as hex
|= jon/json |= jon/json
@ -26,38 +27,34 @@
|= [pax=^path =contacts] |= [pax=^path =contacts]
^- [cord json] ^- [cord json]
:- (spat pax) :- (spat pax)
(contacts-to-json contacts) (contacts-to-json pax contacts)
:: ::
++ contacts-to-json ++ contacts-to-json
|= con=contacts |= [=path con=contacts]
^- json ^- json
=, enjs:format %- pairs:enjs:format
%- pairs
%+ turn ~(tap by con) %+ turn ~(tap by con)
|= [shp=^ship =contact] |= [=ship =contact]
^- [cord json] ^- [cord json]
:- (crip (slag 1 (scow %p shp))) [(crip (slag 1 (scow %p ship))) (contact-to-json path ship contact)]
(contact-to-json contact)
:: ::
++ contact-to-json ++ contact-to-json
|= con=contact |= [=path =ship con=contact]
^- json ^- json
=, enjs:format %- pairs:enjs:format
%- pairs
:~ [%nickname s+nickname.con] :~ [%nickname s+nickname.con]
[%email s+email.con] [%email s+email.con]
[%phone s+phone.con] [%phone s+phone.con]
[%website s+website.con] [%website s+website.con]
[%notes s+notes.con] [%notes s+notes.con]
[%color s+(scot %ux color.con)] [%color s+(scot %ux color.con)]
[%avatar s+'TODO'] [%avatar (avatar-to-json path ship avatar.con)]
== ==
:: ::
++ edit-to-json ++ edit-to-json
|= edit=edit-field |= [=path =ship edit=edit-field]
^- json ^- json
=, enjs:format %+ frond:enjs:format -.edit
%+ frond -.edit
?- -.edit ?- -.edit
%nickname s+nickname.edit %nickname s+nickname.edit
%email s+email.edit %email s+email.edit
@ -65,7 +62,25 @@
%website s+website.edit %website s+website.edit
%notes s+notes.edit %notes s+notes.edit
%color s+(scot %ux color.edit) %color s+(scot %ux color.edit)
%avatar s+'TODO' %avatar (avatar-to-json path ship avatar.edit)
==
::
++ avatar-to-json
|= [=path =ship avat=(unit avatar)]
^- json
?~ avat ~
?- -.u.avat
%octt
:- %s
%- crip
%- zing
:~ "/~groups/avatar"
(trip (spat path))
"/"
(trip (scot %p ship))
==
::
%url s+url.u.avat
== ==
:: ::
++ update-to-json ++ update-to-json
@ -84,7 +99,7 @@
%- pairs %- pairs
:~ [%path (path path.upd)] :~ [%path (path path.upd)]
[%ship (ship ship.upd)] [%ship (ship ship.upd)]
[%contact (contact-to-json contact.upd)] [%contact (contact-to-json path.upd ship.upd contact.upd)]
== ==
?: ?=(%remove -.upd) ?: ?=(%remove -.upd)
:- %remove :- %remove
@ -97,7 +112,7 @@
%- pairs %- pairs
:~ [%path (path path.upd)] :~ [%path (path path.upd)]
[%ship (ship ship.upd)] [%ship (ship ship.upd)]
[%edit-field (edit-to-json edit-field.upd)] [%edit-field (edit-to-json path.upd ship.upd edit-field.upd)]
== ==
[*@t *^json] [*@t *^json]
== ==
@ -190,10 +205,31 @@
== ==
:: ::
++ avat ++ avat
%- ot:dejs:format |= jon=json
:~ [%content-type so:dejs:format] ^- avatar
[%octs octet] |^
=/ =avatar (parse-json jon)
?- -.avatar
%url avatar
%octt
=. octs.avatar (need (de:base64 q.octs.avatar))
avatar
== ==
::
++ parse-json
%- of:dejs:format
:~ [%octt octt]
[%url url]
==
::
++ octt
%- ot:dejs:format
:~ [%content-type so:dejs:format]
[%octs octet]
==
::
++ url so:dejs:format
--
:: ::
++ cont ++ cont
%- ot:dejs:format %- ot:dejs:format

View File

@ -1,10 +1,11 @@
/- *identity /- *identity
|% |%
+$ rolodex (map path contacts) +$ rolodex (map path contacts)
:: +$ contacts (map ship contact)
+$ contacts (map ship contact) +$ avatar
:: $% [%octt content-type=@t octs=[p=@ud q=@t]]
+$ avatar [content-type=@t octs=[p=@ud q=@t]] [%url url=@t]
==
:: ::
+$ contact +$ contact
$: nickname=@t $: nickname=@t

View File

@ -379,15 +379,6 @@ export class ContactCard extends Component {
); );
} }
let removeImage = hasAvatar ? (
<div>
<button className="f9 black pointer db"
onClick={() => this.setField("removeAvatar")}>
Remove photo
</button>
</div>
) : "";
let avatar = (hasAvatar) let avatar = (hasAvatar)
? <img className="dib h-auto" width={128} src={props.contact.avatar} /> ? <img className="dib h-auto" width={128} src={props.contact.avatar} />
: <Sigil : <Sigil
@ -401,7 +392,6 @@ export class ContactCard extends Component {
<div className="w-100 mw6 tc"> <div className="w-100 mw6 tc">
{avatar} {avatar}
{sigilColor} {sigilColor}
{removeImage}
<div className="w-100 pt8 pb8 lh-copy tl"> <div className="w-100 pt8 pb8 lh-copy tl">
<p className="f9 gray2">Ship Name</p> <p className="f9 gray2">Ship Name</p>
<p className="f8 mono">~{props.ship}</p> <p className="f8 mono">~{props.ship}</p>