sweep: fix missing view_count on HTML views, API expiry bounds, search ignoring custom slug (#33)
This commit is contained in:
@@ -167,6 +167,19 @@ func cryptorandRead(b []byte) (int, error) {
|
||||
return cryptoRead(b)
|
||||
}
|
||||
|
||||
// validExpiry reports whether an expires_in duration is in the accepted
|
||||
// window. The UI restricts presets to 1 minute - 1 year (#48); the API must
|
||||
// enforce the same bounds, otherwise negative/zero/absurd durations create
|
||||
// pastes that are born expired (or effectively permanent).
|
||||
const (
|
||||
minExpiry = time.Minute
|
||||
maxExpiry = 366 * 24 * time.Hour // 1 year (+ leap day headroom)
|
||||
)
|
||||
|
||||
func validExpiry(d time.Duration) bool {
|
||||
return d >= minExpiry && d <= maxExpiry
|
||||
}
|
||||
|
||||
func (s *Store) CreatePaste(p *Paste) (*Paste, error) {
|
||||
id := genSlug(6)
|
||||
now := time.Now().Unix()
|
||||
@@ -177,6 +190,9 @@ func (s *Store) CreatePaste(p *Paste) (*Paste, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid expires_in: %w", err)
|
||||
}
|
||||
if !validExpiry(d) {
|
||||
return nil, fmt.Errorf("expires_in must be between 1 minute and 1 year")
|
||||
}
|
||||
t := now + int64(d.Seconds())
|
||||
expiresAt = &t
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user