mirror of
https://github.com/writeas/writefreely
synced 2025-01-05 20:47:30 +01:00
Fix URLs in CSV exports
This includes the instance's hostname in calls to export a CSV file and PublicPost.CanonicalURL(). It also fixes a panic in that method during CSV export caused by draft posts.
This commit is contained in:
parent
3167e19b77
commit
e1149cd1e9
@ -625,7 +625,7 @@ func viewExportPosts(app *App, w http.ResponseWriter, r *http.Request) ([]byte,
|
||||
|
||||
// Export as CSV
|
||||
if strings.HasSuffix(r.URL.Path, ".csv") {
|
||||
data = exportPostsCSV(u, posts)
|
||||
data = exportPostsCSV(app.cfg.App.Host, u, posts)
|
||||
return data, filename, err
|
||||
}
|
||||
if strings.HasSuffix(r.URL.Path, ".zip") {
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"github.com/writeas/web-core/log"
|
||||
)
|
||||
|
||||
func exportPostsCSV(u *User, posts *[]PublicPost) []byte {
|
||||
func exportPostsCSV(hostName string, u *User, posts *[]PublicPost) []byte {
|
||||
var b bytes.Buffer
|
||||
|
||||
r := [][]string{
|
||||
@ -30,8 +30,9 @@ func exportPostsCSV(u *User, posts *[]PublicPost) []byte {
|
||||
var blog string
|
||||
if p.Collection != nil {
|
||||
blog = p.Collection.Alias
|
||||
p.Collection.hostName = hostName
|
||||
}
|
||||
f := []string{p.ID, p.Slug.String, blog, p.CanonicalURL(), p.Created8601(), p.Title.String, strings.Replace(p.Content, "\n", "\\n", -1)}
|
||||
f := []string{p.ID, p.Slug.String, blog, p.CanonicalURL(hostName), p.Created8601(), p.Title.String, strings.Replace(p.Content, "\n", "\\n", -1)}
|
||||
r = append(r, f)
|
||||
}
|
||||
|
||||
|
6
posts.go
6
posts.go
@ -1061,9 +1061,9 @@ func (p *Post) processPost() PublicPost {
|
||||
return *res
|
||||
}
|
||||
|
||||
func (p *PublicPost) CanonicalURL() string {
|
||||
func (p *PublicPost) CanonicalURL(hostName string) string {
|
||||
if p.Collection == nil || p.Collection.Alias == "" {
|
||||
return p.Collection.hostName + "/" + p.ID
|
||||
return hostName + "/" + p.ID
|
||||
}
|
||||
return p.Collection.CanonicalURL() + p.Slug.String
|
||||
}
|
||||
@ -1072,7 +1072,7 @@ func (p *PublicPost) ActivityObject(cfg *config.Config) *activitystreams.Object
|
||||
o := activitystreams.NewArticleObject()
|
||||
o.ID = p.Collection.FederatedAPIBase() + "api/posts/" + p.ID
|
||||
o.Published = p.Created
|
||||
o.URL = p.CanonicalURL()
|
||||
o.URL = p.CanonicalURL(cfg.App.Host)
|
||||
o.AttributedTo = p.Collection.FederatedAccount()
|
||||
o.CC = []string{
|
||||
p.Collection.FederatedAccount() + "/followers",
|
||||
|
Loading…
Reference in New Issue
Block a user