Initial commit: docker compose config
Release Docker multi arch / docker (push) Has been cancelled
Test Install Script / Test Script Syntax (push) Has been cancelled
Test Install Script / Test on almalinux-10 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-10 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (root) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (default) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (root) (push) Has been cancelled
Test Install Script / Test on debian-11 (default) (push) Has been cancelled
Test Install Script / Test on debian-11 (root) (push) Has been cancelled
Test Install Script / Test on debian-12 (default) (push) Has been cancelled
Test Install Script / Test on debian-12 (root) (push) Has been cancelled
Test Install Script / Test on debian-13 (default) (push) Has been cancelled
Test Install Script / Test on debian-13 (root) (push) Has been cancelled
Test Install Script / Test on fedora-latest (default) (push) Has been cancelled
Test Install Script / Test on fedora-latest (root) (push) Has been cancelled
Test Install Script / Test on rocky-10 (default) (push) Has been cancelled
Test Install Script / Test on rocky-10 (root) (push) Has been cancelled
Test Install Script / Test on rocky-8 (default) (push) Has been cancelled
Test Install Script / Test on rocky-8 (root) (push) Has been cancelled
Test Install Script / Test on rocky-9 (default) (push) Has been cancelled
Test Install Script / Test on rocky-9 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (root) (push) Has been cancelled
Release Docker multi arch / docker (push) Has been cancelled
Test Install Script / Test Script Syntax (push) Has been cancelled
Test Install Script / Test on almalinux-10 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-10 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (root) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (default) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (root) (push) Has been cancelled
Test Install Script / Test on debian-11 (default) (push) Has been cancelled
Test Install Script / Test on debian-11 (root) (push) Has been cancelled
Test Install Script / Test on debian-12 (default) (push) Has been cancelled
Test Install Script / Test on debian-12 (root) (push) Has been cancelled
Test Install Script / Test on debian-13 (default) (push) Has been cancelled
Test Install Script / Test on debian-13 (root) (push) Has been cancelled
Test Install Script / Test on fedora-latest (default) (push) Has been cancelled
Test Install Script / Test on fedora-latest (root) (push) Has been cancelled
Test Install Script / Test on rocky-10 (default) (push) Has been cancelled
Test Install Script / Test on rocky-10 (root) (push) Has been cancelled
Test Install Script / Test on rocky-8 (default) (push) Has been cancelled
Test Install Script / Test on rocky-8 (root) (push) Has been cancelled
Test Install Script / Test on rocky-9 (default) (push) Has been cancelled
Test Install Script / Test on rocky-9 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (root) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"server/log"
|
||||
)
|
||||
|
||||
type Viewed struct {
|
||||
Hash string `json:"hash"`
|
||||
FileIndex int `json:"file_index"`
|
||||
}
|
||||
|
||||
func SetViewed(vv *Viewed) {
|
||||
var indexes map[int]struct{}
|
||||
var err error
|
||||
|
||||
buf := tdb.Get("Viewed", vv.Hash)
|
||||
if len(buf) == 0 {
|
||||
indexes = make(map[int]struct{})
|
||||
indexes[vv.FileIndex] = struct{}{}
|
||||
buf, err = json.Marshal(indexes)
|
||||
if err == nil {
|
||||
tdb.Set("Viewed", vv.Hash, buf)
|
||||
}
|
||||
} else {
|
||||
err = json.Unmarshal(buf, &indexes)
|
||||
if err == nil {
|
||||
indexes[vv.FileIndex] = struct{}{}
|
||||
buf, err = json.Marshal(indexes)
|
||||
if err == nil {
|
||||
tdb.Set("Viewed", vv.Hash, buf)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
log.TLogln("Error set viewed:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func RemViewed(vv *Viewed) {
|
||||
buf := tdb.Get("Viewed", vv.Hash)
|
||||
var indeces map[int]struct{}
|
||||
err := json.Unmarshal(buf, &indeces)
|
||||
if err == nil {
|
||||
if vv.FileIndex != -1 {
|
||||
delete(indeces, vv.FileIndex)
|
||||
buf, err = json.Marshal(indeces)
|
||||
if err == nil {
|
||||
tdb.Set("Viewed", vv.Hash, buf)
|
||||
}
|
||||
} else {
|
||||
tdb.Rem("Viewed", vv.Hash)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
log.TLogln("Error rem viewed:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func ListViewed(hash string) []*Viewed {
|
||||
var err error
|
||||
if hash != "" {
|
||||
buf := tdb.Get("Viewed", hash)
|
||||
if len(buf) == 0 {
|
||||
return []*Viewed{}
|
||||
}
|
||||
var indeces map[int]struct{}
|
||||
err = json.Unmarshal(buf, &indeces)
|
||||
if err == nil {
|
||||
var ret []*Viewed
|
||||
for i := range indeces {
|
||||
ret = append(ret, &Viewed{hash, i})
|
||||
}
|
||||
return ret
|
||||
}
|
||||
} else {
|
||||
var ret []*Viewed
|
||||
keys := tdb.List("Viewed")
|
||||
for _, key := range keys {
|
||||
buf := tdb.Get("Viewed", key)
|
||||
if len(buf) == 0 {
|
||||
return []*Viewed{}
|
||||
}
|
||||
var indeces map[int]struct{}
|
||||
err = json.Unmarshal(buf, &indeces)
|
||||
if err == nil {
|
||||
for i := range indeces {
|
||||
ret = append(ret, &Viewed{key, i})
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
log.TLogln("Error list viewed:", err)
|
||||
return []*Viewed{}
|
||||
}
|
||||
Reference in New Issue
Block a user