73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package catalogs
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"sync"
|
|
)
|
|
|
|
var _ = json.RawMessage{}
|
|
var _ = sync.Mutex{}
|
|
var _ = os.ReadFile
|
|
var _ = filepath.Join
|
|
|
|
//
|
|
// Minimal projection of the client's HackerPostConfig (EonBug BBS post list).
|
|
// Source: ConfigDump_v3/HackerPostConfig.json → ClientData/4229938/Configs/HackerPostConfig.json.
|
|
// The BBS panel (HackerBBSMainPanelStore) joins these rows against the PostInfos dictionary
|
|
// carried by SyncHackerJobInfo (64189208); a post the server does not list simply
|
|
// does not render, so the id set here IS the forum.
|
|
//
|
|
var (
|
|
HackerPostCatalog4229938_cacheLock sync.RWMutex
|
|
HackerPostCatalog4229938_cached = false
|
|
HackerPostCatalog4229938_entries []any
|
|
)
|
|
|
|
// LoadHackerPostCatalog4229938 loads catalog records from client config directory
|
|
func LoadHackerPostCatalog4229938(configDir string) ([]any, error) {
|
|
HackerPostCatalog4229938_cacheLock.RLock()
|
|
if HackerPostCatalog4229938_cached {
|
|
defer HackerPostCatalog4229938_cacheLock.RUnlock()
|
|
return HackerPostCatalog4229938_entries, nil
|
|
}
|
|
HackerPostCatalog4229938_cacheLock.RUnlock()
|
|
|
|
HackerPostCatalog4229938_cacheLock.Lock()
|
|
defer HackerPostCatalog4229938_cacheLock.Unlock()
|
|
if HackerPostCatalog4229938_cached { return HackerPostCatalog4229938_entries, nil }
|
|
|
|
filePath := filepath.Join(configDir, "HackerPostCatalog.json.json")
|
|
data, err := os.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var raw struct {
|
|
Records []json.RawMessage `json:"records"`
|
|
}
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var result []any
|
|
for _, item := range raw.Records {
|
|
var m map[string]any
|
|
if err := json.Unmarshal(item, &m); err == nil {
|
|
result = append(result, m)
|
|
}
|
|
}
|
|
|
|
HackerPostCatalog4229938_entries = result
|
|
HackerPostCatalog4229938_cached = true
|
|
return result, nil
|
|
}
|
|
|
|
// Every authored post id, ascending. Post order in the BBS follows this order.
|
|
func HackerPostCatalog4229938_PostIds() []uint32 {
|
|
// Catalog helper HackerPostCatalog4229938_PostIds
|
|
return nil
|
|
}
|
|
|