feat: import IMVU products into a catalog
The importer from t5de-hub's docs/imports.md: says hello to the hub with its key pair, follows the console's config (paused, rate, jobs at a time, IMVU accounts, whose sealed passwords it keeps), claims jobs, finds each product's newest revision on IMVU's CDN, converts it (originals for placeholders, no _contents.json, ProductRating from IMVU's rating), checks it by t5de-api's pack rules and uploads it to the catalog with an import token. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2b0d27831e
commit
e8578e4a71
26 files changed
+2345
-1
No files matched your search
@@ -0,0 +1,101 @@
|
||||
// Package accounts keeps the IMVU accounts' passwords the importer was given: each still sealed for its key, so
|
||||
// the file alone (without the key) reveals nothing. The hub drops its copy once the importer says it has one.
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// FileName is the store's file in the data folder.
|
||||
const FileName = "accounts.json"
|
||||
|
||||
// Account is a kept account.
|
||||
type Account struct {
|
||||
ID string `json:"id"` // the hub's
|
||||
IMVUID int64 `json:"imvuId"`
|
||||
Username string `json:"username"`
|
||||
Sealed string `json:"sealed"`
|
||||
}
|
||||
|
||||
// Store is the accounts file.
|
||||
type Store struct {
|
||||
path string
|
||||
mu sync.Mutex
|
||||
byID map[string]Account
|
||||
}
|
||||
|
||||
// Open reads the store in dir (empty if there's none yet).
|
||||
func Open(dir string) (*Store, error) {
|
||||
s := &Store{path: filepath.Join(dir, FileName), byID: map[string]Account{}}
|
||||
data, err := os.ReadFile(s.path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return s, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var list []Account
|
||||
if err := json.Unmarshal(data, &list); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, a := range list {
|
||||
s.byID[a.ID] = a
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Get returns the account with the hub's ID id.
|
||||
func (s *Store) Get(id string) (Account, bool) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
a, ok := s.byID[id]
|
||||
return a, ok
|
||||
}
|
||||
|
||||
// Put keeps an account (replacing its password, if it had one).
|
||||
func (s *Store) Put(a Account) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.byID[a.ID] = a
|
||||
return s.save()
|
||||
}
|
||||
|
||||
// Keep forgets every account not in ids (the hub no longer lists them) and returns how many it forgot.
|
||||
func (s *Store) Keep(ids map[string]bool) (int, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
n := 0
|
||||
for id := range s.byID {
|
||||
if !ids[id] {
|
||||
delete(s.byID, id)
|
||||
n++
|
||||
}
|
||||
}
|
||||
if n == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return n, s.save()
|
||||
}
|
||||
|
||||
func (s *Store) save() error {
|
||||
list := make([]Account, 0, len(s.byID))
|
||||
for _, a := range s.byID {
|
||||
list = append(list, a)
|
||||
}
|
||||
data, err := json.MarshalIndent(list, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(s.path), 0o700); err != nil {
|
||||
return err
|
||||
}
|
||||
tmp := s.path + ".tmp"
|
||||
if err := os.WriteFile(tmp, data, 0o600); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(tmp, s.path)
|
||||
}
|
||||
Reference in new issue
Block a user