Skip to content

Commit

Permalink
Merge pull request #76 from sgtm-club/dev/moul/edit-title
Browse files Browse the repository at this point in the history
feat: edit title
  • Loading branch information
moul committed Nov 15, 2020
2 parents 528095c + 7f1ef67 commit 2558318
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 228 deletions.
1 change: 1 addition & 0 deletions api/sgtm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ message Post {
double bpm = 43 [(go.field) = {name: 'BPM'}];
string key_signature = 44;
string isrc = 45 [(go.field) = {name: 'ISRC'}];
string provider_title = 53;
string provider_description = 46;
string provider_download_url = 47 [(go.field) = {name: 'DownloadURL'}];
int64 provider_created_at = 48;
Expand Down
2 changes: 1 addition & 1 deletion gen.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/sgtm/page_base.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h4 class="text-white">Recent activities</h4>
<div>
<a href="{{.CanonicalURL}}" class="text-light">
{{ if eq .Kind 1}}<span class="fa fa-music"></span>{{end}}
{{.Title}}
{{.SafeTitle}}
</a>
<small class="text-muted">{{.CreatedAt | fromUnixNano | prettyAgo}}</small>
</div>
Expand Down
2 changes: 1 addition & 1 deletion pkg/sgtm/page_home.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h6 class="card-header">
<div class="media">
<a href="{{.CanonicalURL}}"><img src="{{ .ArtworkURL }}" width="100" class="pr-1 mr-3" alt="Artwork" /></a>
<div class="media-body">
<a href="{{.CanonicalURL}}"><h5 class="mt-0 d-inline-block">{{.Title}}</h5></a>
<a href="{{.CanonicalURL}}"><h5 class="mt-0 d-inline-block">{{.SafeTitle}}</h5></a>
<div>
{{with .TagList}}<div>📁 Tags: {{range .}}<span class="badge badge-secondary">{{.}}</span> {{end}}</div>{{end}}
{{if .Duration}}<div>⏱ Duration: <span data-toggle="tooltip" data-placement="right" title="{{.GoDuration}}">{{.GoDuration | prettyDuration}}</span></div>{{end}}
Expand Down
20 changes: 10 additions & 10 deletions pkg/sgtm/page_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (svc *Service) newPage(box *packr.Box) func(w http.ResponseWriter, r *http.
First(&alreadyExists).
Error
if err == nil && alreadyExists.ID != 0 {
data.New.URLInvalidMsg = fmt.Sprintf(`This track already exists: <a href="/post/%d">%s</a>.`, alreadyExists.ID, alreadyExists.Title)
data.New.URLInvalidMsg = fmt.Sprintf(`This track already exists: <a href="/post/%d">%s</a>.`, alreadyExists.ID, alreadyExists.SafeTitle())
return nil
}
}
Expand All @@ -93,7 +93,7 @@ func (svc *Service) newPage(box *packr.Box) func(w http.ResponseWriter, r *http.
Visibility: sgtmpb.Visibility_Public,
AuthorID: data.User.ID,
Slug: "",
Title: filename,
ProviderTitle: filename,
SortDate: time.Now().UnixNano(),
URL: "https://ipfs.io/ipfs/" + cid,
Provider: sgtmpb.Provider_IPFS,
Expand All @@ -107,12 +107,12 @@ func (svc *Service) newPage(box *packr.Box) func(w http.ResponseWriter, r *http.

// FIXME: check if valid SoundCloud link
post := sgtmpb.Post{
Kind: sgtmpb.Post_TrackKind,
Visibility: sgtmpb.Visibility_Public,
AuthorID: data.User.ID,
Slug: "",
Title: "",
SortDate: time.Now().UnixNano(),
Kind: sgtmpb.Post_TrackKind,
Visibility: sgtmpb.Visibility_Public,
AuthorID: data.User.ID,
Slug: "",
ProviderTitle: "",
SortDate: time.Now().UnixNano(),
}

u, err := url.Parse(fileURL)
Expand Down Expand Up @@ -150,7 +150,7 @@ func (svc *Service) newPage(box *packr.Box) func(w http.ResponseWriter, r *http.
First(&alreadyExists).
Error
if err == nil && alreadyExists.ID != 0 {
data.New.URLInvalidMsg = fmt.Sprintf(`This track already exists: <a href="%s">%s</a>.`, alreadyExists.CanonicalURL(), alreadyExists.Title)
data.New.URLInvalidMsg = fmt.Sprintf(`This track already exists: <a href="%s">%s</a>.`, alreadyExists.CanonicalURL(), alreadyExists.SafeTitle())
return nil
}
}
Expand All @@ -167,7 +167,7 @@ func (svc *Service) newPage(box *packr.Box) func(w http.ResponseWriter, r *http.
}

post.ProviderMetadata = godev.JSON(track)
post.Title = track.Title
post.ProviderTitle = track.Title
createdAt, err := time.Parse("2006/01/02 15:04:05 +0000", track.CreatedAt)
if err == nil {
post.ProviderCreatedAt = createdAt.UnixNano()
Expand Down
6 changes: 3 additions & 3 deletions pkg/sgtm/page_open.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ <h4 id="activities">Activities</h4>
{{with eq $kind "ViewHomeKind"}}🏠 View home page{{end}}
{{with eq $kind "LoginKind"}}👌 Login{{end}}
{{with eq $kind "RegisterKind"}}👋 Register{{end}}
{{with eq $kind "TrackKind"}}🎶 Post <a href="{{$post.CanonicalURL}}">{{$post.Title}}</a>{{end}}
{{with eq $kind "CommentKind"}}{{with $post.TargetPost}}✏️ Comment <a href="{{$post.TargetPost.CanonicalURL}}">{{$post.TargetPost.Title}}</a>{{end}}{{end}}
{{with eq $kind "TrackKind"}}🎶 Post <a href="{{$post.CanonicalURL}}">{{$post.SafeTitle}}</a>{{end}}
{{with eq $kind "CommentKind"}}{{with $post.TargetPost}}✏️ Comment <a href="{{$post.TargetPost.CanonicalURL}}">{{$post.TargetPost.SafeTitle}}</a>{{end}}{{end}}
{{with eq $kind "ViewProfileKind"}}{{with $post.TargetUser}}👤 View <a href="{{$post.TargetUser.CanonicalURL}}">{{$post.TargetUser.DisplayName}}</a> profile{{end}}{{end}}
{{with eq $kind "ViewPostKind"}}
{{with $post.TargetPost}}
<!-- FIXME: switch case on .TargetPost.Kind -->
🎶 View <a href="{{$post.TargetPost.CanonicalURL}}">{{$post.TargetPost.Title}}</a>
🎶 View <a href="{{$post.TargetPost.CanonicalURL}}">{{$post.TargetPost.SafeTitle}}</a>
{{end}}
{{end}}
<span class="text-muted">{{$post.CreatedAt | fromUnixNano | prettyAgo}}</span>
Expand Down
16 changes: 7 additions & 9 deletions pkg/sgtm/page_post-edit.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
<div class="container">
<div class="row">
<div class="col-md-8">
<h1><a href="{{.PostEdit.Post.CanonicalURL}}">{{.PostEdit.Post.Title}}</a> &gt; Edit</h1>
<h1><a href="{{.PostEdit.Post.CanonicalURL}}">{{.PostEdit.Post.SafeTitle}}</a> &gt; Edit</h1>
<form method="post">
{{if .PostEdit.Post.IsIPFS}}
<div class="form-group row">
<label for="title" class="col-sm-2 col-form-label">Title</label>
<div class="col-sm-10">
<input type="text" name="title" class="form-control" value="{{.PostEdit.Post.Title}}">
</div>
<div class="form-group row">
<label for="title" class="col-sm-2 col-form-label">Title</label>
<div class="col-sm-10">
<input type="text" name="title" class="form-control" value="{{.PostEdit.Post.Title}}">
</div>
{{end}}
</div>
<div class="form-group row">
<label for="staticDescription" class="col-sm-2 col-form-label">Description</label>
<div class="col-sm-10">
Expand All @@ -44,7 +42,7 @@ <h1><a href="{{.PostEdit.Post.CanonicalURL}}">{{.PostEdit.Post.Title}}</a> &gt;
<div class="p-2">
<div class="form-group">
<label for="soundcloudTitle">Title</label>
<input type="text" readonly class="form-control-plaintext border" id="soundcloudTitle" value="{{.PostEdit.Post.Title}}">
<input type="text" readonly class="form-control-plaintext border" id="soundcloudTitle" value="{{.PostEdit.Post.ProviderTitle}}">
</div>
<div class="form-group">
<label for="soundcloudArtwork">Artwork</label>
Expand Down
3 changes: 2 additions & 1 deletion pkg/sgtm/page_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (svc *Service) postMaintenancePage(box *packr.Box) func(w http.ResponseWrit
err := svc.rwdb().Transaction(func(tx *gorm.DB) error {
// FIXME: avoid delete/recreate associations if they didn't changed

body := post.Title + "\n\n" + post.SafeDescription()
body := post.SafeTitle() + "\n\n" + post.SafeDescription()

if err := tx.Model(&post).Association("RelationshipsAsSource").Clear(); err != nil {
return err
Expand Down Expand Up @@ -332,6 +332,7 @@ func (svc *Service) postEditPage(box *packr.Box) func(w http.ResponseWriter, r *
}
// FIXME: blacklist, etc
fields := map[string]interface{}{}
fields["title"] = strings.TrimSpace(r.Form.Get("title"))
fields["body"] = strings.TrimSpace(r.Form.Get("body"))
fields["lyrics"] = strings.TrimSpace(r.Form.Get("lyrics"))
if data.PostEdit.Post.Provider == sgtmpb.Provider_IPFS {
Expand Down
12 changes: 6 additions & 6 deletions pkg/sgtm/page_post.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<meta name="twitter:image:src" property="og:image" itemprop="image primaryImageOfPage" content="https://sgtm.club/_assets/img/logo-1x.png" />
<meta property="og:image:width" content="2901" />
<meta property="og:image:height" content="2859" />
<meta name="twitter:title" property="og:title" itemprop="title name" content="{{.Post.Post.Title}} by {{.Post.Post.Author.DisplayName}}" />
<meta name="twitter:title" property="og:title" itemprop="title name" content="{{.Post.Post.SafeTitle}} by {{.Post.Post.Author.DisplayName}}" />
<meta name="twitter:description" property="og:description" itemprop="description" content="Sounds good to me (SGTM)." />
<meta name="description" content="Check out {{.Post.Post.Title}} by {{.Post.Post.Author.DisplayName}} on SGTM." />
<meta name="description" content="Check out {{.Post.Post.SafeTitle}} by {{.Post.Post.Author.DisplayName}} on SGTM." />

{{if .Post.Post.IsSoundCloud}}
<script type="text/javascript" src="https://w.soundcloud.com/player/api.js" defer></script>
Expand All @@ -23,7 +23,7 @@
<div class="container">
<div class="row">
<div class="col-md-8">
<h1>{{.Post.Post.Title}}</h1>
<h1>{{.Post.Post.SafeTitle}}</h1>
<p>by <a href="{{.Post.Post.Author.CanonicalURL}}"><img height="30" src="{{.Post.Post.Author.Avatar}}" />@{{.Post.Post.Author.Slug}}</a></p>

{{if .Post.Post.IsSoundCloud}}
Expand Down Expand Up @@ -56,7 +56,7 @@ <h1>{{.Post.Post.Title}}</h1>
{{end}}
{{if .Post.Post.IsIPFS}}
<div>🔈 Type: {{ .Post.Post.MIMEType }}</div>
<div>⬇️ <a download="{{.Post.Post.Title}}.{{.Post.Post.FileExtension}}" href="/post/{{ .Post.Post.ID }}/download">Download</a></div>
<div>⬇️ <a download="{{.Post.Post.SafeTitle}}.{{.Post.Post.FileExtension}}" href="/post/{{ .Post.Post.ID }}/download">Download</a></div>
<div style="word-break: break-all;">⚓ IPFS CID: {{ .Post.Post.IPFSCID }}</div>
{{end}}
<!--{{with .Post.Post.DownloadURL}}<div><a href="{{.}}" class="btn">⬇️ Download</a></div>{{end}}-->
Expand Down Expand Up @@ -121,10 +121,10 @@ <h1>{{.Post.Post.Title}}</h1>
<div class="card mb-3 bg-light">
<div class="card-header"><span class="fa fa-share-alt"></span> Sharing</div>
<div class="p-2">
<div><a href="https://twitter.com/intent/tweet?url=https://sgtm.club{{.Post.Post.CanonicalURL}}&text={{.Post.Post.Title}}+by+{{.Post.Post.Author.DisplayName}}" target="_blank" title="Share on Twitter">
<div><a href="https://twitter.com/intent/tweet?url=https://sgtm.club{{.Post.Post.CanonicalURL}}&text={{.Post.Post.SafeTitle}}+by+{{.Post.Post.Author.DisplayName}}" target="_blank" title="Share on Twitter">
<span class="fab fa-twitter" aria-hidden="true"></span> Share on Twitter
</a></div>
<div><a href="https://www.facebook.com/sharer/sharer.php?u=https://sgtm.club{{.Post.Post.CanonicalURL}}&t={{.Post.Post.Title}}+by+{{.Post.Post.Author.DisplayName}}" target="_blank" title="Share with Facebook">
<div><a href="https://www.facebook.com/sharer/sharer.php?u=https://sgtm.club{{.Post.Post.CanonicalURL}}&t={{.Post.Post.SafeTitle}}+by+{{.Post.Post.Author.DisplayName}}" target="_blank" title="Share with Facebook">
<span class="fab fa-facebook" aria-hidden="true"></span> Share on facebook
</a></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion pkg/sgtm/page_profile.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2>🎶 Tracks by {{.Profile.User.DisplayName}}</h2>
<div class="media">
<a href="{{.CanonicalURL}}"><img src="{{ .ArtworkURL }}" class="p-1 mr-3" width="100" alt="Artwork" /></a>
<div class="media-body">
<a href="{{.CanonicalURL}}"><h5 class="mt-0 d-inline-block">{{.Title}}</h5></a>
<a href="{{.CanonicalURL}}"><h5 class="mt-0 d-inline-block">{{.SafeTitle}}</h5></a>
<a href="{{.CanonicalURL}}"><small class="text-muted">{{.SortDate | fromUnixNano | prettyAgo}}</small></a>
<div>
{{with .SafeDescription}}<p>{{.}}</p>{{end}}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sgtm/page_rss.tmpl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<atom:link href="https://sgtm.club/rss.xml" rel="self" type="application/rss+xml"/>
{{range .RSS.LastTracks}}
<item>
<title>{{stripTags .Title}} by @{{.Author.Slug}}</title>
<title>{{stripTags .SafeTitle}} by @{{.Author.Slug}}</title>
<link>https://sgtm.club{{.CanonicalURL}}</link>
<pubDate>{{ dateInZone "02 Jan 06 15:04:05 MST" (.SortDate | fromUnixNano) "UTC"}}</pubDate>
<guid>https://sgtm.club{{.CanonicalURL}}</guid>
Expand Down
14 changes: 13 additions & 1 deletion pkg/sgtm/processing_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,24 @@ func (svc *Service) setupMigrations() {
// nothing to do
return nil
}

return tx.Model(post).Updates(map[string]interface{}{
"tags": post.Genre, // nolint:staticcheck
"genre": "",
}).Error
},

// set SoundCloud provider_title
func(post *sgtmpb.Post, tx *gorm.DB) error {
if post.GetProvider() != sgtmpb.Provider_SoundCloud || post.ProviderTitle != "" {
return nil
}

return tx.Model(post).Updates(map[string]interface{}{
"provider_title": post.Title,
"title": "",
}).Error
},

/*
// FIXME: try downloading the mp3 locally
func(post *sgtmpb.Post) error { return fmt.Errorf("not implemented") },
Expand Down
13 changes: 10 additions & 3 deletions pkg/sgtmpb/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import (
// Post

func (p *Post) ApplyDefaults() {
if p.Title == "" {
p.Title = "noname"
}
if p.ArtworkURL == "" && p.Provider == Provider_SoundCloud {
var metadata soundcloud.Track
err := json.Unmarshal([]byte(p.ProviderMetadata), &metadata)
Expand Down Expand Up @@ -42,6 +39,16 @@ func (p *Post) SafeDescription() string {
return p.ProviderDescription
}

func (p *Post) SafeTitle() string {
if p.Title != "" {
return p.Title
}
if p.ProviderTitle != "" {
return p.ProviderTitle
}
return "noname"
}

func (p *Post) SafeLyrics() string {
return strings.TrimSpace(p.Lyrics)
}
Expand Down
Loading

0 comments on commit 2558318

Please sign in to comment.