Skip to content

Commit

Permalink
Merge pull request #57 from moul/fix-ipfs-reader-race
Browse files Browse the repository at this point in the history
  • Loading branch information
moul authored Nov 9, 2020
2 parents 6966561 + c0dde00 commit ac800ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pkg/sgtm/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ type ipfsReadSeeker struct {
var _ ReadSeekerCloser = (*ipfsReadSeeker)(nil)

func (irs *ipfsReadSeeker) Seek(offset int64, whence int) (int64, error) {
err := irs.Close()
irs.mu.Lock()
defer irs.mu.Unlock()

err := irs.lockedClose()
if err != nil {
return irs.offset, err
}

irs.mu.Lock()
defer irs.mu.Unlock()

switch whence {
case io.SeekStart:
irs.offset = offset
Expand Down Expand Up @@ -122,6 +122,10 @@ func (irs *ipfsReadSeeker) Close() error {
irs.mu.Lock()
defer irs.mu.Unlock()

return irs.lockedClose()
}

func (irs *ipfsReadSeeker) lockedClose() error {
if irs.pipe != nil {
err := irs.pipe.Close()
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion pkg/sgtm/page_post.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ <h1>{{.Post.Post.Title}}</h1>
<iframe id="soundcloud-player" width=100% height=166 scrolling=no frameborder=no allow=autoplay
src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/{{.Post.Post.SoundCloudID}}{{with .Post.Post.SoundCloudSecretToken}}%3Fsecret_token%3D{{.}}{{end}}&color=%23ff5500&auto_play=false&hide_related=true&show_comments=false&show_user=true&show_reposts=false&show_teaser=false"></iframe>
{{else}}{{if .Post.Post.IsIPFS}}
<audio controls src="/post/{{ .Post.Post.ID }}/download">
<audio controls>
<source src="/post/{{.Post.Post.ID}}/download" />
<source src="https://gateway.ipfs.io/ipfs/{{.Post.Post.IPFSCID}}" />
<source src="https://ipfs.io/ipfs/{{.Post.Post.IPFSCID}}" />
<source src="https://cloudflare-ipfs.com/ipfs/{{.Post.Post.IPFSCID}}" />
<source src="https://jorropo.ovh/ipfs/{{.Post.Post.IPFSCID}}" />
Your browser does not support the
<code>audio</code> element.
</audio>
Expand Down

0 comments on commit ac800ba

Please sign in to comment.