Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipfs for image assets #173

Merged
merged 5 commits into from
Sep 28, 2016
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/image.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ emit = ($item, item) ->
$item.append "<img class=thumbnail src=\"#{item.url}\"> <p>#{resolve.resolveLinks(item.text)}</p>"

bind = ($item, item) ->
$item.dblclick -> editor.textEditor $item, item
$item.find('img').dblclick -> dialog.open item.text, this
$item.dblclick ->
editor.textEditor $item, item
url = item.url
if item.ipfs?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is the best way of doing this - surely if the item is stored on ipfs the item.url will be a gateway address! Worth looking at the browser IPFS gateway plugins for inspiration, the Firefox on looks for ULRs that match the pattern https?://<public_gateway>/(ipfs|ipns)/$RESOURCE where by default <public_gateway> is ipfs.io gateway.ipfs.io ipfs.pics.

Copy link
Member Author

@WardCunningham WardCunningham Sep 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The item url will be for the postcard image, a dataurl. Folks who want nothing to do with ipfs will get the same old postcards they use to get. Those who like ipfs will run local nodes and get fabulous service unavailable from public gateways.

$.get "http://localhost:8080/ipfs/#{item.ipfs}", ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely to be slow. The Firefox plugin checks for the local gateway by polling it using the IPFS API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initiate the get when the page is rendered. I don't expect a result until the user double-clicks to enlarge the image. If ipfs is slow one can try later, then it will be fast because images are stored in the local node.

url = "http://localhost:8080/ipfs/#{item.ipfs}"
$item.find('img').dblclick (event) ->
event.stopPropagation()
Copy link
Member Author

@WardCunningham WardCunningham Sep 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This long-standing omission caused both dblclick handers to run.

dialog.open item.text, "<img style=\"width:100%\" src=\"#{url}\">"

module.exports = {emit, bind}