Add admin API for content reload

This commit is contained in:
Ilya Groshev
2026-04-28 21:22:28 +03:00
parent 9be0df4c30
commit 3fe564cb1d
36 changed files with 992 additions and 638 deletions
+19 -2
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"os"
pb "lunar-tear/server/gen/proto"
"lunar-tear/server/internal/store"
@@ -12,6 +13,16 @@ import (
"google.golang.org/protobuf/types/known/emptypb"
)
// masterDataBinPath is the canonical location of the encrypted master data
// file. The mtime of this file is folded into the version string so the
// client invalidates its cache as soon as an admin reload swaps it in.
const masterDataBinPath = "assets/release/20240404193219.bin.e"
// masterDataBaseVersion preserves the historical "yyyymmddHHMMSS" value the
// client has always seen; we suffix it with the file mtime to force a
// re-download when content changes.
const masterDataBaseVersion = "20240404193219"
type DataServiceServer struct {
pb.UnimplementedDataServiceServer
users store.UserRepository
@@ -23,9 +34,15 @@ func NewDataServiceServer(users store.UserRepository, sessions store.SessionRepo
}
func (s *DataServiceServer) GetLatestMasterDataVersion(ctx context.Context, _ *emptypb.Empty) (*pb.MasterDataGetLatestVersionResponse, error) {
log.Printf("[DataService] GetLatestMasterDataVersion")
version := masterDataBaseVersion
if info, err := os.Stat(masterDataBinPath); err == nil {
version = fmt.Sprintf("%s_%d", masterDataBaseVersion, info.ModTime().UnixMilli())
} else {
log.Printf("[DataService] stat %s: %v (falling back to base version)", masterDataBinPath, err)
}
log.Printf("[DataService] GetLatestMasterDataVersion -> %s", version)
return &pb.MasterDataGetLatestVersionResponse{
LatestMasterDataVersion: "20240404193219",
LatestMasterDataVersion: version,
}, nil
}