Admin endpoint: ENV/file admin key, --reset-admin-key, settings API wired into ratelimit/max-bytes/default-expiry/burn-window (#40)
CI / test (push) Successful in 22s
CI / docker (push) Skipped

This commit is contained in:
2026-09-09 00:44:02 -05:00
parent 03600b2ed5
commit a3349b4a98
10 changed files with 562 additions and 11 deletions
+12 -1
View File
@@ -23,6 +23,17 @@ func genDeletionToken() string {
// as a new read. See the decision comment on issue #49.
const readWindowMinutes = 15
// burnViewerWindowMinutes returns the admin-tunable per-viewer dedupe window
// (#40), falling back to the 15-minute default from #49.
func burnViewerWindowMinutes() int {
if globalSettingsFn != nil {
if m := globalSettings().BurnViewerWindowMinutes; m > 0 {
return m
}
}
return readWindowMinutes
}
// timeNow is overridable in tests to inject the clock.
var timeNow = time.Now
@@ -48,7 +59,7 @@ func (s *Store) registerRead(row *PasteRow, viewerID string) (remaining *int, co
var last sql.NullInt64
s.db.QueryRow(`SELECT last_viewed FROM paste_views WHERE paste_id=? AND viewer_id=?`,
row.ID, viewerID).Scan(&last)
if last.Valid && now-last.Int64 < readWindowMinutes*60 {
if last.Valid && now-last.Int64 < int64(burnViewerWindowMinutes())*60 {
r := int(row.ReadsLimit.Int64) - row.ReadsUsed
if r < 0 {
r = 0