Merge branch 'export-title' into import-zip

This commit is contained in:
Matt Baer 2019-05-30 10:44:31 -04:00
commit 98700fc576
6 changed files with 25 additions and 14 deletions

View File

@ -127,7 +127,7 @@ func handleFetchCollectionOutbox(app *app, w http.ResponseWriter, r *http.Reques
ocp := activitystreams.NewOrderedCollectionPage(accountRoot, "outbox", res.TotalPosts, p)
ocp.OrderedItems = []interface{}{}
posts, err := app.db.GetPosts(c, p, false, true)
posts, err := app.db.GetPosts(c, p, false, true, false)
for _, pp := range *posts {
pp.Collection = res
o := pp.ActivityObject()

View File

@ -492,7 +492,7 @@ func fetchCollectionPosts(app *app, w http.ResponseWriter, r *http.Request) erro
}
}
posts, err := app.db.GetPosts(c, page, isCollOwner, false)
posts, err := app.db.GetPosts(c, page, isCollOwner, false, false)
if err != nil {
return err
}
@ -723,7 +723,7 @@ func handleViewCollection(app *app, w http.ResponseWriter, r *http.Request) erro
return impart.HTTPError{http.StatusFound, redirURL}
}
coll.Posts, _ = app.db.GetPosts(c, page, cr.isCollOwner, false)
coll.Posts, _ = app.db.GetPosts(c, page, cr.isCollOwner, false, false)
// Serve collection
displayPage := CollectionPage{

View File

@ -104,7 +104,7 @@ type writestore interface {
ClaimPosts(userID int64, collAlias string, posts *[]ClaimPostRequest) (*[]ClaimPostResult, error)
GetPostsCount(c *CollectionObj, includeFuture bool)
GetPosts(c *Collection, page int, includeFuture, forceRecentFirst bool) (*[]PublicPost, error)
GetPosts(c *Collection, page int, includeFuture, forceRecentFirst, includePinned bool) (*[]PublicPost, error)
GetPostsTagged(c *Collection, tag string, page int, includeFuture bool) (*[]PublicPost, error)
GetAPFollowers(c *Collection) (*[]RemoteUser, error)
@ -1062,10 +1062,11 @@ func (db *datastore) GetPostsCount(c *CollectionObj, includeFuture bool) {
c.TotalPosts = int(count)
}
// GetPosts retrieves all standard (non-pinned) posts for the given Collection.
// GetPosts retrieves all posts for the given Collection.
// It will return future posts if `includeFuture` is true.
// It will include only standard (non-pinned) posts unless `includePinned` is true.
// TODO: change includeFuture to isOwner, since that's how it's used
func (db *datastore) GetPosts(c *Collection, page int, includeFuture, forceRecentFirst bool) (*[]PublicPost, error) {
func (db *datastore) GetPosts(c *Collection, page int, includeFuture, forceRecentFirst, includePinned bool) (*[]PublicPost, error) {
collID := c.ID
cf := c.NewFormat()
@ -1089,7 +1090,11 @@ func (db *datastore) GetPosts(c *Collection, page int, includeFuture, forceRecen
if !includeFuture {
timeCondition = "AND created <= " + db.now()
}
rows, err := db.Query("SELECT "+postCols+" FROM posts WHERE collection_id = ? AND pinned_position IS NULL "+timeCondition+" ORDER BY created "+order+limitStr, collID)
pinnedCondition := ""
if !includePinned {
pinnedCondition = "AND pinned_position IS NULL"
}
rows, err := db.Query("SELECT "+postCols+" FROM posts WHERE collection_id = ? "+pinnedCondition+" "+timeCondition+" ORDER BY created "+order+limitStr, collID)
if err != nil {
log.Error("Failed selecting from posts: %v", err)
return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve collection posts."}

View File

@ -44,8 +44,9 @@ func exportPostsCSV(u *User, posts *[]PublicPost) []byte {
}
type exportedTxt struct {
Name, Body string
Mod time.Time
Name, Title, Body string
Mod time.Time
}
func exportPostsZip(u *User, posts *[]PublicPost) []byte {
@ -67,7 +68,7 @@ func exportPostsZip(u *User, posts *[]PublicPost) []byte {
filename += p.Slug.String + "_"
}
filename += p.ID + ".txt"
files = append(files, exportedTxt{filename, p.Content, p.Created})
files = append(files, exportedTxt{filename, p.Title.String, p.Content, p.Created})
}
for _, file := range files {
@ -77,7 +78,12 @@ func exportPostsZip(u *User, posts *[]PublicPost) []byte {
if err != nil {
log.Error("export zip header: %v", err)
}
_, err = f.Write([]byte(file.Body))
var fullPost string
if file.Title != "" {
fullPost = "# " + file.Title + "\n\n"
}
fullPost += file.Body
_, err = f.Write([]byte(fullPost))
if err != nil {
log.Error("export zip write: %v", err)
}
@ -111,7 +117,7 @@ func compileFullExport(app *app, u *User) *ExportUser {
var collObjs []CollectionObj
for _, c := range *colls {
co := &CollectionObj{Collection: c}
co.Posts, err = app.db.GetPosts(&c, 0, true, false)
co.Posts, err = app.db.GetPosts(&c, 0, true, false, true)
if err != nil {
log.Error("unable to get collection posts: %v", err)
}

View File

@ -56,7 +56,7 @@ func ViewFeed(app *app, w http.ResponseWriter, req *http.Request) error {
if tag != "" {
coll.Posts, _ = app.db.GetPostsTagged(c, tag, 1, false)
} else {
coll.Posts, _ = app.db.GetPosts(c, 1, false, true)
coll.Posts, _ = app.db.GetPosts(c, 1, false, true, false)
}
author := ""

View File

@ -64,7 +64,7 @@ func handleViewSitemap(app *app, w http.ResponseWriter, r *http.Request) error {
host = c.CanonicalURL()
sm := buildSitemap(host, pre)
posts, err := app.db.GetPosts(c, 0, false, false)
posts, err := app.db.GetPosts(c, 0, false, false, false)
if err != nil {
log.Error("Error getting posts: %v", err)
return err