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

Method getFilesMeta

cmd/server/main.go:380–423  ·  view source on GitHub ↗
(ctx context.Context, req *getFilesMetaRequest)

Source from the content-addressed store, hash-verified

378}
379
380func (s *server) getFilesMeta(ctx context.Context, req *getFilesMetaRequest) (*getFilesMetaResponse, error) {
381 var fIDs []db.FileID
382 for _, f := range req.Files {
383 // TODO: Consider validating these, not sure how reliable the `e.<hex data>` is
384 // though, should dig into that a bit more.
385 fIDs = append(fIDs, db.FileID(f))
386 }
387
388 gID := db.GraphID(req.GraphUUID)
389 mds, err := s.db.BatchFileMeta(ctx, gID, fIDs)
390 if err != nil {
391 return nil, httperr.Internal("failed to load batch file meta: %w", err)
392 }
393
394 userID, err := s.getUserID(ctx)
395 if err != nil {
396 return nil, httperr.Unauthorized("failed to load user ID: %w", err)
397 }
398
399 out := []getFilesMetaResponseSingle{}
400 for id, md := range mds {
401 if md == nil {
402 // Means the requested ID wasn't found
403 out = append(out, getFilesMetaResponseSingle{
404 FilePath: string(id),
405 Error: fmt.Sprintf("not found %s/%s/%s", userID, gID, id),
406 })
407 continue
408 }
409
410 out = append(out, getFilesMetaResponseSingle{
411 FilePath: string(md.ID),
412 Checksum: string(md.Checksum),
413 LastModified: md.LastModifiedAt.UnixMilli(),
414 Size: md.Size,
415 Txid: int64(md.LastModifiedTX),
416 })
417 }
418
419 // This is a wonky thing to do, but the alternative is not using the handy-dandy
420 // toHandleFunc helper
421 resp := getFilesMetaResponse(out)
422 return &resp, nil
423}
424
425type userInfoRequest struct{}
426type userInfoResponse struct {

Callers

nothing calls this directly

Calls 7

getUserIDMethod · 0.95
FileIDTypeAlias · 0.92
GraphIDTypeAlias · 0.92
InternalFunction · 0.92
UnauthorizedFunction · 0.92
getFilesMetaResponseTypeAlias · 0.85
BatchFileMetaMethod · 0.65

Tested by

no test coverage detected