mirror of
https://github.com/go-shiori/shiori.git
synced 2025-02-22 06:53:22 +08:00
Fix: bookmarks not ordered by latest in web view
This commit is contained in:
parent
786cae511a
commit
ac75f8cff5
4 changed files with 8 additions and 4 deletions
|
@ -30,7 +30,7 @@ var (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read bookmarks from database
|
// Read bookmarks from database
|
||||||
bookmarks, err := DB.SearchBookmarks(keyword, tags...)
|
bookmarks, err := DB.SearchBookmarks(false, keyword, tags...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cError.Println(err)
|
cError.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -202,7 +202,7 @@ func apiGetBookmarks(w http.ResponseWriter, r *http.Request, ps httprouter.Param
|
||||||
checkError(err)
|
checkError(err)
|
||||||
|
|
||||||
// Fetch all bookmarks
|
// Fetch all bookmarks
|
||||||
bookmarks, err := DB.SearchBookmarks(keyword, tags...)
|
bookmarks, err := DB.SearchBookmarks(true, keyword, tags...)
|
||||||
checkError(err)
|
checkError(err)
|
||||||
|
|
||||||
err = json.NewEncoder(w).Encode(&bookmarks)
|
err = json.NewEncoder(w).Encode(&bookmarks)
|
||||||
|
|
|
@ -17,7 +17,7 @@ type Database interface {
|
||||||
DeleteBookmarks(indices ...string) ([]int, []int, error)
|
DeleteBookmarks(indices ...string) ([]int, []int, error)
|
||||||
|
|
||||||
// SearchBookmarks search bookmarks by the keyword or tags.
|
// SearchBookmarks search bookmarks by the keyword or tags.
|
||||||
SearchBookmarks(keyword string, tags ...string) ([]model.Bookmark, error)
|
SearchBookmarks(orderLatest bool, keyword string, tags ...string) ([]model.Bookmark, error)
|
||||||
|
|
||||||
// UpdateBookmarks updates the saved bookmark in database.
|
// UpdateBookmarks updates the saved bookmark in database.
|
||||||
UpdateBookmarks(bookmarks []model.Bookmark) error
|
UpdateBookmarks(bookmarks []model.Bookmark) error
|
||||||
|
|
|
@ -384,7 +384,7 @@ func (db *SQLiteDatabase) DeleteBookmarks(indices ...string) (oldIndices, newInd
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchBookmarks search bookmarks by the keyword or tags.
|
// SearchBookmarks search bookmarks by the keyword or tags.
|
||||||
func (db *SQLiteDatabase) SearchBookmarks(keyword string, tags ...string) ([]model.Bookmark, error) {
|
func (db *SQLiteDatabase) SearchBookmarks(orderLatest bool, keyword string, tags ...string) ([]model.Bookmark, error) {
|
||||||
// Create initial variable
|
// Create initial variable
|
||||||
keyword = strings.TrimSpace(keyword)
|
keyword = strings.TrimSpace(keyword)
|
||||||
whereClause := "WHERE 1"
|
whereClause := "WHERE 1"
|
||||||
|
@ -421,6 +421,10 @@ func (db *SQLiteDatabase) SearchBookmarks(keyword string, tags ...string) ([]mod
|
||||||
min_read_time, max_read_time, modified
|
min_read_time, max_read_time, modified
|
||||||
FROM bookmark ` + whereClause
|
FROM bookmark ` + whereClause
|
||||||
|
|
||||||
|
if orderLatest {
|
||||||
|
query += ` ORDER BY modified DESC`
|
||||||
|
}
|
||||||
|
|
||||||
bookmarks := []model.Bookmark{}
|
bookmarks := []model.Bookmark{}
|
||||||
err := db.Select(&bookmarks, query, args...)
|
err := db.Select(&bookmarks, query, args...)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
|
Loading…
Reference in a new issue