client

package
v1.67.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package client provides a client for interacting with the ImageKit API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AITag

type AITag struct {
	Name       string  `json:"name"`
	Confidence float32 `json:"confidence"`
	Source     string  `json:"source"`
}

AITag represents an AI tag for a media library file.

type CreateFolderParam

type CreateFolderParam struct {
	FolderName       string `validate:"nonzero" json:"folderName"`
	ParentFolderPath string `validate:"nonzero" json:"parentFolderPath"`
}

CreateFolderParam represents parameter to create folder api

type DeleteFolderParam

type DeleteFolderParam struct {
	FolderPath string `validate:"nonzero" json:"folderPath"`
}

DeleteFolderParam represents parameter to delete folder api

type File

type File struct {
	FileID            string            `json:"fileId"`
	Name              string            `json:"name"`
	FilePath          string            `json:"filePath"`
	Type              string            `json:"type"`
	VersionInfo       map[string]string `json:"versionInfo"`
	IsPrivateFile     *bool             `json:"isPrivateFile"`
	CustomCoordinates *string           `json:"customCoordinates"`
	URL               string            `json:"url"`
	Thumbnail         string            `json:"thumbnail"`
	FileType          string            `json:"fileType"`
	Mime              string            `json:"mime"`
	Height            int               `json:"height"`
	Width             int               `json:"Width"`
	Size              uint64            `json:"size"`
	HasAlpha          bool              `json:"hasAlpha"`
	CustomMetadata    map[string]any    `json:"customMetadata,omitempty"`
	EmbeddedMetadata  map[string]any    `json:"embeddedMetadata"`
	CreatedAt         time.Time         `json:"createdAt"`
	UpdatedAt         time.Time         `json:"updatedAt"`
	Tags              []string          `json:"tags"`
	AITags            []AITag           `json:"AITags"`
}

File represents media library File details.

type FilesOrFolderParam

type FilesOrFolderParam struct {
	Path        string `json:"path,omitempty"`
	Limit       int    `json:"limit,omitempty"`
	Skip        int    `json:"skip,omitempty"`
	SearchQuery string `json:"searchQuery,omitempty"`
}

FilesOrFolderParam struct is a parameter type to ListFiles() function to search / list media library files.

type Folder

type Folder struct {
	*File
	FolderPath string `json:"folderPath"`
}

Folder represents media library Folder details.

type ImageKit

type ImageKit struct {
	Prefix        string
	UploadPrefix  string
	Timeout       int64
	UploadTimeout int64
	PrivateKey    string
	PublicKey     string
	URLEndpoint   string
	HTTPClient    *rest.Client
}

ImageKit main struct

func New

func New(ctx context.Context, params NewParams) (*ImageKit, error)

New returns ImageKit object from environment variables

func (*ImageKit) BulkJobStatus

func (ik *ImageKit) BulkJobStatus(ctx context.Context, jobID string) (*http.Response, *JobStatus, error)

BulkJobStatus retrieves the status of a bulk job by job ID.

func (*ImageKit) CreateFolder

func (ik *ImageKit) CreateFolder(ctx context.Context, param CreateFolderParam) (*http.Response, error)

CreateFolder creates a new folder in media library

func (*ImageKit) DeleteFile

func (ik *ImageKit) DeleteFile(ctx context.Context, fileID string) (*http.Response, error)

DeleteFile removes file by FileID from media library

func (*ImageKit) DeleteFolder

func (ik *ImageKit) DeleteFolder(ctx context.Context, param DeleteFolderParam) (*http.Response, error)

DeleteFolder removes the folder from media library

func (*ImageKit) File

func (ik *ImageKit) File(ctx context.Context, fileID string) (*http.Response, *File, error)

File represents media library File details.

func (*ImageKit) Files

func (ik *ImageKit) Files(ctx context.Context, params FilesOrFolderParam, includeVersion bool) (*http.Response, *[]File, error)

Files retrieves media library files. Filter options can be supplied as FilesOrFolderParam.

func (*ImageKit) Folders

func (ik *ImageKit) Folders(ctx context.Context, params FilesOrFolderParam) (*http.Response, *[]Folder, error)

Folders retrieves media library files. Filter options can be supplied as FilesOrFolderParam.

func (*ImageKit) MoveFolder

func (ik *ImageKit) MoveFolder(ctx context.Context, param MoveFolderParam) (*http.Response, *JobIDResponse, error)

MoveFolder moves given folder to new path in media library

func (*ImageKit) URL

func (ik *ImageKit) URL(params URLParam) (string, error)

URL generates url from URLParam

func (*ImageKit) Upload

func (ik *ImageKit) Upload(ctx context.Context, file io.Reader, param UploadParam) (*http.Response, *UploadResult, error)

Upload uploads an asset to a imagekit account.

The asset can be:

  • the actual data (io.Reader)
  • the Data URI (Base64 encoded), max ~60 MB (62,910,000 chars)
  • the remote FTP, HTTP or HTTPS URL address of an existing file

https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload

type JobIDResponse

type JobIDResponse struct {
	JobID string `json:"jobId"`
}

JobIDResponse respresents response struct with JobID for folder operations

type JobStatus

type JobStatus struct {
	JobID  string `json:"jobId"`
	Type   string `json:"type"`
	Status string `json:"status"`
}

JobStatus represents response Data to job status api

type MoveFolderParam

type MoveFolderParam struct {
	SourceFolderPath string `validate:"nonzero" json:"sourceFolderPath"`
	DestinationPath  string `validate:"nonzero" json:"destinationPath"`
}

MoveFolderParam represents parameter to move folder api

type NewParams

type NewParams struct {
	PrivateKey  string
	PublicKey   string
	URLEndpoint string
}

NewParams is a struct to define parameters to imagekit

type URLParam

type URLParam struct {
	Path            string
	Src             string
	URLEndpoint     string
	Signed          bool
	ExpireSeconds   int64
	QueryParameters map[string]string
}

URLParam represents parameters for generating url

type UploadParam

type UploadParam struct {
	FileName      string `json:"fileName"`
	Folder        string `json:"folder,omitempty"` // default value:  /
	Tags          string `json:"tags,omitempty"`
	IsPrivateFile *bool  `json:"isPrivateFile,omitempty"` // default: false
}

UploadParam defines upload parameters

type UploadResult

type UploadResult struct {
	FileID       string            `json:"fileId"`
	Name         string            `json:"name"`
	URL          string            `json:"url"`
	ThumbnailURL string            `json:"thumbnailUrl"`
	Height       int               `json:"height"`
	Width        int               `json:"Width"`
	Size         uint64            `json:"size"`
	FilePath     string            `json:"filePath"`
	AITags       []map[string]any  `json:"AITags"`
	VersionInfo  map[string]string `json:"versionInfo"`
}

UploadResult defines the response structure for the upload API

Jump to

Keyboard shortcuts

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