store.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // AuthorizeRepositoryAccess returns true if the user has as good as desired
  26. // access mode to the repository.
  27. AuthorizeRepositoryAccess(ctx context.Context, userID, repoID int64, desired database.AccessMode, opts database.AccessModeOptions) bool
  28. // GetRepositoryByName returns the repository with given owner and name. It
  29. // returns database.ErrRepoNotExist when not found.
  30. GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*database.Repository, error)
  31. }
  32. type store struct{}
  33. // NewStore returns a new Store using the global database handle.
  34. func NewStore() Store {
  35. return &store{}
  36. }
  37. func (*store) GetAccessTokenBySHA1(ctx context.Context, sha1 string) (*database.AccessToken, error) {
  38. return database.Handle.AccessTokens().GetBySHA1(ctx, sha1)
  39. }
  40. func (*store) TouchAccessTokenByID(ctx context.Context, id int64) error {
  41. return database.Handle.AccessTokens().Touch(ctx, id)
  42. }
  43. func (*store) CreateLFSObject(ctx context.Context, repoID int64, oid lfsutil.OID, size int64, storage lfsutil.Storage) error {
  44. return database.Handle.LFS().CreateObject(ctx, repoID, oid, size, storage)
  45. }
  46. func (*store) GetLFSObjectByOID(ctx context.Context, repoID int64, oid lfsutil.OID) (*database.LFSObject, error) {
  47. return database.Handle.LFS().GetObjectByOID(ctx, repoID, oid)
  48. }
  49. func (*store) GetLFSObjectsByOIDs(ctx context.Context, repoID int64, oids ...lfsutil.OID) ([]*database.LFSObject, error) {
  50. return database.Handle.LFS().GetObjectsByOIDs(ctx, repoID, oids...)
  51. }
  52. func (*store) AuthorizeRepositoryAccess(ctx context.Context, userID, repoID int64, desired database.AccessMode, opts database.AccessModeOptions) bool {
  53. return database.Handle.Permissions().Authorize(ctx, userID, repoID, desired, opts)
  54. }
  55. func (*store) GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*database.Repository, error) {
  56. return database.Handle.Repositories().GetByName(ctx, ownerID, name)
  57. }