image

package
v0.0.0-...-d22e7c3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

README

Image Usecase

The usecase for image is only 2(at least for now):

  1. Upload Image
  2. Download Image

Upload Image

There are two mode for uploading image:

  1. Public
  2. Private

We want to have different mode, because not all image is public. We might want to store a sensitive image related to customer.

Private Image

When uploading the private image, metadata attribute is saved alongside the image. In this metadata, contains the access and priviledge that belong to spesific user. This to make sure that private image can only be accessed by the rightful users.

Download Image

Download image usecase exists to serve private image. Image that belong to one user and is private should not visible to other users. So we need to check whether the downloader is the rightful user.

Temporary Path

To be added

Object Storage Signed URL

To be added

TODO

  • Image manipulation(resize)
  • Image compression

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Image

type Image struct {
	Proto        string
	Host         string
	FilePath     string
	DownloadPath string
	DownloadLink string
}

Image struct

type Usecase

type Usecase struct {
	// contains filtered or unexported fields
}

Usecase of image

func New

func New(privateStorage *objectstorage.Storage, imageRepo imageRepository, objStoragePath *objstoragepath.ObjectStoragePath) (*Usecase, error)

New image usecase

func (*Usecase) Download

func (u *Usecase) Download(ctx context.Context, imagePath string, userHash userentity.Hash, admin bool) ([]byte, error)

Download image download usecase never use a public storage as public storage being served via CDN and local filesystem in LOCAL to download temporary filepath, use format: temporary:{id}

func (*Usecase) FilePathFromTemporaryPath

func (u *Usecase) FilePathFromTemporaryPath(ctx context.Context, tempPath string) (string, error)

FilePathFromTemporaryPath path return the true filepath from temporary endpoint

func (*Usecase) GenerateSignedURL

func (u *Usecase) GenerateSignedURL(ctx context.Context, filePath string, expiry time.Duration) (string, error)

GenerateSignedURL for generating temporary path to download image directly from object storage provider this method is different from temporary as we are not serving the download from our server

func (*Usecase) GenerateTemporaryPath

func (u *Usecase) GenerateTemporaryPath(ctx context.Context, filepath string, expiryTime time.Duration) (string, error)

GenerateTemporaryPath for generating path to download image but with disposable image path this is useful for secure image handling

func (*Usecase) GenerateTemporaryURL

func (u *Usecase) GenerateTemporaryURL(ctx context.Context, filePath string, expiry time.Duration) (string, error)

GenerateTemporaryURL directly from backend instad of using object-storage url, this will use image-proxy url

func (*Usecase) GetImageFilePath

func (u *Usecase) GetImageFilePath(ctx context.Context, imagePath string) (prefix, filePath string, err error)

GetImageFilePath normalize and return the true image file path needed by backend

func (*Usecase) Upload

func (u *Usecase) Upload(ctx context.Context, reader io.Reader, info imageentity.FileInfo) (Image, error)

Upload image

Directories

Path Synopsis
Package image is a generated GoMock package.
Package image is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL