Merge branch 'develop' into wm-fix

pull/463/head
Matt Baer 4 years ago
commit f0697fd555
  1. 12
      database.go
  2. 4
      pad.go
  3. 30
      posts.go
  4. 1
      read.go
  5. 2
      templates/classic.tmpl

@ -875,7 +875,7 @@ func (db *datastore) UpdateCollection(c *SubmittedCollection, alias string) erro
// WHERE values // WHERE values
q.Where("alias = ? AND owner_id = ?", alias, c.OwnerID) q.Where("alias = ? AND owner_id = ?", alias, c.OwnerID)
if q.Updates == "" { if q.Updates == "" && c.Monetization == nil {
return ErrPostNoUpdatableVals return ErrPostNoUpdatableVals
} }
@ -932,10 +932,12 @@ func (db *datastore) UpdateCollection(c *SubmittedCollection, alias string) erro
} }
// Update rest of the collection data // Update rest of the collection data
res, err = db.Exec("UPDATE collections SET "+q.Updates+" WHERE "+q.Conditions, q.Params...) if q.Updates != "" {
if err != nil { res, err = db.Exec("UPDATE collections SET "+q.Updates+" WHERE "+q.Conditions, q.Params...)
log.Error("Unable to update collection: %v", err) if err != nil {
return err log.Error("Unable to update collection: %v", err)
return err
}
} }
rowsAffected, _ = res.RowsAffected() rowsAffected, _ = res.RowsAffected()

