store.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package lfs
  2. import (
  3. "context"
  4. "gogs.io/gogs/internal/database"
  5. "gogs.io/gogs/internal/lfsutil"
  6. )
  7. // Store is the data layer carrier for LFS endpoints. This interface is meant to
  8. // abstract away and limit the exposure of the underlying data layer to the
  9. // handler through a thin-wrapper.
  10. type Store interface {
  11. // GetAccessTokenBySHA1 returns the access token with given SHA1. It returns
  12. // database.ErrAccessTokenNotExist when not found.
  13. GetAccessTokenBySHA1(ctx context.Context, sha1 string) (*database.AccessToken, error)
  14. // TouchAccessTokenByID updates the updated time of the given access token to
  15. // the current time.
  16. TouchAccessTokenByID(ctx context.Context, id int64) error
  17. // CreateLFSObject creates an LFS object record in database.
  18. CreateLFSObject(ctx context.Context, repoID int64, oid lfsutil.OID, size int64, storage lfsutil.Storage) error
  19. // GetLFSObjectByOID returns the LFS object with given OID. It returns
  20. // database.ErrLFSObjectNotExist when not found.
  21. GetLFSObjectByOID(ctx context.Context, repoID int64, oid lfsutil.OID) (*database.LFSObject, error)
  22. // GetLFSObjectsByOIDs returns LFS objects found within "oids". The returned
  23. // list could have fewer elements if some oids were not found.
  24. GetLFSObjectsByOIDs(ctx context.Context, repoID int64, oids ...lfsutil.OID) ([]*database.LFSObject, error)
  25. }
  26. type store struct{}
  27. // NewStore returns a new Store using the global database handle.
  28. func NewStore() Store {
  29. return &store{}
  30. }
  31. func (*store) GetAccessTokenBySHA1(ctx context.Context, sha1 string) (*database.AccessToken, error) {
  32. return database.Handle.AccessTokens().GetBySHA1(ctx, sha1)
  33. }
  34. func (*store) TouchAccessTokenByID(ctx context.Context, id int64) error {
  35. return database.Handle.AccessTokens().Touch(ctx, id)
  36. }
  37. func (*store) CreateLFSObject(ctx context.Context, repoID int64, oid lfsutil.OID, size int64, storage lfsutil.Storage) error {
  38. return database.Handle.LFS().CreateObject(ctx, repoID, oid, size, storage)
  39. }
  40. func (*store) GetLFSObjectByOID(ctx context.Context, repoID int64, oid lfsutil.OID) (*database.LFSObject, error) {
  41. return database.Handle.LFS().GetObjectByOID(ctx, repoID, oid)
  42. }
  43. func (*store) GetLFSObjectsByOIDs(ctx context.Context, repoID int64, oids ...lfsutil.OID) ([]*database.LFSObject, error) {
  44. return database.Handle.LFS().GetObjectsByOIDs(ctx, repoID, oids...)
  45. }