MCPcopy Create free account
hub / github.com/bcspragu/logseq-sync / createGraphSalt

Method createGraphSalt

cmd/server/main.go:584–605  ·  view source on GitHub ↗
(ctx context.Context, req *createGraphSaltRequest)

Source from the content-addressed store, hash-verified

582}
583
584func (s *server) createGraphSalt(ctx context.Context, req *createGraphSaltRequest) (*createGraphSaltResponse, error) {
585 _, err := s.db.Graph(ctx, db.GraphID(req.GraphUUID))
586 if db.IsNotExists(err) {
587 return nil, httperr.NotFound("graph %q wasn't found", req.GraphUUID)
588 } else if err != nil {
589 return nil, httperr.Internal("failed to load graph: %w", err)
590 }
591
592 b := make([]byte, 64)
593 if n, err := s.r.Read(b); err != nil {
594 return nil, httperr.Internal("failed to generate random bytes: %w", err)
595 } else if n != 64 {
596 return nil, httperr.Internal("expected to read 64 random bytes, read %d", n)
597 }
598
599 // Experimentally, these seem to expire about two months into the future?
600 exp := s.now().AddDate(0, 2, 0)
601 return &createGraphSaltResponse{
602 Value: base64.StdEncoding.EncodeToString(b),
603 ExpiredAt: exp.UnixMilli(),
604 }, nil
605}
606
607type getGraphSaltRequest struct {
608 GraphUUID string `json:"GraphUUID"`

Callers

nothing calls this directly

Calls 5

GraphIDTypeAlias · 0.92
IsNotExistsFunction · 0.92
NotFoundFunction · 0.92
InternalFunction · 0.92
GraphMethod · 0.65

Tested by

no test coverage detected