feat(setting): Implemented the settings administrative menu
This commit is contained in:
@@ -153,6 +153,43 @@ func RenewManifest(boxID string, seconds int64) (models.BoxManifest, error) {
|
||||
manifest.ExpiresAt = time.Now().UTC().Add(time.Duration(seconds) * time.Second)
|
||||
return manifest, writeManifestUnlocked(boxID, manifest)
|
||||
}
|
||||
|
||||
func ExpireBox(boxID string) (models.BoxManifest, error) {
|
||||
manifestMu.Lock()
|
||||
defer manifestMu.Unlock()
|
||||
|
||||
manifest, err := readManifestUnlocked(boxID)
|
||||
if err != nil {
|
||||
return manifest, err
|
||||
}
|
||||
manifest.ExpiresAt = time.Now().UTC().Add(-time.Second)
|
||||
return manifest, writeManifestUnlocked(boxID, manifest)
|
||||
}
|
||||
|
||||
func BumpBoxExpiry(boxID string, delta time.Duration) (models.BoxManifest, error) {
|
||||
manifestMu.Lock()
|
||||
defer manifestMu.Unlock()
|
||||
|
||||
manifest, err := readManifestUnlocked(boxID)
|
||||
if err != nil {
|
||||
return manifest, err
|
||||
}
|
||||
if delta <= 0 {
|
||||
return manifest, fmt.Errorf("Invalid bump duration")
|
||||
}
|
||||
if manifest.OneTimeDownload {
|
||||
return manifest, fmt.Errorf("One-time boxes cannot be extended")
|
||||
}
|
||||
|
||||
base := manifest.ExpiresAt
|
||||
now := time.Now().UTC()
|
||||
if base.IsZero() || base.Before(now) {
|
||||
base = now
|
||||
}
|
||||
manifest.ExpiresAt = base.Add(delta)
|
||||
return manifest, writeManifestUnlocked(boxID, manifest)
|
||||
}
|
||||
|
||||
func reconcileManifest(boxID string) (models.BoxManifest, error) {
|
||||
manifestMu.Lock()
|
||||
defer manifestMu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user