1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package lfs
- import (
- "context"
- "gogs.io/gogs/internal/database"
- "gogs.io/gogs/internal/lfsutil"
- )
- // Store is the data layer carrier for LFS endpoints. This interface is meant to
- // abstract away and limit the exposure of the underlying data layer to the
- // handler through a thin-wrapper.
- type Store interface {
- // GetAccessTokenBySHA1 returns the access token with given SHA1. It returns
- // database.ErrAccessTokenNotExist when not found.
- GetAccessTokenBySHA1(ctx context.Context, sha1 string) (*database.AccessToken, error)
- // TouchAccessTokenByID updates the updated time of the given access token to
- // the current time.
- TouchAccessTokenByID(ctx context.Context, id int64) error
- // CreateLFSObject creates an LFS object record in database.
- CreateLFSObject(ctx context.Context, repoID int64, oid lfsutil.OID, size int64, storage lfsutil.Storage) error
- // GetLFSObjectByOID returns the LFS object with given OID. It returns
- // database.ErrLFSObjectNotExist when not found.
- GetLFSObjectByOID(ctx context.Context, repoID int64, oid lfsutil.OID) (*database.LFSObject, error)
- // GetLFSObjectsByOIDs returns LFS objects found within "oids". The returned
- // list could have fewer elements if some oids were not found.
- GetLFSObjectsByOIDs(ctx context.Context, repoID int64, oids ...lfsutil.OID) ([]*database.LFSObject, error)
- }
- type store struct{}
- // NewStore returns a new Store using the global database handle.
- func NewStore() Store {
- return &store{}
- }
- func (*store) GetAccessTokenBySHA1(ctx context.Context, sha1 string) (*database.AccessToken, error) {
- return database.Handle.AccessTokens().GetBySHA1(ctx, sha1)
- }
- func (*store) TouchAccessTokenByID(ctx context.Context, id int64) error {
- return database.Handle.AccessTokens().Touch(ctx, id)
- }
- func (*store) CreateLFSObject(ctx context.Context, repoID int64, oid lfsutil.OID, size int64, storage lfsutil.Storage) error {
- return database.Handle.LFS().CreateObject(ctx, repoID, oid, size, storage)
- }
- func (*store) GetLFSObjectByOID(ctx context.Context, repoID int64, oid lfsutil.OID) (*database.LFSObject, error) {
- return database.Handle.LFS().GetObjectByOID(ctx, repoID, oid)
- }
- func (*store) GetLFSObjectsByOIDs(ctx context.Context, repoID int64, oids ...lfsutil.OID) ([]*database.LFSObject, error) {
- return database.Handle.LFS().GetObjectsByOIDs(ctx, repoID, oids...)
- }
|