@ -90,6 +90,7 @@ func handleViewPad(app *App, w http.ResponseWriter, r *http.Request) error {
} }
appData.EditCollection, err = app.db.GetCollectionForPad(collAlias) appData.EditCollection, err = app.db.GetCollectionForPad(collAlias)
if err != nil { if err != nil {
log.Error("Unable to GetCollectionForPad: %s", err)
return err return err
} }
appData.EditCollection.hostName = app.cfg.App.Host appData.EditCollection.hostName = app.cfg.App.Host
@ -101,9 +102,10 @@ func handleViewPad(app *App, w http.ResponseWriter, r *http.Request) error {
if appData.Post.Gone { if appData.Post.Gone {
return ErrPostUnpublished return ErrPostUnpublished
} else if appData.Post.Found && appData.Post.Content != "" { } else if appData.Post.Found && (appData.Post.Title != "" || appData.Post.Content != "") {
// Got the post // Got the post
} else if appData.Post.Found { } else if appData.Post.Found {
log.Error("Found post, but other conditions failed.")
return ErrPostFetchError return ErrPostFetchError
} else { } else {
return ErrPostNotFound return ErrPostNotFound

@ -125,6 +125,7 @@ type (
Views int64 `json:"views"` Views int64 `json:"views"`
Owner *PublicUser `json:"-"` Owner *PublicUser `json:"-"`
IsOwner bool `json:"-"` IsOwner bool `json:"-"`
URL string `json:"url,omitempty"`
Collection *CollectionObj `json:"collection,omitempty"` Collection *CollectionObj `json:"collection,omitempty"`
} }
@ -396,7 +397,7 @@ func handleViewPost(app *App, w http.ResponseWriter, r *http.Request) error {
} }
// Check if post has been unpublished // Check if post has been unpublished
if content == "" { if title == "" && content == "" {
gone = true gone = true
if isJSON { if isJSON {
@ -545,9 +546,14 @@ func newPost(app *App, w http.ResponseWriter, r *http.Request) error {
t := "" t := ""
p.Title = &t p.Title = &t
} }
if strings.TrimSpace(*(p.Content)) == "" { if strings.TrimSpace(*(p.Title)) == "" && (p.Content == nil || strings.TrimSpace(*(p.Content)) == "") {
return ErrNoPublishableContent return ErrNoPublishableContent
} }
if p.Content == nil {
c := ""
p.Content = &c
}
} else { } else {
post := r.FormValue("body") post := r.FormValue("body")
appearance := r.FormValue("font") appearance := r.FormValue("font")
@ -612,6 +618,7 @@ func newPost(app *App, w http.ResponseWriter, r *http.Request) error {
newPost.extractData() newPost.extractData()
newPost.OwnerName = username newPost.OwnerName = username
newPost.URL = newPost.CanonicalURL(app.cfg.App.Host)
// Write success now // Write success now
response := impart.WriteSuccess(w, newPost, http.StatusCreated) response := impart.WriteSuccess(w, newPost, http.StatusCreated)
@ -1124,7 +1131,7 @@ func (p *Post) processPost() PublicPost {
func (p *PublicPost) CanonicalURL(hostName string) string { func (p *PublicPost) CanonicalURL(hostName string) string {
if p.Collection == nil || p.Collection.Alias == "" { if p.Collection == nil || p.Collection.Alias == "" {
return hostName + "/" + p.ID return hostName + "/" + p.ID + ".md"
} }
return p.Collection.CanonicalURL() + p.Slug.String return p.Collection.CanonicalURL() + p.Slug.String
} }
@ -1258,10 +1265,22 @@ func getRawPost(app *App, friendlyID string) *RawPost {
case err == sql.ErrNoRows: case err == sql.ErrNoRows:
return &RawPost{Content: "", Found: false, Gone: false} return &RawPost{Content: "", Found: false, Gone: false}
case err != nil: case err != nil:
log.Error("Unable to fetch getRawPost: %s", err)
return &RawPost{Content: "", Found: true, Gone: false} return &RawPost{Content: "", Found: true, Gone: false}
} }
return &RawPost{Title: title, Content: content, Font: font, Created: created, Updated: updated, IsRTL: isRTL, Language: lang, OwnerID: ownerID.Int64, Found: true, Gone: content == ""} return &RawPost{
Title: title,
Content: content,
Font: font,
Created: created,
Updated: updated,
IsRTL: isRTL,
Language: lang,
OwnerID: ownerID.Int64,
Found: true,
Gone: content == "" && title == "",
}
} }
@ -1284,6 +1303,7 @@ func getRawCollectionPost(app *App, slug, collAlias string) *RawPost {
case err == sql.ErrNoRows: case err == sql.ErrNoRows:
return &RawPost{Content: "", Found: false, Gone: false} return &RawPost{Content: "", Found: false, Gone: false}
case err != nil: case err != nil:
log.Error("Unable to fetch getRawCollectionPost: %s", err)
return &RawPost{Content: "", Found: true, Gone: false} return &RawPost{Content: "", Found: true, Gone: false}
} }
@ -1299,7 +1319,7 @@ func getRawCollectionPost(app *App, slug, collAlias string) *RawPost {
Language: lang, Language: lang,
OwnerID: ownerID.Int64, OwnerID: ownerID.Int64,
Found: true, Found: true,
Gone: content == "", Gone: content == "" && title == "",
Views: views, Views: views,
} }
} }

@ -315,7 +315,6 @@ func viewLocalTimelineFeed(app *App, w http.ResponseWriter, req *http.Request) e
author = p.Collection.Title author = p.Collection.Title
} else { } else {
author = "Anonymous" author = "Anonymous"
permalink += ".md"
} }
i := &Item{ i := &Item{
Id: app.cfg.App.Host + "/read/a/" + p.ID, Id: app.cfg.App.Host + "/read/a/" + p.ID,

@ -283,7 +283,7 @@
*/ */
$btnPublish.on('click', function(e) { $btnPublish.on('click', function(e) {
e.preventDefault(); e.preventDefault();
if (!publishing && $content.el.value) { if (!publishing && ($title.el.value || $content.el.value)) {
var title = $title.el.value; var title = $title.el.value;
var content = $content.el.value; var content = $content.el.value;
publish(title, content, selectedFont); publish(title, content, selectedFont);

Loading…
Cancel
Save