Add file metadata TagSharedByCount and TagSharedByGeoIP

This commit is contained in:
Kleissner
2021-09-29 20:20:53 +02:00
parent 2c20fa950d
commit d29fc960b6
4 changed files with 112 additions and 26 deletions

View File

@@ -10,6 +10,7 @@ package webapi
import (
"encoding/hex"
"fmt"
"math/rand"
"sync"
"time"
@@ -284,20 +285,48 @@ func createTestResult(fileType int) (file core.BlockRecordFile) {
extension = ".bin"
}
file.Tags = append(file.Tags, core.TagFromText(core.TagName, TempFileName("", extension)))
file.Tags = append(file.Tags, core.TagFromText(core.TagName, tempFileName("", extension)))
//file.Tags = append(file.Tags, core.TagFromText(core.TagFolder, "not set"))
file.Tags = append(file.Tags, core.TagFromDate(core.TagDateShared, time.Now().UTC()))
sharedByCount := uint64(rand.Intn(10))
file.Tags = append(file.Tags, core.TagFromNumber(core.TagSharedByCount, sharedByCount))
if sharedByCount > 0 {
var sharedByGeoIP string
for n := uint64(0); n < sharedByCount; n++ {
latitude, longitude := randomGeoIP()
if n > 0 {
sharedByGeoIP += "\n"
}
sharedByGeoIP += fmt.Sprintf("%.4f", latitude) + "," + fmt.Sprintf("%.4f", longitude)
}
file.Tags = append(file.Tags, core.TagFromText(core.TagSharedByGeoIP, sharedByGeoIP))
}
return
}
// TempFileName generates a temporary filename for use in testing or whatever
func TempFileName(prefix, suffix string) string {
// tempFileName generates a temporary filename for use in testing
func tempFileName(prefix, suffix string) string {
randBytes := make([]byte, 16)
rand.Read(randBytes)
return prefix + hex.EncodeToString(randBytes) + "." + suffix
}
// randomGeoIP generates random geo IP coordinates
func randomGeoIP() (latitude, longitude float32) {
// Latitude generates latitude (from -90.0 to 90.0)
latitude = rand.Float32()*180 - 90
// Longitude generates longitude (from -180 to 180)
longitude = rand.Float32()*360 - 180
return
}
// queryRecentShared returns recently shared files on the network. fileType = -1 for any.
func queryRecentShared(fileType, limit int) (files []*core.BlockRecordFile) {
for n := 0; n < limit; n++ {