commented client functions
This commit is contained in:
parent
2f5cd563ad
commit
339dbe617f
@ -27,6 +27,7 @@ func NewClient(db db.DB, s3 s3.S3) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
// createRandomString creates a random string of length 6 to be used as a slug
|
||||
func createRandomString() string {
|
||||
s := make([]rune, 6)
|
||||
for i := range s {
|
||||
@ -35,6 +36,7 @@ func createRandomString() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// createValidSlug creates a valid slug that is not yet in use
|
||||
func (c *Client) createValidSlug(ctx context.Context) (string, error) {
|
||||
for i := 0; i < 10; i++ {
|
||||
slug := createRandomString()
|
||||
@ -52,10 +54,12 @@ func (c *Client) createValidSlug(ctx context.Context) (string, error) {
|
||||
return "", errors.New("could not create valid slug after 10 tries")
|
||||
}
|
||||
|
||||
// GetShare returns the share with the given slug, nil if not found
|
||||
func (c *Client) GetShare(ctx context.Context, slug string) (*types.Share, error) {
|
||||
return c.db.GetShare(ctx, slug)
|
||||
}
|
||||
|
||||
// CreateShare creates a new share with the given key and returns the share with the slug
|
||||
func (c *Client) CreateShare(ctx context.Context, key string) (*types.Share, error) {
|
||||
slug, err := c.createValidSlug(ctx)
|
||||
if err != nil {
|
||||
@ -84,14 +88,17 @@ func (c *Client) CreateShare(ctx context.Context, key string) (*types.Share, err
|
||||
return share, nil
|
||||
}
|
||||
|
||||
// GetObjectFromShare returns the s3 object to the given share
|
||||
func (c *Client) GetObjectFromShare(ctx context.Context, share *types.Share) (s3.ObjectReader, error) {
|
||||
return c.s3.GetObject(ctx, share.Key)
|
||||
}
|
||||
|
||||
// DeleteShare deletes the share with the given slug
|
||||
func (c *Client) DeleteShare(ctx context.Context, slug string) error {
|
||||
return c.db.DeleteShare(ctx, slug)
|
||||
}
|
||||
|
||||
// GetObjectMetadata returns the metadata of the object with the given key
|
||||
func (c *Client) GetObjectMetadata(ctx context.Context, key string) (*types.Metadata, error) {
|
||||
metadata, err := c.s3.GetObjectMetadata(ctx, key)
|
||||
if err != nil {
|
||||
@ -109,6 +116,7 @@ func (c *Client) GetObjectMetadata(ctx context.Context, key string) (*types.Meta
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
// GetAllShares returns all shares
|
||||
func (c *Client) GetAllShares(ctx context.Context) ([]*types.Share, error) {
|
||||
return c.db.GetAllShares(ctx)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user