mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Add admin API for content reload
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user