Admin endpoint: ENV/file admin key, --reset-admin-key, settings API wired into ratelimit/max-bytes/default-expiry/burn-window (#40)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user