Google Reader: Cosmetic improvements
This commit is contained in:
parent
4b6e46d9ab
commit
0b3c3a1f28
7 changed files with 98 additions and 83 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
||||
// Copyright 2022 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.
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// Copyright 2022 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 googlereader // import "miniflux.app/googlereader"
|
||||
|
||||
import (
|
||||
|
@ -159,9 +163,11 @@ func (st StreamType) String() string {
|
|||
return st.String()
|
||||
}
|
||||
}
|
||||
|
||||
func (s Stream) String() string {
|
||||
return fmt.Sprintf("%v - '%s'", s.Type, s.ID)
|
||||
}
|
||||
|
||||
func (r RequestModifiers) String() string {
|
||||
result := fmt.Sprintf("UserID: %d\n", r.UserID)
|
||||
result += fmt.Sprintf("Streams: %d\n", len(r.Streams))
|
||||
|
@ -383,56 +389,56 @@ func (h *handler) editTag(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
||||
logger.Info("[Reader][/edit-tag][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
logger.Info("[GoogleReader][/edit-tag][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
addTags, err := getStreams(r.PostForm[ParamTagsAdd], userID)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
removeTags, err := getStreams(r.PostForm[ParamTagsRemove], userID)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
if len(addTags) == 0 && len(removeTags) == 0 {
|
||||
err = fmt.Errorf("add or/and remove tags should be supllied")
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] ", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] ", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
tags, err := checkAndSimplifyTags(addTags, removeTags)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
itemIDs, err := getItemIDs(r)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
logger.Debug("[Reader][/edit-tag] [ClientIP=%s] itemIDs: %v", clientIP, itemIDs)
|
||||
logger.Debug("[Reader][/edit-tag] [ClientIP=%s] tags: %v", clientIP, tags)
|
||||
logger.Debug("[GoogleReader][/edit-tag] [ClientIP=%s] itemIDs: %v", clientIP, itemIDs)
|
||||
logger.Debug("[GoogleReader][/edit-tag] [ClientIP=%s] tags: %v", clientIP, tags)
|
||||
builder := h.store.NewEntryQueryBuilder(userID)
|
||||
builder.WithEntryIDs(itemIDs)
|
||||
builder.WithoutStatus(model.EntryStatusRemoved)
|
||||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -465,7 +471,7 @@ func (h *handler) editTag(w http.ResponseWriter, r *http.Request) {
|
|||
if len(readEntryIDs) > 0 {
|
||||
err = h.store.SetEntriesStatus(userID, readEntryIDs, model.EntryStatusRead)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -474,7 +480,7 @@ func (h *handler) editTag(w http.ResponseWriter, r *http.Request) {
|
|||
if len(unreadEntryIDs) > 0 {
|
||||
err = h.store.SetEntriesStatus(userID, unreadEntryIDs, model.EntryStatusUnread)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -483,7 +489,7 @@ func (h *handler) editTag(w http.ResponseWriter, r *http.Request) {
|
|||
if len(unstarredEntryIDs) > 0 {
|
||||
err = h.store.SetEntriesBookmarkedState(userID, unstarredEntryIDs, true)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -492,7 +498,7 @@ func (h *handler) editTag(w http.ResponseWriter, r *http.Request) {
|
|||
if len(starredEntryIDs) > 0 {
|
||||
err = h.store.SetEntriesBookmarkedState(userID, starredEntryIDs, true)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -501,7 +507,7 @@ func (h *handler) editTag(w http.ResponseWriter, r *http.Request) {
|
|||
if len(entries) > 0 {
|
||||
settings, err := h.store.Integration(userID)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/edit-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -521,11 +527,11 @@ func (h *handler) quickAdd(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
||||
logger.Info("[Reader][/subscription/quickadd][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
logger.Info("[GoogleReader][/subscription/quickadd][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/subscription/quickadd] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/subscription/quickadd] [ClientIP=%s] %v", clientIP, err)
|
||||
json.BadRequest(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -667,11 +673,11 @@ func (h *handler) editSubscription(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
||||
logger.Info("[Reader][/subscription/edit][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
logger.Info("[GoogleReader][/subscription/edit][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/subscription/edit] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/subscription/edit] [ClientIP=%s] %v", clientIP, err)
|
||||
json.BadRequest(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -734,30 +740,30 @@ func (h *handler) streamItemContents(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
||||
logger.Info("[Reader][/stream/items/contents][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
logger.Info("[GoogleReader][/stream/items/contents][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
|
||||
if err := checkOutputFormat(w, r); err != nil {
|
||||
logger.Error("[Reader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
var user *model.User
|
||||
if user, err = h.store.UserByID(userID); err != nil {
|
||||
logger.Error("[Reader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
requestModifiers, err := getStreamFilterModifiers(r)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -768,11 +774,11 @@ func (h *handler) streamItemContents(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
itemIDs, err := getItemIDs(r)
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
logger.Debug("[Reader][/stream/items/contents] [ClientIP=%s] itemIDs: %v", clientIP, itemIDs)
|
||||
logger.Debug("[GoogleReader][/stream/items/contents] [ClientIP=%s] itemIDs: %v", clientIP, itemIDs)
|
||||
|
||||
builder := h.store.NewEntryQueryBuilder(userID)
|
||||
builder.WithoutStatus(model.EntryStatusRemoved)
|
||||
|
@ -787,7 +793,7 @@ func (h *handler) streamItemContents(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if len(entries) == 0 {
|
||||
err = fmt.Errorf("no items returned from the database")
|
||||
logger.Error("[Reader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/contents] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -872,11 +878,11 @@ func (h *handler) disableTag(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
||||
logger.Info("[Reader][/disable-tag][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
logger.Info("[GoogleReader][/disable-tag][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/disable-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/disable-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.BadRequest(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -909,11 +915,11 @@ func (h *handler) renameTag(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
||||
logger.Info("[Reader][/rename-tag][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
logger.Info("[GoogleReader][/rename-tag][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/rename-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/rename-tag] [ClientIP=%s] %v", clientIP, err)
|
||||
json.BadRequest(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -970,10 +976,10 @@ func (h *handler) tagList(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
||||
logger.Info("[Reader][tags/list][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
logger.Info("[GoogleReader][tags/list][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
|
||||
if err := checkOutputFormat(w, r); err != nil {
|
||||
logger.Error("[Reader][OutputFormat] %v", err)
|
||||
logger.Error("[GoogleReader][OutputFormat] %v", err)
|
||||
json.BadRequest(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -1002,10 +1008,10 @@ func (h *handler) subscriptionList(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
||||
logger.Info("[Reader][/subscription/list][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
logger.Info("[GoogleReader][/subscription/list][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
|
||||
if err := checkOutputFormat(w, r); err != nil {
|
||||
logger.Error("[Reader][/subscription/list] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/subscription/list] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -1033,24 +1039,24 @@ func (h *handler) subscriptionList(w http.ResponseWriter, r *http.Request) {
|
|||
func (h *handler) serve(w http.ResponseWriter, r *http.Request) {
|
||||
clientIP := request.ClientIP(r)
|
||||
dump, _ := httputil.DumpRequest(r, true)
|
||||
logger.Info("[Reader][UNKNOWN] [ClientIP=%s] URL: %s", clientIP, dump)
|
||||
logger.Info("[GoogleReader][UNKNOWN] [ClientIP=%s] URL: %s", clientIP, dump)
|
||||
logger.Error("Call to Google Reader API not implemented yet!!")
|
||||
json.OK(w, r, []string{})
|
||||
}
|
||||
|
||||
func (h *handler) userInfo(w http.ResponseWriter, r *http.Request) {
|
||||
clientIP := request.ClientIP(r)
|
||||
logger.Info("[Reader][UserInfo] [ClientIP=%s] Sending", clientIP)
|
||||
logger.Info("[GoogleReader][UserInfo] [ClientIP=%s] Sending", clientIP)
|
||||
|
||||
if err := checkOutputFormat(w, r); err != nil {
|
||||
logger.Error("[Reader][/user-info] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/user-info] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := h.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/user-info] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/user-info] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -1062,11 +1068,11 @@ func (h *handler) streamItemIDs(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
||||
logger.Debug("[Reader][/stream/items/ids][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
logger.Info("[GoogleReader][/stream/items/ids][ClientIP=%s] Incoming Request for userID #%d", clientIP, userID)
|
||||
|
||||
if err := checkOutputFormat(w, r); err != nil {
|
||||
err := fmt.Errorf("output only as json supported")
|
||||
logger.Error("[Reader][/stream/items/ids] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/ids] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -1076,10 +1082,10 @@ func (h *handler) streamItemIDs(w http.ResponseWriter, r *http.Request) {
|
|||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
logger.Info("Request Modifiers: %v", rm)
|
||||
logger.Debug("Request Modifiers: %v", rm)
|
||||
if len(rm.Streams) != 1 {
|
||||
err := fmt.Errorf("only one stream type expected")
|
||||
logger.Error("[Reader][/stream/items/ids] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/ids] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -1092,9 +1098,9 @@ func (h *handler) streamItemIDs(w http.ResponseWriter, r *http.Request) {
|
|||
h.handleReadStream(w, r, rm)
|
||||
default:
|
||||
dump, _ := httputil.DumpRequest(r, true)
|
||||
logger.Info("[Reader][/stream/items/ids] [ClientIP=%s] Unknown Stream: %s", clientIP, dump)
|
||||
logger.Info("[GoogleReader][/stream/items/ids] [ClientIP=%s] Unknown Stream: %s", clientIP, dump)
|
||||
err := fmt.Errorf("unknown stream type")
|
||||
logger.Error("[Reader][/stream/items/ids] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/ids] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -1109,7 +1115,7 @@ func (h *handler) handleReadingListStream(w http.ResponseWriter, r *http.Request
|
|||
case ReadStream:
|
||||
builder.WithStatus(model.EntryStatusUnread)
|
||||
default:
|
||||
logger.Info("[Reader][ReadingListStreamIDs][ClientIP=%s] xt filter type: %#v", clientIP, s)
|
||||
logger.Info("[GoogleReader][ReadingListStreamIDs][ClientIP=%s] xt filter type: %#v", clientIP, s)
|
||||
}
|
||||
}
|
||||
builder.WithLimit(rm.Count)
|
||||
|
@ -1117,7 +1123,7 @@ func (h *handler) handleReadingListStream(w http.ResponseWriter, r *http.Request
|
|||
builder.WithDirection(rm.SortDirection)
|
||||
rawEntryIDs, err := builder.GetEntryIDs()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/stream/items/ids#reading-list] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/ids#reading-list] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -1139,7 +1145,7 @@ func (h *handler) handleStarredStream(w http.ResponseWriter, r *http.Request, rm
|
|||
builder.WithDirection(rm.SortDirection)
|
||||
rawEntryIDs, err := builder.GetEntryIDs()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/stream/items/ids#starred] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/ids#starred] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
@ -1167,7 +1173,7 @@ func (h *handler) handleReadStream(w http.ResponseWriter, r *http.Request, rm Re
|
|||
|
||||
rawEntryIDs, err := builder.GetEntryIDs()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][/stream/items/ids#read] [ClientIP=%s] %v", clientIP, err)
|
||||
logger.Error("[GoogleReader][/stream/items/ids#read] [ClientIP=%s] %v", clientIP, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
||||
// Copyright 2022 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.
|
||||
|
||||
|
@ -34,7 +34,7 @@ func (m *middleware) clientLogin(w http.ResponseWriter, r *http.Request) {
|
|||
var integration *model.Integration
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][Login] [ClientIP=%s] Could not parse form", clientIP)
|
||||
logger.Error("[GoogleReader][Login] [ClientIP=%s] Could not parse form", clientIP)
|
||||
json.Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
|
@ -43,21 +43,21 @@ func (m *middleware) clientLogin(w http.ResponseWriter, r *http.Request) {
|
|||
output = r.Form.Get("output")
|
||||
|
||||
if username == "" || password == "" {
|
||||
logger.Error("[Reader][Login] [ClientIP=%s] Empty username or password", clientIP)
|
||||
logger.Error("[GoogleReader][Login] [ClientIP=%s] Empty username or password", clientIP)
|
||||
json.Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if err = m.store.GoogleReaderUserCheckPassword(username, password); err != nil {
|
||||
logger.Error("[Reader][Login] [ClientIP=%s] Invalid username or password: %s", clientIP, username)
|
||||
logger.Error("[GoogleReader][Login] [ClientIP=%s] Invalid username or password: %s", clientIP, username)
|
||||
json.Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
logger.Info("[Reader][Login] [ClientIP=%s] User authenticated: %s", clientIP, username)
|
||||
logger.Info("[GoogleReader][Login] [ClientIP=%s] User authenticated: %s", clientIP, username)
|
||||
|
||||
if integration, err = m.store.GoogleReaderUserGetIntegration(username); err != nil {
|
||||
logger.Error("[Reader][Login] [ClientIP=%s] Could not load integration: %s", clientIP, username)
|
||||
logger.Error("[GoogleReader][Login] [ClientIP=%s] Could not load integration: %s", clientIP, username)
|
||||
json.Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func (m *middleware) clientLogin(w http.ResponseWriter, r *http.Request) {
|
|||
m.store.SetLastLogin(integration.UserID)
|
||||
|
||||
token := getAuthToken(integration.GoogleReaderUsername, integration.GoogleReaderPassword)
|
||||
logger.Info("[Reader][Login] [ClientIP=%s] Created token: %s", clientIP, token)
|
||||
logger.Info("[GoogleReader][Login] [ClientIP=%s] Created token: %s", clientIP, token)
|
||||
result := login{SID: token, LSID: token, Auth: token}
|
||||
if output == "json" {
|
||||
json.OK(w, r, result)
|
||||
|
@ -81,17 +81,17 @@ func (m *middleware) token(w http.ResponseWriter, r *http.Request) {
|
|||
clientIP := request.ClientIP(r)
|
||||
|
||||
if !request.IsAuthenticated(r) {
|
||||
logger.Error("[Reader][Token] [ClientIP=%s] User is not authenticated", clientIP)
|
||||
logger.Error("[GoogleReader][Token] [ClientIP=%s] User is not authenticated", clientIP)
|
||||
json.Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
token := request.GoolgeReaderToken(r)
|
||||
if token == "" {
|
||||
logger.Error("[Reader][Token] [ClientIP=%s] User does not have token: %s", clientIP, request.UserID(r))
|
||||
logger.Error("[GoogleReader][Token] [ClientIP=%s] User does not have token: %s", clientIP, request.UserID(r))
|
||||
json.Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
logger.Info("[Reader][Token] [ClientIP=%s] token: %s", clientIP, token)
|
||||
logger.Info("[GoogleReader][Token] [ClientIP=%s] token: %s", clientIP, token)
|
||||
w.Header().Add("Content-Type", "text/plain; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(token))
|
||||
|
@ -118,13 +118,13 @@ func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
|
|||
if r.Method == http.MethodPost {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
logger.Error("[Reader][Login] [ClientIP=%s] Could not parse form", clientIP)
|
||||
logger.Error("[GoogleReader][Login] [ClientIP=%s] Could not parse form", clientIP)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
token = r.Form.Get("T")
|
||||
if token == "" {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] Post-Form T field is empty", clientIP)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Post-Form T field is empty", clientIP)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
|
@ -132,29 +132,29 @@ func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
|
|||
authorization := r.Header.Get("Authorization")
|
||||
|
||||
if authorization == "" {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] No token provided", clientIP)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] No token provided", clientIP)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
fields := strings.Fields(authorization)
|
||||
if len(fields) != 2 {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
if fields[0] != "GoogleLogin" {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] Authorization header does not begin with GoogleLogin - '%s'", clientIP, authorization)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Authorization header does not begin with GoogleLogin - '%s'", clientIP, authorization)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
auths := strings.Split(fields[1], "=")
|
||||
if len(auths) != 2 {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
if auths[0] != "auth" {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
|
|||
|
||||
parts := strings.Split(token, "/")
|
||||
if len(parts) != 2 {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] Auth token does not have the expected structure username/hash - '%s'", clientIP, token)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Auth token does not have the expected structure username/hash - '%s'", clientIP, token)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
|
@ -171,19 +171,19 @@ func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
|
|||
var user *model.User
|
||||
var err error
|
||||
if integration, err = m.store.GoogleReaderUserGetIntegration(parts[0]); err != nil {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] token: %s", clientIP, token)
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] No user found with the given google reader username: %s", clientIP, parts[0])
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] token: %s", clientIP, token)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] No user found with the given google reader username: %s", clientIP, parts[0])
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
expectedToken := getAuthToken(integration.GoogleReaderUsername, integration.GoogleReaderPassword)
|
||||
if expectedToken != token {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] Token does not match: %s", clientIP, token)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Token does not match: %s", clientIP, token)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
if user, err = m.store.UserByID(integration.UserID); err != nil {
|
||||
logger.Error("[Reader][Auth] [ClientIP=%s] No user found with the userID: %d", clientIP, integration.UserID)
|
||||
logger.Error("[GoogleReader][Auth] [ClientIP=%s] No user found with the userID: %d", clientIP, integration.UserID)
|
||||
Unauthorized(w, r)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
||||
// Copyright 2022 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.
|
||||
|
||||
|
|
|
@ -223,6 +223,7 @@
|
|||
"error.unlink_account_without_password": "Sinun on määritettävä salasana, muuten et voi kirjautua uudelleen.",
|
||||
"error.duplicate_linked_account": "There is already someone associated with this provider!",
|
||||
"error.duplicate_fever_username": "There is already someone else with the same Fever username!",
|
||||
"error.duplicate_googlereader_username": "On jo joku muu, jolla on sama Google-syötteenlukijan käyttäjätunnus!",
|
||||
"error.pocket_request_token": "Unable to fetch request token from Pocket!",
|
||||
"error.pocket_access_token": "Unable to fetch access token from Pocket!",
|
||||
"error.category_already_exists": "Kategoria on jo olemassa. ",
|
||||
|
@ -308,6 +309,10 @@
|
|||
"form.integration.fever_username": "Fever-käyttäjätunnus",
|
||||
"form.integration.fever_password": "Fever-salasana",
|
||||
"form.integration.fever_endpoint": "Fever API -päätepiste:",
|
||||
"form.integration.googlereader_activate": "Aktivoi Google Reader API",
|
||||
"form.integration.googlereader_username": "Google-lukijan käyttäjätunnus",
|
||||
"form.integration.googlereader_password": "Google-lukijan salasana",
|
||||
"form.integration.googlereader_endpoint": "Google Reader API -päätepiste:",
|
||||
"form.integration.pinboard_activate": "Tallenna artikkelit Pinboardiin",
|
||||
"form.integration.pinboard_token": "Pinboard API-tunnus",
|
||||
"form.integration.pinboard_tags": "Pinboard-tagit",
|
||||
|
|
|
@ -312,7 +312,7 @@
|
|||
"form.integration.googlereader_activate": "Activer l'API de Google Reader",
|
||||
"form.integration.googlereader_username": "Nom d'utilisateur pour l'API de Google Reader",
|
||||
"form.integration.googlereader_password": "Mot de passe pour l'API de Google Reader",
|
||||
"form.integration.googlereader_endpoint": "Point de terminaison de l'API Google Reader:",
|
||||
"form.integration.googlereader_endpoint": "Point de terminaison de l'API Google Reader :",
|
||||
"form.integration.pinboard_activate": "Sauvegarder les articles vers Pinboard",
|
||||
"form.integration.pinboard_token": "Jeton de sécurité de l'API de Pinboard",
|
||||
"form.integration.pinboard_tags": "Libellés de Pinboard",
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"miniflux.app/model"
|
||||
)
|
||||
|
||||
// HasDuplicateFeverUsername checks if another user have the same fever username.
|
||||
// HasDuplicateFeverUsername checks if another user have the same Fever username.
|
||||
func (s *Storage) HasDuplicateFeverUsername(userID int64, feverUsername string) bool {
|
||||
query := `SELECT true FROM integrations WHERE user_id != $1 AND fever_username=$2`
|
||||
var result bool
|
||||
|
@ -20,7 +20,7 @@ func (s *Storage) HasDuplicateFeverUsername(userID int64, feverUsername string)
|
|||
return result
|
||||
}
|
||||
|
||||
// HasDuplicateGoogleReaderUsername checks if another user have the same googlereader username.
|
||||
// HasDuplicateGoogleReaderUsername checks if another user have the same Google Reader username.
|
||||
func (s *Storage) HasDuplicateGoogleReaderUsername(userID int64, googleReaderUsername string) bool {
|
||||
query := `SELECT true FROM integrations WHERE user_id != $1 AND googlereader_username=$2`
|
||||
var result bool
|
||||
|
@ -33,8 +33,10 @@ func (s *Storage) UserByFeverToken(token string) (*model.User, error) {
|
|||
query := `
|
||||
SELECT
|
||||
users.id, users.is_admin, users.timezone
|
||||
FROM users
|
||||
LEFT JOIN integrations ON integrations.user_id=users.id
|
||||
FROM
|
||||
users
|
||||
LEFT JOIN
|
||||
integrations ON integrations.user_id=users.id
|
||||
WHERE
|
||||
integrations.fever_enabled='t' AND lower(integrations.fever_token)=lower($1)
|
||||
`
|
||||
|
@ -45,20 +47,21 @@ func (s *Storage) UserByFeverToken(token string) (*model.User, error) {
|
|||
case err == sql.ErrNoRows:
|
||||
return nil, nil
|
||||
case err != nil:
|
||||
return nil, fmt.Errorf("unable to fetch user: %v", err)
|
||||
return nil, fmt.Errorf("store: unable to fetch user: %v", err)
|
||||
default:
|
||||
return &user, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GoogleReaderUserCheckPassword validates the hashed password.
|
||||
// GoogleReaderUserCheckPassword validates the Google Reader hashed password.
|
||||
func (s *Storage) GoogleReaderUserCheckPassword(username, password string) error {
|
||||
var hash string
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
googlereader_password
|
||||
FROM integrations
|
||||
FROM
|
||||
integrations
|
||||
WHERE
|
||||
integrations.googlereader_enabled='t' AND integrations.googlereader_username=$1
|
||||
`
|
||||
|
@ -77,7 +80,7 @@ func (s *Storage) GoogleReaderUserCheckPassword(username, password string) error
|
|||
return nil
|
||||
}
|
||||
|
||||
// GoogleReaderUserGetIntegration returns part of the google reader parts of the integration struct.
|
||||
// GoogleReaderUserGetIntegration returns part of the Google Reader parts of the integration struct.
|
||||
func (s *Storage) GoogleReaderUserGetIntegration(username string) (*model.Integration, error) {
|
||||
var integration model.Integration
|
||||
|
||||
|
@ -87,7 +90,8 @@ func (s *Storage) GoogleReaderUserGetIntegration(username string) (*model.Integr
|
|||
googlereader_enabled,
|
||||
googlereader_username,
|
||||
googlereader_password
|
||||
FROM integrations
|
||||
FROM
|
||||
integrations
|
||||
WHERE
|
||||
integrations.googlereader_enabled='t' AND integrations.googlereader_username=$1
|
||||
`
|
||||
|
|
Loading…
Add table
Reference in a new issue