mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-19 11:37:51 +01:00
Add file metadata TagSharedByCount and TagSharedByGeoIP
This commit is contained in:
@@ -14,13 +14,15 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// List of defined file tags.
|
||||
// List of defined file tags. Virtual tags are generated at runtime and are read-only. They cannot be stored on the blockchain.
|
||||
const (
|
||||
TagName = 0 // Name of file.
|
||||
TagFolder = 1 // Folder name.
|
||||
TagDescription = 2 // Arbitrary description of the file. May contain hashtags.
|
||||
TagDateShared = 3 // When the file was published on the blockchain. Cannot be set manually (virtual read-only tag).
|
||||
TagDateCreated = 4 // Date when the file was originally created. This may differ from the date in the block record, which indicates when the file was shared.
|
||||
TagName = 0 // Name of file.
|
||||
TagFolder = 1 // Folder name.
|
||||
TagDescription = 2 // Arbitrary description of the file. May contain hashtags.
|
||||
TagDateShared = 3 // When the file was published on the blockchain. Virtual.
|
||||
TagDateCreated = 4 // Date when the file was originally created. This may differ from the date in the block record, which indicates when the file was shared.
|
||||
TagSharedByCount = 5 // Count of peers that share the file. Virtual.
|
||||
TagSharedByGeoIP = 6 // GeoIP data of peers that are sharing the file. CSV encoded with header "latitude,longitude". Virtual.
|
||||
)
|
||||
|
||||
// Future tags to be defined for audio/video: Artist, Album, Title, Length, Bitrate, Codec
|
||||
@@ -43,9 +45,18 @@ func (tag *BlockRecordFileTag) Text() string {
|
||||
return string(tag.Data)
|
||||
}
|
||||
|
||||
// Number returns the tags data as uint64. It returns 0 if the data cannot be decoded.
|
||||
func (tag *BlockRecordFileTag) Number() uint64 {
|
||||
if len(tag.Data) != 8 {
|
||||
return 0
|
||||
}
|
||||
|
||||
return binary.LittleEndian.Uint64(tag.Data[0:8])
|
||||
}
|
||||
|
||||
// IsVirtual checks if the tag is virtual.
|
||||
func (tag *BlockRecordFileTag) IsVirtual() bool {
|
||||
return tag.Type == TagDateShared
|
||||
return IsTagVirtual(tag.Type)
|
||||
}
|
||||
|
||||
// TagFromDate returns a tag from date
|
||||
@@ -60,3 +71,21 @@ func TagFromDate(Type uint16, Date time.Time) BlockRecordFileTag {
|
||||
func TagFromText(Type uint16, Text string) BlockRecordFileTag {
|
||||
return BlockRecordFileTag{Type: Type, Data: []byte(Text)}
|
||||
}
|
||||
|
||||
// TagFromNumber returns a tag from a number
|
||||
func TagFromNumber(Type uint16, Number uint64) BlockRecordFileTag {
|
||||
var tempDate [8]byte
|
||||
binary.LittleEndian.PutUint64(tempDate[0:8], Number)
|
||||
|
||||
return BlockRecordFileTag{Type: Type, Data: tempDate[:]}
|
||||
}
|
||||
|
||||
// IsTagVirtual checks if the tag is a virtual one.
|
||||
func IsTagVirtual(Type uint16) bool {
|
||||
switch Type {
|
||||
case TagDateShared, TagSharedByCount, TagSharedByGeoIP:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user