mirror of
https://github.com/go-shiori/shiori.git
synced 2025-11-08 06:11:36 +08:00
fix: golangci-lint errors (#366)
This commit is contained in:
parent
2ca628b7fe
commit
a76b121098
8 changed files with 140 additions and 82 deletions
|
|
@ -37,7 +37,9 @@ func exportHandler(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// Make sure destination directory exist
|
// Make sure destination directory exist
|
||||||
dstDir := fp.Dir(args[0])
|
dstDir := fp.Dir(args[0])
|
||||||
os.MkdirAll(dstDir, os.ModePerm)
|
if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
|
||||||
|
cError.Printf("Error crating destination directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Create destination file
|
// Create destination file
|
||||||
dstFile, err := os.Create(args[0])
|
dstFile, err := os.Create(args[0])
|
||||||
|
|
|
||||||
|
|
@ -13,21 +13,19 @@ import (
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/go-shiori/shiori/internal/model"
|
"github.com/go-shiori/shiori/internal/model"
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cIndex = color.New(color.FgHiCyan)
|
cIndex = color.New(color.FgHiCyan)
|
||||||
cSymbol = color.New(color.FgHiMagenta)
|
cSymbol = color.New(color.FgHiMagenta)
|
||||||
cTitle = color.New(color.FgHiGreen).Add(color.Bold)
|
cTitle = color.New(color.FgHiGreen).Add(color.Bold)
|
||||||
cReadTime = color.New(color.FgHiMagenta)
|
|
||||||
cURL = color.New(color.FgHiYellow)
|
cURL = color.New(color.FgHiYellow)
|
||||||
cExcerpt = color.New(color.FgHiWhite)
|
cExcerpt = color.New(color.FgHiWhite)
|
||||||
cTag = color.New(color.FgHiBlue)
|
cTag = color.New(color.FgHiBlue)
|
||||||
|
|
||||||
cInfo = color.New(color.FgHiCyan)
|
cInfo = color.New(color.FgHiCyan)
|
||||||
cError = color.New(color.FgHiRed)
|
cError = color.New(color.FgHiRed)
|
||||||
cWarning = color.New(color.FgHiYellow)
|
|
||||||
|
|
||||||
errInvalidIndex = errors.New("Index is not valid")
|
errInvalidIndex = errors.New("Index is not valid")
|
||||||
)
|
)
|
||||||
|
|
@ -130,7 +128,7 @@ func openBrowser(url string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTerminalWidth() int {
|
func getTerminalWidth() int {
|
||||||
width, _, _ := terminal.GetSize(int(os.Stdin.Fd()))
|
width, _, _ := term.GetSize(int(os.Stdin.Fd()))
|
||||||
return width
|
return width
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func ProcessBookmark(req ProcessRequest) (model.Bookmark, bool, error) {
|
||||||
|
|
||||||
nurl, err := url.Parse(book.URL)
|
nurl, err := url.Parse(book.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("Failed to parse url: %v", err)
|
return book, true, fmt.Errorf("Failed to parse url: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
article, err := readability.FromReader(readabilityInput, nurl)
|
article, err := readability.FromReader(readabilityInput, nurl)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package database
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -33,7 +34,9 @@ func OpenMySQLDatabase(connString string) (mysqlDB *MySQLDatabase, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
mysqlDB = nil
|
mysqlDB = nil
|
||||||
err = panicErr
|
err = panicErr
|
||||||
|
|
@ -102,7 +105,9 @@ func (db *MySQLDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []mo
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
result = []model.Bookmark{}
|
result = []model.Bookmark{}
|
||||||
err = panicErr
|
err = panicErr
|
||||||
|
|
@ -192,7 +197,9 @@ func (db *MySQLDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []mo
|
||||||
tag.ID = int(tagID64)
|
tag.ID = int(tagID64)
|
||||||
}
|
}
|
||||||
|
|
||||||
stmtInsertBookTag.Exec(tag.ID, book.ID)
|
if _, err := stmtInsertBookTag.Exec(tag.ID, book.ID); err != nil {
|
||||||
|
log.Printf("error during insert: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newTags = append(newTags, tag)
|
newTags = append(newTags, tag)
|
||||||
|
|
@ -458,7 +465,9 @@ func (db *MySQLDatabase) DeleteBookmarks(ids ...int) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
err = panicErr
|
err = panicErr
|
||||||
}
|
}
|
||||||
|
|
@ -507,7 +516,9 @@ func (db *MySQLDatabase) GetBookmark(id int, url string) (model.Bookmark, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
book := model.Bookmark{}
|
book := model.Bookmark{}
|
||||||
db.Get(&book, query, args...)
|
if err := db.Get(&book, query, args...); err != nil {
|
||||||
|
log.Printf("error during db.get: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
return book, book.ID != 0
|
return book, book.ID != 0
|
||||||
}
|
}
|
||||||
|
|
@ -562,9 +573,12 @@ func (db *MySQLDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account,
|
||||||
// Returns the account and boolean whether it's exist or not.
|
// Returns the account and boolean whether it's exist or not.
|
||||||
func (db *MySQLDatabase) GetAccount(username string) (model.Account, bool) {
|
func (db *MySQLDatabase) GetAccount(username string) (model.Account, bool) {
|
||||||
account := model.Account{}
|
account := model.Account{}
|
||||||
db.Get(&account, `SELECT
|
if err := db.Get(&account, `SELECT
|
||||||
id, username, password, owner FROM account WHERE username = ?`,
|
id, username, password, owner FROM account WHERE username = ?`,
|
||||||
username)
|
username,
|
||||||
|
); err != nil {
|
||||||
|
log.Printf("error during db.get: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
return account, account.ID != 0
|
return account, account.ID != 0
|
||||||
}
|
}
|
||||||
|
|
@ -581,7 +595,9 @@ func (db *MySQLDatabase) DeleteAccounts(usernames ...string) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
err = panicErr
|
err = panicErr
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package database
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -32,8 +33,9 @@ func OpenPGDatabase(connString string) (pgDB *PGDatabase, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
pgDB = nil
|
pgDB = nil
|
||||||
err = panicErr
|
err = panicErr
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +100,9 @@ func (db *PGDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []model
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
result = []model.Bookmark{}
|
result = []model.Bookmark{}
|
||||||
err = panicErr
|
err = panicErr
|
||||||
|
|
@ -188,7 +192,9 @@ func (db *PGDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []model
|
||||||
tag.ID = int(tagID64)
|
tag.ID = int(tagID64)
|
||||||
}
|
}
|
||||||
|
|
||||||
stmtInsertBookTag.Exec(tag.ID, book.ID)
|
if _, err := stmtInsertBookTag.Exec(tag.ID, book.ID); err != nil {
|
||||||
|
log.Printf("error during insert: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newTags = append(newTags, tag)
|
newTags = append(newTags, tag)
|
||||||
|
|
@ -315,7 +321,8 @@ func (db *PGDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmark,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand query, because some of the args might be an array
|
// Expand query, because some of the args might be an array
|
||||||
query, args, err := sqlx.Named(query, arg)
|
var err error
|
||||||
|
query, args, _ := sqlx.Named(query, arg)
|
||||||
query, args, err = sqlx.In(query, args...)
|
query, args, err = sqlx.In(query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to expand query: %v", err)
|
return nil, fmt.Errorf("failed to expand query: %v", err)
|
||||||
|
|
@ -431,7 +438,8 @@ func (db *PGDatabase) GetBookmarksCount(opts GetBookmarksOptions) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand query, because some of the args might be an array
|
// Expand query, because some of the args might be an array
|
||||||
query, args, err := sqlx.Named(query, arg)
|
var err error
|
||||||
|
query, args, _ := sqlx.Named(query, arg)
|
||||||
query, args, err = sqlx.In(query, args...)
|
query, args, err = sqlx.In(query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("failed to expand query: %v", err)
|
return 0, fmt.Errorf("failed to expand query: %v", err)
|
||||||
|
|
@ -460,8 +468,9 @@ func (db *PGDatabase) DeleteBookmarks(ids ...int) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
err = panicErr
|
err = panicErr
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
@ -509,7 +518,9 @@ func (db *PGDatabase) GetBookmark(id int, url string) (model.Bookmark, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
book := model.Bookmark{}
|
book := model.Bookmark{}
|
||||||
db.Get(&book, query, args...)
|
if err := db.Get(&book, query, args...); err != nil {
|
||||||
|
log.Printf("error during db.get: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
return book, book.ID != 0
|
return book, book.ID != 0
|
||||||
}
|
}
|
||||||
|
|
@ -564,9 +575,12 @@ func (db *PGDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account, err
|
||||||
// Returns the account and boolean whether it's exist or not.
|
// Returns the account and boolean whether it's exist or not.
|
||||||
func (db *PGDatabase) GetAccount(username string) (model.Account, bool) {
|
func (db *PGDatabase) GetAccount(username string) (model.Account, bool) {
|
||||||
account := model.Account{}
|
account := model.Account{}
|
||||||
db.Get(&account, `SELECT
|
if err := db.Get(&account, `SELECT
|
||||||
id, username, password, owner FROM account WHERE username = $1`,
|
id, username, password, owner FROM account WHERE username = $1`,
|
||||||
username)
|
username,
|
||||||
|
); err != nil {
|
||||||
|
log.Printf("error during db.get: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
return account, account.ID != 0
|
return account, account.ID != 0
|
||||||
}
|
}
|
||||||
|
|
@ -583,8 +597,9 @@ func (db *PGDatabase) DeleteAccounts(usernames ...string) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
err = panicErr
|
err = panicErr
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package database
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -31,8 +32,9 @@ func OpenSQLiteDatabase(databasePath string) (sqliteDB *SQLiteDatabase, err erro
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
sqliteDB = nil
|
sqliteDB = nil
|
||||||
err = panicErr
|
err = panicErr
|
||||||
}
|
}
|
||||||
|
|
@ -74,8 +76,12 @@ func OpenSQLiteDatabase(databasePath string) (sqliteDB *SQLiteDatabase, err erro
|
||||||
tx.MustExec(`CREATE VIRTUAL TABLE IF NOT EXISTS bookmark_content USING fts5(title, content, html, docid)`)
|
tx.MustExec(`CREATE VIRTUAL TABLE IF NOT EXISTS bookmark_content USING fts5(title, content, html, docid)`)
|
||||||
|
|
||||||
// Alter table if needed
|
// Alter table if needed
|
||||||
tx.Exec(`ALTER TABLE account ADD COLUMN owner INTEGER NOT NULL DEFAULT 0`)
|
if _, err := tx.Exec(`ALTER TABLE account ADD COLUMN owner INTEGER NOT NULL DEFAULT 0`); err != nil {
|
||||||
tx.Exec(`ALTER TABLE bookmark ADD COLUMN public INTEGER NOT NULL DEFAULT 0`)
|
log.Printf("error during database alert: %s", err)
|
||||||
|
}
|
||||||
|
if _, err := tx.Exec(`ALTER TABLE bookmark ADD COLUMN public INTEGER NOT NULL DEFAULT 0`); err != nil {
|
||||||
|
log.Printf("error during database alert: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
checkError(err)
|
checkError(err)
|
||||||
|
|
@ -97,8 +103,9 @@ func (db *SQLiteDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []m
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
result = []model.Bookmark{}
|
result = []model.Bookmark{}
|
||||||
err = panicErr
|
err = panicErr
|
||||||
}
|
}
|
||||||
|
|
@ -112,9 +119,9 @@ func (db *SQLiteDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []m
|
||||||
url = ?, title = ?, excerpt = ?, author = ?,
|
url = ?, title = ?, excerpt = ?, author = ?,
|
||||||
public = ?, modified = ?`)
|
public = ?, modified = ?`)
|
||||||
|
|
||||||
stmtInsertBookContent, _ := tx.Preparex(`INSERT OR IGNORE INTO bookmark_content
|
// stmtInsertBookContent, _ := tx.Preparex(`INSERT OR IGNORE INTO bookmark_content
|
||||||
(docid, title, content, html)
|
// (docid, title, content, html)
|
||||||
VALUES (?, ?, ?, ?)`)
|
// VALUES (?, ?, ?, ?)`)
|
||||||
|
|
||||||
stmtUpdateBookContent, _ := tx.Preparex(`UPDATE bookmark_content SET
|
stmtUpdateBookContent, _ := tx.Preparex(`UPDATE bookmark_content SET
|
||||||
title = ?, content = ?, html = ?
|
title = ?, content = ?, html = ?
|
||||||
|
|
@ -158,7 +165,7 @@ func (db *SQLiteDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []m
|
||||||
book.URL, book.Title, book.Excerpt, book.Author, book.Public, book.Modified)
|
book.URL, book.Title, book.Excerpt, book.Author, book.Public, book.Modified)
|
||||||
|
|
||||||
stmtUpdateBookContent.MustExec(book.Title, book.Content, book.HTML, book.ID)
|
stmtUpdateBookContent.MustExec(book.Title, book.Content, book.HTML, book.ID)
|
||||||
stmtInsertBookContent.MustExec(book.ID, book.Title, book.Content, book.HTML)
|
//stmtInsertBookContent.MustExec(book.ID, book.Title, book.Content, book.HTML)
|
||||||
|
|
||||||
// Save book tags
|
// Save book tags
|
||||||
newTags := []model.Tag{}
|
newTags := []model.Tag{}
|
||||||
|
|
@ -187,7 +194,9 @@ func (db *SQLiteDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []m
|
||||||
tag.ID = int(tagID64)
|
tag.ID = int(tagID64)
|
||||||
}
|
}
|
||||||
|
|
||||||
stmtInsertBookTag.Exec(tag.ID, book.ID)
|
if _, err := stmtInsertBookTag.Exec(tag.ID, book.ID); err != nil {
|
||||||
|
log.Printf("error during insert: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newTags = append(newTags, tag)
|
newTags = append(newTags, tag)
|
||||||
|
|
@ -215,7 +224,7 @@ func (db *SQLiteDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookma
|
||||||
`b.author`,
|
`b.author`,
|
||||||
`b.public`,
|
`b.public`,
|
||||||
`b.modified`,
|
`b.modified`,
|
||||||
`bc.content <> "" has_content`,}
|
`bc.content <> "" has_content`}
|
||||||
|
|
||||||
if opts.WithContent {
|
if opts.WithContent {
|
||||||
columns = append(columns, `bc.content`, `bc.html`)
|
columns = append(columns, `bc.content`, `bc.html`)
|
||||||
|
|
@ -464,8 +473,9 @@ func (db *SQLiteDatabase) DeleteBookmarks(ids ...int) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
err = panicErr
|
err = panicErr
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
@ -520,7 +530,9 @@ func (db *SQLiteDatabase) GetBookmark(id int, url string) (model.Bookmark, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
book := model.Bookmark{}
|
book := model.Bookmark{}
|
||||||
db.Get(&book, query, args...)
|
if err := db.Get(&book, query, args...); err != nil {
|
||||||
|
log.Printf("error during db.get: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
return book, book.ID != 0
|
return book, book.ID != 0
|
||||||
}
|
}
|
||||||
|
|
@ -575,9 +587,12 @@ func (db *SQLiteDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account,
|
||||||
// Returns the account and boolean whether it's exist or not.
|
// Returns the account and boolean whether it's exist or not.
|
||||||
func (db *SQLiteDatabase) GetAccount(username string) (model.Account, bool) {
|
func (db *SQLiteDatabase) GetAccount(username string) (model.Account, bool) {
|
||||||
account := model.Account{}
|
account := model.Account{}
|
||||||
db.Get(&account, `SELECT
|
if err := db.Get(&account, `SELECT
|
||||||
id, username, password, owner FROM account WHERE username = ?`,
|
id, username, password, owner FROM account WHERE username = ?`,
|
||||||
username)
|
username,
|
||||||
|
); err != nil {
|
||||||
|
log.Printf("error during db.get: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
return account, account.ID != 0
|
return account, account.ID != 0
|
||||||
}
|
}
|
||||||
|
|
@ -594,8 +609,9 @@ func (db *SQLiteDatabase) DeleteAccounts(usernames ...string) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panicErr, _ := r.(error)
|
panicErr, _ := r.(error)
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
log.Printf("error during rollback: %s", err)
|
||||||
|
}
|
||||||
err = panicErr
|
err = panicErr
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,6 @@ func (h *handler) apiLogin(w http.ResponseWriter, r *http.Request, ps httprouter
|
||||||
expTime := time.Hour
|
expTime := time.Hour
|
||||||
if request.Remember {
|
if request.Remember {
|
||||||
expTime = time.Hour * 24 * 30
|
expTime = time.Hour * 24 * 30
|
||||||
} else {
|
|
||||||
expTime = time.Hour
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create session
|
// Create session
|
||||||
|
|
@ -675,7 +673,7 @@ func (h *handler) apiDeleteAccount(w http.ResponseWriter, r *http.Request, ps ht
|
||||||
checkError(err)
|
checkError(err)
|
||||||
|
|
||||||
// Delete user's sessions
|
// Delete user's sessions
|
||||||
userSessions := []string{}
|
var userSessions []string
|
||||||
for _, username := range usernames {
|
for _, username := range usernames {
|
||||||
if val, found := h.UserCache.Get(username); found {
|
if val, found := h.UserCache.Get(username); found {
|
||||||
userSessions = val.([]string)
|
userSessions = val.([]string)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -58,7 +59,9 @@ func (h *handler) serveIndexPage(w http.ResponseWriter, r *http.Request, ps http
|
||||||
}
|
}
|
||||||
|
|
||||||
if developmentMode {
|
if developmentMode {
|
||||||
h.prepareTemplates()
|
if err := h.prepareTemplates(); err != nil {
|
||||||
|
log.Printf("error during template preparation: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.templates["index"].Execute(w, h.RootPath)
|
err = h.templates["index"].Execute(w, h.RootPath)
|
||||||
|
|
@ -76,7 +79,9 @@ func (h *handler) serveLoginPage(w http.ResponseWriter, r *http.Request, ps http
|
||||||
}
|
}
|
||||||
|
|
||||||
if developmentMode {
|
if developmentMode {
|
||||||
h.prepareTemplates()
|
if err := h.prepareTemplates(); err != nil {
|
||||||
|
log.Printf("error during template preparation: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.templates["login"].Execute(w, h.RootPath)
|
err = h.templates["login"].Execute(w, h.RootPath)
|
||||||
|
|
@ -177,7 +182,9 @@ func (h *handler) serveBookmarkContent(w http.ResponseWriter, r *http.Request, p
|
||||||
|
|
||||||
// Execute template
|
// Execute template
|
||||||
if developmentMode {
|
if developmentMode {
|
||||||
h.prepareTemplates()
|
if err := h.prepareTemplates(); err != nil {
|
||||||
|
log.Printf("error during template preparation: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tplData := struct {
|
tplData := struct {
|
||||||
|
|
@ -217,7 +224,9 @@ func (h *handler) serveThumbnailImage(w http.ResponseWriter, r *http.Request, ps
|
||||||
w.Header().Set("Cache-Control", "max-age=86400")
|
w.Header().Set("Cache-Control", "max-age=86400")
|
||||||
|
|
||||||
// Serve image
|
// Serve image
|
||||||
img.Seek(0, 0)
|
if _, err := img.Seek(0, 0); err != nil {
|
||||||
|
log.Printf("error during image seek: %s", err)
|
||||||
|
}
|
||||||
_, err = io.Copy(w, img)
|
_, err = io.Copy(w, img)
|
||||||
checkError(err)
|
checkError(err)
|
||||||
}
|
}
|
||||||
|
|
@ -301,11 +310,15 @@ func (h *handler) serveBookmarkArchive(w http.ResponseWriter, r *http.Request, p
|
||||||
|
|
||||||
// Gzip it again and send to response writer
|
// Gzip it again and send to response writer
|
||||||
gzipWriter := gzip.NewWriter(w)
|
gzipWriter := gzip.NewWriter(w)
|
||||||
gzipWriter.Write([]byte(outerHTML))
|
if _, err := gzipWriter.Write([]byte(outerHTML)); err != nil {
|
||||||
|
log.Printf("error writting gzip file: %s", err)
|
||||||
|
}
|
||||||
gzipWriter.Flush()
|
gzipWriter.Flush()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve content
|
// Serve content
|
||||||
w.Write(content)
|
if _, err := w.Write(content); err != nil {
|
||||||
|
log.Printf("error writting response: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue