Browse Source

Track download count only if there is a limit, and rewrite metadata file only when the counter should be increased

at-2021
JustAnotherArchivist 3 years ago
parent
commit
a7fd2aeffb
1 changed files with 2 additions and 4 deletions
  1. +2
    -4
      server/handlers.go

+ 2
- 4
server/handlers.go View File

@@ -663,13 +663,11 @@ func (s *Server) CheckMetadata(token, filename string, increaseDownload bool) (M
return metadata, errors.New("MaxDownloads expired.")
} else if !metadata.MaxDate.IsZero() && time.Now().After(metadata.MaxDate) {
return metadata, errors.New("MaxDate expired.")
} else {
} else if metadata.MaxDownloads != -1 && increaseDownload {
// todo(nl5887): mutex?

// update number of downloads
if increaseDownload {
metadata.Downloads++
}
metadata.Downloads++

buffer := &bytes.Buffer{}
if err := json.NewEncoder(buffer).Encode(metadata); err != nil {


Loading…
Cancel
Save