8000 [pull] main from miniflux:main by pull[bot] · Pull Request #279 · suhaoGe/miniflux · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions internal/cli/cleanup_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
)

func runCleanupTasks(store *storage.Storage) {
nbSessions := store.CleanOldSessions(config.Opts.CleanupRemoveSessionsInterval())
nbUserSessions := store.CleanOldUserSessions(config.Opts.CleanupRemoveSessionsInterval())
slog.Info("Sessions cleanup completed",
slog.Int64("application_sessions_removed", nbSessions),
slog.Int64("user_sessions_removed", nbUserSessions),
)
if nbWebSessions, err := store.CleanOldWebSessions(config.Opts.CleanupRemoveSessionsInterval()); err != nil {
slog.Error("Unable to clean old web sessions", slog.Any("error", err))
} else {
slog.Info("Sessions cleanup completed",
slog.Int64("web_sessions_removed", nbWebSessions),
)
}

startTime := time.Now()
if rowsAffected, err := store.ArchiveEntries(model.EntryStatusRead, config.Opts.CleanupArchiveReadInterval(), config.Opts.CleanupArchiveBatchSize()); err != nil {
Expand Down
26 changes: 26 additions & 0 deletions internal/database/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,4 +1431,30 @@ var migrations = [...]func(tx *sql.Tx) error{
_, err = tx.Exec(`ALTER TABLE feeds ADD COLUMN ignore_entry_updates bool default 'f'`)
return err
},
func(tx *sql.Tx) (err error) {
_, err = tx.Exec(`
DROP TABLE IF EXISTS sessions;
DROP TABLE IF EXISTS user_sessions;

CREATE TABLE web_sessions (
id text not null,
secret_hash bytea not null,
user_id int references users(id) on delete cascade,
created_at timestamp with time zone not null default now(),
user_agent text not null default '',
ip inet,
state jsonb not null default '{}'::jsonb,
primary key (id),
check (jsonb_typeof(state) = 'object')
);

CREATE INDEX web_sessions_user_id_idx
ON web_sessions (user_id)
WHERE user_id IS NOT NULL;

CREATE INDEX web_sessions_created_at_idx
ON web_sessions (created_at);
`)
return err
},
}
51 changes: 0 additions & 51 deletions internal/http/cookie/cookie.go

This file was deleted.

109 changes: 26 additions & 83 deletions internal/http/request/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package request // import "miniflux.app/v2/internal/http/request"

import (
"net/http"
"strconv"
"time"

"miniflux.app/v2/internal/model"
)
Expand All @@ -21,26 +19,16 @@ const (
UserTimezoneContextKey
IsAdminUserContextKey
IsAuthenticatedContextKey
UserSessionTokenContextKey
UserLanguageContextKey
UserThemeContextKey
SessionIDContextKey
CSRFContextKey
OAuth2StateContextKey
OAuth2CodeVerifierContextKey
FlashMessageContextKey
FlashErrorMessageContextKey
LastForceRefreshContextKey
WebSessionContextKey
ClientIPContextKey
GoogleReaderTokenKey
WebAuthnDataContextKey
)

// WebAuthnSessionData returns WebAuthn session data from the request context, or nil if absent.
func WebAuthnSessionData(r *http.Request) *model.WebAuthnSession {
if v := r.Context().Value(WebAuthnDataContextKey); v != nil {
if value, valid := v.(model.WebAuthnSession); valid {
return &value
// WebSession returns the current web session from the request context, if present.
func WebSession(r *http.Request) *model.WebSession {
if v := r.Context().Value(WebSessionContextKey); v != nil {
if value, valid := v.(*model.WebSession); valid {
return value
}
}
return nil
Expand All @@ -58,12 +46,30 @@ func IsAdminUser(r *http.Request) bool {

// IsAuthenticated reports whether the user is authenticated.
func IsAuthenticated(r *http.Request) bool {
return getContextBoolValue(r, IsAuthenticatedContextKey)
if getContextBoolValue(r, IsAuthenticatedContextKey) {
return true
}

if session := WebSession(r); session != nil {
return session.IsAuthenticated()
}

return false
}

// UserID returns the logged-in user's ID from the request context.
func UserID(r *http.Request) int64 {
return getContextInt64Value(r, UserIDContextKey)
if userID := getContextInt64Value(r, UserIDContextKey); userID != 0 {
return userID
}

if session := WebSession(r); session != nil {
if id, ok := session.UserID(); ok {
return id
}
}

return 0
}

// UserName returns the logged-in user's username, or "unknown" when unset.
Expand All @@ -84,69 +90,6 @@ func UserTimezone(r *http.Request) string {
return value
}

// UserLanguage returns the user's locale, defaulting to "en_US" when unset.
func UserLanguage(r *http.Request) string {
language := getContextStringValue(r, UserLanguageContextKey)
if language == "" {
language = "en_US"
}
return language
}

// UserTheme returns the user's theme, defaulting to "system_serif" when unset.
func UserTheme(r *http.Request) string {
theme := getContextStringValue(r, UserThemeContextKey)
if theme == "" {
theme = "system_serif"
}
return theme
}

// CSRF returns the CSRF token from the request context.
func CSRF(r *http.Request) string {
return getContextStringValue(r, CSRFContextKey)
}

// SessionID returns the current session ID from the request context.
func SessionID(r *http.Request) string {
return getContextStringValue(r, SessionIDContextKey)
}

// UserSessionToken returns the current user session token from the request context.
func UserSessionToken(r *http.Request) string {
return getContextStringValue(r, UserSessionTokenContextKey)
}

// OAuth2State returns the OAuth2 state value from the request context.
func OAuth2State(r *http.Request) string {
return getContextStringValue(r, OAuth2StateContextKey)
}

// OAuth2CodeVerifier returns the OAuth2 PKCE code verifier from the request context.
func OAuth2CodeVerifier(r *http.Request) string {
return getContextStringValue(r, OAuth2CodeVerifierContextKey)
}

// FlashMessage returns the flash message from the request context, if any.
func FlashMessage(r *http.Request) string {
return getContextStringValue(r, FlashMessageContextKey)
}

// FlashErrorMessage returns the flash error message from the request context, if any.
func FlashErrorMessage(r *http.Request) string {
return getContextStringValue(r, FlashErrorMessageContextKey)
}

// LastForceRefresh returns the last force refresh timestamp from the request context.
func LastForceRefresh(r *http.Request) time.Time {
jsonStringValue := getContextStringValue(r, LastForceRefreshContextKey)
timestamp, err := strconv.ParseInt(jsonStringValue, 10, 64)
6A1F if err != nil {
return time.Time{}
}
return time.Unix(timestamp, 0)
}

// ClientIP returns the client IP address stored in the request context.
func ClientIP(r *http.Request) string {
return getContextStringValue(r, ClientIPContextKey)
Expand Down
Loading
Loading
0