Rename helper packages
This commit is contained in:
parent
3c3f397bf5
commit
c39f2e1a8d
31 changed files with 97 additions and 97 deletions
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package helper
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the MIT License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package helper
|
||||
package duration
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
@ -26,9 +26,9 @@ var (
|
|||
Years = `%d years ago`
|
||||
)
|
||||
|
||||
// GetElapsedTime returns in a human readable format the elapsed time
|
||||
// ElapsedTime returns in a human readable format the elapsed time
|
||||
// since the given datetime.
|
||||
func GetElapsedTime(translator *locale.Language, t time.Time) string {
|
||||
func ElapsedTime(translator *locale.Language, t time.Time) string {
|
||||
if t.IsZero() || time.Now().Before(t) {
|
||||
return translator.Get(NotYet)
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the MIT License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package helper
|
||||
package duration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -31,7 +31,7 @@ func TestElapsedTime(t *testing.T) {
|
|||
{time.Now().Add(-time.Hour * 24 * 365 * 3), fmt.Sprintf(Years, 3)},
|
||||
}
|
||||
for i, tt := range dt {
|
||||
if out := GetElapsedTime(&locale.Language{}, tt.in); out != tt.out {
|
||||
if out := ElapsedTime(&locale.Language{}, tt.in); out != tt.out {
|
||||
t.Errorf("%d. content mismatch for %v:exp=%q got=%q", i, tt.in, tt.out, out)
|
||||
}
|
||||
}
|
|
@ -15,8 +15,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
)
|
||||
|
||||
// Note: Some websites have a user agent filter.
|
||||
|
@ -73,7 +73,7 @@ func (c *Client) PostJSON(data interface{}) (*Response, error) {
|
|||
}
|
||||
|
||||
func (c *Client) executeRequest(request *http.Request) (*Response, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[HttpClient] url=%s", c.url))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[HttpClient] url=%s", c.url))
|
||||
|
||||
client := c.buildClient()
|
||||
resp, err := client.Do(request)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2017-12-29 14:34:59.486421907 -0800 PST m=+0.007402806
|
||||
// 2017-12-31 18:38:42.071995118 -0800 PST m=+0.052826276
|
||||
|
||||
package locale
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/crypto"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/reader/date"
|
||||
|
@ -163,7 +163,7 @@ func getContent(a *atomEntry) string {
|
|||
func getHash(a *atomEntry) string {
|
||||
for _, value := range []string{a.ID, getURL(a.Links)} {
|
||||
if value != "" {
|
||||
return helper.Hash(value)
|
||||
return crypto.Hash(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,13 +9,13 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/errors"
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/http"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/reader/icon"
|
||||
"github.com/miniflux/miniflux/reader/processor"
|
||||
"github.com/miniflux/miniflux/storage"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -34,7 +34,7 @@ type Handler struct {
|
|||
|
||||
// CreateFeed fetch, parse and store a new feed.
|
||||
func (h *Handler) CreateFeed(userID, categoryID int64, url string, crawler bool) (*model.Feed, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Handler:CreateFeed] feedUrl=%s", url))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Handler:CreateFeed] feedUrl=%s", url))
|
||||
|
||||
if !h.store.CategoryExists(userID, categoryID) {
|
||||
return nil, errors.NewLocalizedError(errCategoryNotFound)
|
||||
|
@ -96,7 +96,7 @@ func (h *Handler) CreateFeed(userID, categoryID int64, url string, crawler bool)
|
|||
|
||||
// RefreshFeed fetch and update a feed if necessary.
|
||||
func (h *Handler) RefreshFeed(userID, feedID int64) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Handler:RefreshFeed] feedID=%d", feedID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Handler:RefreshFeed] feedID=%d", feedID))
|
||||
|
||||
originalFeed, err := h.store.FeedByID(userID, feedID)
|
||||
if err != nil {
|
||||
|
|
|
@ -12,12 +12,12 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/reader/atom"
|
||||
"github.com/miniflux/miniflux/reader/json"
|
||||
"github.com/miniflux/miniflux/reader/rdf"
|
||||
"github.com/miniflux/miniflux/reader/rss"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
|
||||
"golang.org/x/net/html/charset"
|
||||
)
|
||||
|
@ -33,7 +33,7 @@ const (
|
|||
|
||||
// DetectFeedFormat detect feed format from input data.
|
||||
func DetectFeedFormat(data io.Reader) string {
|
||||
defer helper.ExecutionTime(time.Now(), "[Feed:DetectFeedFormat]")
|
||||
defer timer.ExecutionTime(time.Now(), "[Feed:DetectFeedFormat]")
|
||||
|
||||
var buffer bytes.Buffer
|
||||
tee := io.TeeReader(data, &buffer)
|
||||
|
@ -67,7 +67,7 @@ func DetectFeedFormat(data io.Reader) string {
|
|||
}
|
||||
|
||||
func parseFeed(data io.Reader) (*model.Feed, error) {
|
||||
defer helper.ExecutionTime(time.Now(), "[Feed:ParseFeed]")
|
||||
defer timer.ExecutionTime(time.Now(), "[Feed:ParseFeed]")
|
||||
|
||||
var buffer bytes.Buffer
|
||||
io.Copy(&buffer, data)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/crypto"
|
||||
"github.com/miniflux/miniflux/http"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
|
@ -107,7 +107,7 @@ func downloadIcon(iconURL string) (*model.Icon, error) {
|
|||
}
|
||||
|
||||
icon := &model.Icon{
|
||||
Hash: helper.HashFromBytes(body),
|
||||
Hash: crypto.HashFromBytes(body),
|
||||
MimeType: response.ContentType,
|
||||
Content: body,
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ func parseImageDataURL(value string) (*model.Icon, error) {
|
|||
}
|
||||
|
||||
icon := &model.Icon{
|
||||
Hash: helper.HashFromBytes(blob),
|
||||
Hash: crypto.HashFromBytes(blob),
|
||||
Content: blob,
|
||||
MimeType: mimeType,
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/crypto"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/reader/date"
|
||||
|
@ -105,7 +105,7 @@ func (j *jsonItem) GetAuthor() string {
|
|||
func (j *jsonItem) GetHash() string {
|
||||
for _, value := range []string{j.ID, j.URL, j.Text + j.HTML + j.Summary} {
|
||||
if value != "" {
|
||||
return helper.Hash(value)
|
||||
return crypto.Hash(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/crypto"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/reader/sanitizer"
|
||||
"github.com/miniflux/miniflux/url"
|
||||
|
@ -73,5 +73,5 @@ func getHash(r *rdfItem) string {
|
|||
value = r.Title + r.Description
|
||||
}
|
||||
|
||||
return helper.Hash(value)
|
||||
return crypto.Hash(value)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/crypto"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/reader/date"
|
||||
|
@ -157,7 +157,7 @@ func (r *rssItem) GetAuthor() string {
|
|||
func (r *rssItem) GetHash() string {
|
||||
for _, value := range []string{r.GUID, r.GetURL()} {
|
||||
if value != "" {
|
||||
return helper.Hash(value)
|
||||
return crypto.Hash(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/errors"
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/http"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/reader/feed"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
"github.com/miniflux/miniflux/url"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
@ -27,7 +27,7 @@ var (
|
|||
|
||||
// FindSubscriptions downloads and try to find one or more subscriptions from an URL.
|
||||
func FindSubscriptions(websiteURL string) (Subscriptions, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[FindSubscriptions] url=%s", websiteURL))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[FindSubscriptions] url=%s", websiteURL))
|
||||
|
||||
client := http.NewClient(websiteURL)
|
||||
response, err := client.Get()
|
||||
|
|
|
@ -7,7 +7,7 @@ package core
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/crypto"
|
||||
"github.com/miniflux/miniflux/locale"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
|
@ -111,7 +111,7 @@ func (c *Context) OAuth2State() string {
|
|||
|
||||
// GenerateOAuth2State generate a new OAuth2 state.
|
||||
func (c *Context) GenerateOAuth2State() string {
|
||||
state := helper.GenerateRandomString(32)
|
||||
state := crypto.GenerateRandomString(32)
|
||||
c.store.UpdateSessionField(c.SessionID(), "oauth2_state", state)
|
||||
return state
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/config"
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/locale"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/server/middleware"
|
||||
"github.com/miniflux/miniflux/server/template"
|
||||
"github.com/miniflux/miniflux/storage"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/tomasen/realip"
|
||||
|
@ -36,7 +36,7 @@ type Handler struct {
|
|||
// Use is a wrapper around an HTTP handler.
|
||||
func (h *Handler) Use(f HandlerFunc) http.Handler {
|
||||
return h.middleware.WrapFunc(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer helper.ExecutionTime(time.Now(), r.URL.Path)
|
||||
defer timer.ExecutionTime(time.Now(), r.URL.Path)
|
||||
logger.Debug("[HTTP] %s %s %s", realip.RealIP(r), r.Method, r.URL.Path)
|
||||
|
||||
if r.Header.Get("X-Forwarded-Proto") == "https" {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2017-12-28 18:55:07.408638507 -0800 PST m=+0.035359093
|
||||
// 2017-12-31 18:38:42.07097409 -0800 PST m=+0.051805248
|
||||
|
||||
package template
|
||||
|
||||
|
|
|
@ -13,11 +13,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/config"
|
||||
"github.com/miniflux/miniflux/duration"
|
||||
"github.com/miniflux/miniflux/errors"
|
||||
"github.com/miniflux/miniflux/locale"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/server/route"
|
||||
"github.com/miniflux/miniflux/server/template/helper"
|
||||
"github.com/miniflux/miniflux/server/ui/filter"
|
||||
"github.com/miniflux/miniflux/url"
|
||||
|
||||
|
@ -83,7 +83,7 @@ func (e *Engine) parseAll() {
|
|||
return ts.Format("2006-01-02 15:04:05")
|
||||
},
|
||||
"elapsed": func(ts time.Time) string {
|
||||
return helper.GetElapsedTime(e.currentLocale, ts)
|
||||
return duration.ElapsedTime(e.currentLocale, ts)
|
||||
},
|
||||
"t": func(key interface{}, args ...interface{}) string {
|
||||
switch key.(type) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2017-12-28 19:08:21.190684499 -0800 PST m=+0.036802540
|
||||
// 2017-12-31 18:38:42.048775793 -0800 PST m=+0.029606951
|
||||
|
||||
package template
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/crypto"
|
||||
"github.com/miniflux/miniflux/http"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/server/core"
|
||||
|
@ -50,7 +50,7 @@ func (c *Controller) ImageProxy(ctx *core.Context, request *core.Request, respon
|
|||
}
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
etag := helper.HashFromBytes(body)
|
||||
etag := crypto.HashFromBytes(body)
|
||||
|
||||
response.Cache(resp.ContentType, etag, body, 72*time.Hour)
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
)
|
||||
|
||||
// AnotherCategoryExists checks if another category exists with the same title.
|
||||
func (s *Storage) AnotherCategoryExists(userID, categoryID int64, title string) bool {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherCategoryExists] userID=%d, categoryID=%d, title=%s", userID, categoryID, title))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherCategoryExists] userID=%d, categoryID=%d, title=%s", userID, categoryID, title))
|
||||
|
||||
var result int
|
||||
query := `SELECT count(*) as c FROM categories WHERE user_id=$1 AND id != $2 AND title=$3`
|
||||
|
@ -26,7 +26,7 @@ func (s *Storage) AnotherCategoryExists(userID, categoryID int64, title string)
|
|||
|
||||
// CategoryExists checks if the given category exists into the database.
|
||||
func (s *Storage) CategoryExists(userID, categoryID int64) bool {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryExists] userID=%d, categoryID=%d", userID, categoryID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryExists] userID=%d, categoryID=%d", userID, categoryID))
|
||||
|
||||
var result int
|
||||
query := `SELECT count(*) as c FROM categories WHERE user_id=$1 AND id=$2`
|
||||
|
@ -36,7 +36,7 @@ func (s *Storage) CategoryExists(userID, categoryID int64) bool {
|
|||
|
||||
// Category returns a category from the database.
|
||||
func (s *Storage) Category(userID, categoryID int64) (*model.Category, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Category] userID=%d, getCategory=%d", userID, categoryID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Category] userID=%d, getCategory=%d", userID, categoryID))
|
||||
var category model.Category
|
||||
|
||||
query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 AND id=$2`
|
||||
|
@ -52,7 +52,7 @@ func (s *Storage) Category(userID, categoryID int64) (*model.Category, error) {
|
|||
|
||||
// FirstCategory returns the first category for the given user.
|
||||
func (s *Storage) FirstCategory(userID int64) (*model.Category, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FirstCategory] userID=%d", userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FirstCategory] userID=%d", userID))
|
||||
var category model.Category
|
||||
|
||||
query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 ORDER BY title ASC LIMIT 1`
|
||||
|
@ -68,7 +68,7 @@ func (s *Storage) FirstCategory(userID int64) (*model.Category, error) {
|
|||
|
||||
// CategoryByTitle finds a category by the title.
|
||||
func (s *Storage) CategoryByTitle(userID int64, title string) (*model.Category, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryByTitle] userID=%d, title=%s", userID, title))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryByTitle] userID=%d, title=%s", userID, title))
|
||||
var category model.Category
|
||||
|
||||
query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 AND title=$2`
|
||||
|
@ -84,7 +84,7 @@ func (s *Storage) CategoryByTitle(userID int64, title string) (*model.Category,
|
|||
|
||||
// Categories returns all categories that belongs to the given user.
|
||||
func (s *Storage) Categories(userID int64) (model.Categories, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Categories] userID=%d", userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Categories] userID=%d", userID))
|
||||
|
||||
query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 ORDER BY title ASC`
|
||||
rows, err := s.db.Query(query, userID)
|
||||
|
@ -108,7 +108,7 @@ func (s *Storage) Categories(userID int64) (model.Categories, error) {
|
|||
|
||||
// CategoriesWithFeedCount returns all categories with the number of feeds.
|
||||
func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoriesWithFeedCount] userID=%d", userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoriesWithFeedCount] userID=%d", userID))
|
||||
query := `SELECT
|
||||
c.id, c.user_id, c.title,
|
||||
(SELECT count(*) FROM feeds WHERE feeds.category_id=c.id) AS count
|
||||
|
@ -135,7 +135,7 @@ func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error
|
|||
|
||||
// CreateCategory creates a new category.
|
||||
func (s *Storage) CreateCategory(category *model.Category) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateCategory] title=%s", category.Title))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateCategory] title=%s", category.Title))
|
||||
|
||||
query := `
|
||||
INSERT INTO categories
|
||||
|
@ -159,7 +159,7 @@ func (s *Storage) CreateCategory(category *model.Category) error {
|
|||
|
||||
// UpdateCategory updates an existing category.
|
||||
func (s *Storage) UpdateCategory(category *model.Category) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateCategory] categoryID=%d", category.ID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateCategory] categoryID=%d", category.ID))
|
||||
|
||||
query := `UPDATE categories SET title=$1 WHERE id=$2 AND user_id=$3`
|
||||
_, err := s.db.Exec(
|
||||
|
@ -178,7 +178,7 @@ func (s *Storage) UpdateCategory(category *model.Category) error {
|
|||
|
||||
// RemoveCategory deletes a category.
|
||||
func (s *Storage) RemoveCategory(userID, categoryID int64) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveCategory] userID=%d, categoryID=%d", userID, categoryID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveCategory] userID=%d, categoryID=%d", userID, categoryID))
|
||||
|
||||
result, err := s.db.Exec("DELETE FROM categories WHERE id = $1 AND user_id = $2", categoryID, userID)
|
||||
if err != nil {
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
@ -159,7 +159,7 @@ func (s *Storage) cleanupEntries(feedID int64, entryHashes []string) error {
|
|||
|
||||
// SetEntriesStatus update the status of the given list of entries.
|
||||
func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetEntriesStatus] userID=%d, entryIDs=%v, status=%s", userID, entryIDs, status))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetEntriesStatus] userID=%d, entryIDs=%v, status=%s", userID, entryIDs, status))
|
||||
|
||||
query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND id=ANY($3)`
|
||||
result, err := s.db.Exec(query, status, userID, pq.Array(entryIDs))
|
||||
|
@ -181,7 +181,7 @@ func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string
|
|||
|
||||
// ToggleBookmark toggles entry bookmark value.
|
||||
func (s *Storage) ToggleBookmark(userID int64, entryID int64) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:ToggleBookmark] userID=%d, entryID=%d", userID, entryID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:ToggleBookmark] userID=%d, entryID=%d", userID, entryID))
|
||||
|
||||
query := `UPDATE entries SET starred = NOT starred WHERE user_id=$1 AND id=$2`
|
||||
result, err := s.db.Exec(query, userID, entryID)
|
||||
|
@ -203,7 +203,7 @@ func (s *Storage) ToggleBookmark(userID int64, entryID int64) error {
|
|||
|
||||
// FlushHistory set all entries with the status "read" to "removed".
|
||||
func (s *Storage) FlushHistory(userID int64) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FlushHistory] userID=%d", userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FlushHistory] userID=%d", userID))
|
||||
|
||||
query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND status=$3 AND starred='f'`
|
||||
_, err := s.db.Exec(query, model.EntryStatusRemoved, userID, model.EntryStatusRead)
|
||||
|
|
|
@ -11,8 +11,8 @@ import (
|
|||
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
)
|
||||
|
||||
// EntryQueryBuilder builds a SQL query to fetch entries.
|
||||
|
@ -114,7 +114,7 @@ func (e *EntryQueryBuilder) WithOffset(offset int) *EntryQueryBuilder {
|
|||
|
||||
// CountEntries count the number of entries that match the condition.
|
||||
func (e *EntryQueryBuilder) CountEntries() (count int, err error) {
|
||||
defer helper.ExecutionTime(
|
||||
defer timer.ExecutionTime(
|
||||
time.Now(),
|
||||
fmt.Sprintf("[EntryQueryBuilder:CountEntries] userID=%d, feedID=%d, status=%s", e.userID, e.feedID, e.status),
|
||||
)
|
||||
|
@ -152,7 +152,7 @@ func (e *EntryQueryBuilder) GetEntry() (*model.Entry, error) {
|
|||
// GetEntries returns a list of entries that match the condition.
|
||||
func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) {
|
||||
debugStr := "[EntryQueryBuilder:GetEntries] userID=%d, feedID=%d, categoryID=%d, status=%s, order=%s, direction=%s, offset=%d, limit=%d"
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf(debugStr, e.userID, e.feedID, e.categoryID, e.status, e.order, e.direction, e.offset, e.limit))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf(debugStr, e.userID, e.feedID, e.categoryID, e.status, e.order, e.direction, e.offset, e.limit))
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
|
@ -233,7 +233,7 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) {
|
|||
// GetEntryIDs returns a list of entry IDs that match the condition.
|
||||
func (e *EntryQueryBuilder) GetEntryIDs() ([]int64, error) {
|
||||
debugStr := "[EntryQueryBuilder:GetEntryIDs] userID=%d, feedID=%d, categoryID=%d, status=%s, order=%s, direction=%s, offset=%d, limit=%d"
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf(debugStr, e.userID, e.feedID, e.categoryID, e.status, e.order, e.direction, e.offset, e.limit))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf(debugStr, e.userID, e.feedID, e.categoryID, e.status, e.order, e.direction, e.offset, e.limit))
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
|
|
|
@ -10,13 +10,13 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
)
|
||||
|
||||
// FeedExists checks if the given feed exists.
|
||||
func (s *Storage) FeedExists(userID, feedID int64) bool {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedExists] userID=%d, feedID=%d", userID, feedID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedExists] userID=%d, feedID=%d", userID, feedID))
|
||||
|
||||
var result int
|
||||
query := `SELECT count(*) as c FROM feeds WHERE user_id=$1 AND id=$2`
|
||||
|
@ -26,7 +26,7 @@ func (s *Storage) FeedExists(userID, feedID int64) bool {
|
|||
|
||||
// FeedURLExists checks if feed URL already exists.
|
||||
func (s *Storage) FeedURLExists(userID int64, feedURL string) bool {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedURLExists] userID=%d, feedURL=%s", userID, feedURL))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedURLExists] userID=%d, feedURL=%s", userID, feedURL))
|
||||
|
||||
var result int
|
||||
query := `SELECT count(*) as c FROM feeds WHERE user_id=$1 AND feed_url=$2`
|
||||
|
@ -47,7 +47,7 @@ func (s *Storage) CountFeeds(userID int64) int {
|
|||
|
||||
// Feeds returns all feeds of the given user.
|
||||
func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Feeds] userID=%d", userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Feeds] userID=%d", userID))
|
||||
|
||||
feeds := make(model.Feeds, 0)
|
||||
query := `SELECT
|
||||
|
@ -110,7 +110,7 @@ func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
|
|||
|
||||
// FeedByID returns a feed by the ID.
|
||||
func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedByID] feedID=%d", feedID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedByID] feedID=%d", feedID))
|
||||
|
||||
var feed model.Feed
|
||||
var iconID interface{}
|
||||
|
@ -165,7 +165,7 @@ func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) {
|
|||
|
||||
// CreateFeed creates a new feed.
|
||||
func (s *Storage) CreateFeed(feed *model.Feed) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateFeed] feedURL=%s", feed.FeedURL))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateFeed] feedURL=%s", feed.FeedURL))
|
||||
sql := `
|
||||
INSERT INTO feeds
|
||||
(feed_url, site_url, title, category_id, user_id, etag_header, last_modified_header, crawler)
|
||||
|
@ -202,7 +202,7 @@ func (s *Storage) CreateFeed(feed *model.Feed) error {
|
|||
|
||||
// UpdateFeed updates an existing feed.
|
||||
func (s *Storage) UpdateFeed(feed *model.Feed) (err error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateFeed] feedURL=%s", feed.FeedURL))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateFeed] feedURL=%s", feed.FeedURL))
|
||||
|
||||
query := `UPDATE feeds SET
|
||||
feed_url=$1, site_url=$2, title=$3, category_id=$4, etag_header=$5, last_modified_header=$6, checked_at=$7,
|
||||
|
@ -235,7 +235,7 @@ func (s *Storage) UpdateFeed(feed *model.Feed) (err error) {
|
|||
|
||||
// RemoveFeed removes a feed.
|
||||
func (s *Storage) RemoveFeed(userID, feedID int64) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveFeed] userID=%d, feedID=%d", userID, feedID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveFeed] userID=%d, feedID=%d", userID, feedID))
|
||||
|
||||
result, err := s.db.Exec("DELETE FROM feeds WHERE id = $1 AND user_id = $2", feedID, userID)
|
||||
if err != nil {
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
)
|
||||
|
||||
// HasIcon checks if the given feed has an icon.
|
||||
|
@ -24,7 +24,7 @@ func (s *Storage) HasIcon(feedID int64) bool {
|
|||
|
||||
// IconByID returns an icon by the ID.
|
||||
func (s *Storage) IconByID(iconID int64) (*model.Icon, error) {
|
||||
defer helper.ExecutionTime(time.Now(), "[Storage:IconByID]")
|
||||
defer timer.ExecutionTime(time.Now(), "[Storage:IconByID]")
|
||||
|
||||
var icon model.Icon
|
||||
query := `SELECT id, hash, mime_type, content FROM icons WHERE id=$1`
|
||||
|
@ -40,7 +40,7 @@ func (s *Storage) IconByID(iconID int64) (*model.Icon, error) {
|
|||
|
||||
// IconByFeedID returns a feed icon.
|
||||
func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:IconByFeedID] userID=%d, feedID=%d", userID, feedID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:IconByFeedID] userID=%d, feedID=%d", userID, feedID))
|
||||
query := `
|
||||
SELECT
|
||||
icons.id, icons.hash, icons.mime_type, icons.content
|
||||
|
@ -62,7 +62,7 @@ func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error) {
|
|||
|
||||
// IconByHash returns an icon by the hash (checksum).
|
||||
func (s *Storage) IconByHash(icon *model.Icon) error {
|
||||
defer helper.ExecutionTime(time.Now(), "[Storage:IconByHash]")
|
||||
defer timer.ExecutionTime(time.Now(), "[Storage:IconByHash]")
|
||||
|
||||
err := s.db.QueryRow(`SELECT id FROM icons WHERE hash=$1`, icon.Hash).Scan(&icon.ID)
|
||||
if err == sql.ErrNoRows {
|
||||
|
@ -76,7 +76,7 @@ func (s *Storage) IconByHash(icon *model.Icon) error {
|
|||
|
||||
// CreateIcon creates a new icon.
|
||||
func (s *Storage) CreateIcon(icon *model.Icon) error {
|
||||
defer helper.ExecutionTime(time.Now(), "[Storage:CreateIcon]")
|
||||
defer timer.ExecutionTime(time.Now(), "[Storage:CreateIcon]")
|
||||
|
||||
query := `
|
||||
INSERT INTO icons
|
||||
|
@ -101,7 +101,7 @@ func (s *Storage) CreateIcon(icon *model.Icon) error {
|
|||
|
||||
// CreateFeedIcon creates an icon and associate the icon to the given feed.
|
||||
func (s *Storage) CreateFeedIcon(feed *model.Feed, icon *model.Icon) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateFeedIcon] feedID=%d", feed.ID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateFeedIcon] feedID=%d", feed.ID))
|
||||
|
||||
err := s.IconByHash(icon)
|
||||
if err != nil {
|
||||
|
@ -125,7 +125,7 @@ func (s *Storage) CreateFeedIcon(feed *model.Feed, icon *model.Icon) error {
|
|||
|
||||
// Icons returns all icons tht belongs to a user.
|
||||
func (s *Storage) Icons(userID int64) (model.Icons, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Icons] userID=%d", userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Icons] userID=%d", userID))
|
||||
query := `
|
||||
SELECT
|
||||
icons.id, icons.hash, icons.mime_type, icons.content
|
||||
|
|
|
@ -8,15 +8,15 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
)
|
||||
|
||||
const maxParsingError = 3
|
||||
|
||||
// NewBatch returns a serie of jobs.
|
||||
func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetJobs] batchSize=%d", batchSize))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetJobs] batchSize=%d", batchSize))
|
||||
query := `
|
||||
SELECT
|
||||
id, user_id
|
||||
|
@ -29,7 +29,7 @@ func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) {
|
|||
|
||||
// NewUserBatch returns a serie of jobs but only for a given user.
|
||||
func (s *Storage) NewUserBatch(userID int64, batchSize int) (jobs model.JobList, err error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetUserJobs] batchSize=%d, userID=%d", batchSize, userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetUserJobs] batchSize=%d, userID=%d", batchSize, userID))
|
||||
query := `
|
||||
SELECT
|
||||
id, user_id
|
||||
|
|
|
@ -8,15 +8,15 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/crypto"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
)
|
||||
|
||||
// CreateSession creates a new session.
|
||||
func (s *Storage) CreateSession() (*model.Session, error) {
|
||||
session := model.Session{
|
||||
ID: helper.GenerateRandomString(32),
|
||||
Data: &model.SessionData{CSRF: helper.GenerateRandomString(64)},
|
||||
ID: crypto.GenerateRandomString(32),
|
||||
Data: &model.SessionData{CSRF: crypto.GenerateRandomString(64)},
|
||||
}
|
||||
|
||||
query := "INSERT INTO sessions (id, data) VALUES ($1, $2)"
|
||||
|
|
|
@ -8,12 +8,12 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
)
|
||||
|
||||
// Timezones returns all timezones supported by the database.
|
||||
func (s *Storage) Timezones() (map[string]string, error) {
|
||||
defer helper.ExecutionTime(time.Now(), "[Storage:Timezones]")
|
||||
defer timer.ExecutionTime(time.Now(), "[Storage:Timezones]")
|
||||
|
||||
timezones := make(map[string]string)
|
||||
query := `select name from pg_timezone_names() order by name asc`
|
||||
|
|
|
@ -13,15 +13,15 @@ import (
|
|||
|
||||
"github.com/lib/pq/hstore"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/timer"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
// SetLastLogin updates the last login date of a user.
|
||||
func (s *Storage) SetLastLogin(userID int64) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetLastLogin] userID=%d", userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetLastLogin] userID=%d", userID))
|
||||
query := "UPDATE users SET last_login_at=now() WHERE id=$1"
|
||||
_, err := s.db.Exec(query, userID)
|
||||
if err != nil {
|
||||
|
@ -33,7 +33,7 @@ func (s *Storage) SetLastLogin(userID int64) error {
|
|||
|
||||
// UserExists checks if a user exists by using the given username.
|
||||
func (s *Storage) UserExists(username string) bool {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserExists] username=%s", username))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserExists] username=%s", username))
|
||||
|
||||
var result int
|
||||
s.db.QueryRow(`SELECT count(*) as c FROM users WHERE username=LOWER($1)`, username).Scan(&result)
|
||||
|
@ -42,7 +42,7 @@ func (s *Storage) UserExists(username string) bool {
|
|||
|
||||
// AnotherUserExists checks if another user exists with the given username.
|
||||
func (s *Storage) AnotherUserExists(userID int64, username string) bool {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherUserExists] userID=%d, username=%s", userID, username))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherUserExists] userID=%d, username=%s", userID, username))
|
||||
|
||||
var result int
|
||||
s.db.QueryRow(`SELECT count(*) as c FROM users WHERE id != $1 AND username=LOWER($2)`, userID, username).Scan(&result)
|
||||
|
@ -51,7 +51,7 @@ func (s *Storage) AnotherUserExists(userID int64, username string) bool {
|
|||
|
||||
// CreateUser creates a new user.
|
||||
func (s *Storage) CreateUser(user *model.User) (err error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateUser] username=%s", user.Username))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateUser] username=%s", user.Username))
|
||||
password := ""
|
||||
extra := hstore.Hstore{Map: make(map[string]sql.NullString)}
|
||||
|
||||
|
@ -114,7 +114,7 @@ func (s *Storage) RemoveExtraField(userID int64, field string) error {
|
|||
|
||||
// UpdateUser updates a user.
|
||||
func (s *Storage) UpdateUser(user *model.User) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateUser] userID=%d", user.ID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateUser] userID=%d", user.ID))
|
||||
|
||||
if user.Password != "" {
|
||||
hashedPassword, err := hashPassword(user.Password)
|
||||
|
@ -177,7 +177,7 @@ func (s *Storage) UpdateUser(user *model.User) error {
|
|||
|
||||
// UserByID finds a user by the ID.
|
||||
func (s *Storage) UserByID(userID int64) (*model.User, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByID] userID=%d", userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByID] userID=%d", userID))
|
||||
query := `SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
||||
FROM users
|
||||
|
@ -188,7 +188,7 @@ func (s *Storage) UserByID(userID int64) (*model.User, error) {
|
|||
|
||||
// UserByUsername finds a user by the username.
|
||||
func (s *Storage) UserByUsername(username string) (*model.User, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByUsername] username=%s", username))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByUsername] username=%s", username))
|
||||
query := `SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
||||
FROM users
|
||||
|
@ -199,7 +199,7 @@ func (s *Storage) UserByUsername(username string) (*model.User, error) {
|
|||
|
||||
// UserByExtraField finds a user by an extra field value.
|
||||
func (s *Storage) UserByExtraField(field, value string) (*model.User, error) {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByExtraField] field=%s", field))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByExtraField] field=%s", field))
|
||||
query := `SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
||||
FROM users
|
||||
|
@ -241,7 +241,7 @@ func (s *Storage) fetchUser(query string, args ...interface{}) (*model.User, err
|
|||
|
||||
// RemoveUser deletes a user.
|
||||
func (s *Storage) RemoveUser(userID int64) error {
|
||||
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveUser] userID=%d", userID))
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveUser] userID=%d", userID))
|
||||
|
||||
result, err := s.db.Exec("DELETE FROM users WHERE id = $1", userID)
|
||||
if err != nil {
|
||||
|
@ -262,7 +262,7 @@ func (s *Storage) RemoveUser(userID int64) error {
|
|||
|
||||
// Users returns all users.
|
||||
func (s *Storage) Users() (model.Users, error) {
|
||||
defer helper.ExecutionTime(time.Now(), "[Storage:Users]")
|
||||
defer timer.ExecutionTime(time.Now(), "[Storage:Users]")
|
||||
query := `
|
||||
SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
||||
|
@ -309,7 +309,7 @@ func (s *Storage) Users() (model.Users, error) {
|
|||
|
||||
// CheckPassword validate the hashed password.
|
||||
func (s *Storage) CheckPassword(username, password string) error {
|
||||
defer helper.ExecutionTime(time.Now(), "[Storage:CheckPassword]")
|
||||
defer timer.ExecutionTime(time.Now(), "[Storage:CheckPassword]")
|
||||
|
||||
var hash string
|
||||
username = strings.ToLower(username)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/crypto"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
)
|
||||
|
||||
|
@ -55,7 +55,7 @@ func (s *Storage) CreateUserSession(username, userAgent, ip string) (sessionID s
|
|||
return "", fmt.Errorf("unable to fetch UserID: %v", err)
|
||||
}
|
||||
|
||||
token := helper.GenerateRandomString(64)
|
||||
token := crypto.GenerateRandomString(64)
|
||||
query := "INSERT INTO user_sessions (token, user_id, user_agent, ip) VALUES ($1, $2, $3, $4)"
|
||||
_, err = s.db.Exec(query, token, userID, userAgent, ip)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package helper
|
||||
package timer
|
||||
|
||||
import (
|
||||
"time"
|
Loading…
Reference in a new issue