plugins

package
v0.0.0-...-80b44f5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 10 Imported by: 0

README

Rikka Plugin System

中文版

Rikka back-end image save is powered by plugins.

fs Plugin

This is default plugin of Rikka,it save image file to server where Rikka live directly, and run a static file server for those files.

Refer to fs Plugin Doc for plugin options.

Qiniu Cloud Plugin

This plugin use Qiniu Cloud CDN to store your image.

Refer to Qiniu Plugin Doc for plugin options.

UPai Cloud Plugin

This plugin use UPai Cloud CDN to store your image.

Refer to UPai Plugin Doc.

Sina Weibo Plugin

This plugin use Sina weibo to store your image.

Refer to Weibo plugin Doc.

Tencent COS Plugin

This plugin use Cloud Object Service (COS) of Tencent to store image files.

Refer to TC-COS Plugin Doc.

Tencent CI Plugin

This plugin use Cloud Image (CI) of Tencent to store image files.

Refer to TC-CI Plugin Doc.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ArgBucketName = flag.String("bname", "", "Bucket name to store image")
	ArgBucketHost = flag.String("bhost", "", "Bucket host")
	ArgBucketPath = flag.String("bpath", "", "Where the image will be save in bucket")
)

Common flags for cloud plugins like qiniu and upai

Functions

func AcceptFile

func AcceptFile(q *SaveRequest) (fileID *api.TaskId, err error)

AcceptFile will be called when you receive a file upload request, the SaveRequest struct contains the file.

func ChangeTaskState

func ChangeTaskState(pProvidedState *api.State) error

ChangeTaskState change the state of a task. If taskID not exist, return an error.

func CheckCommonArgs

func CheckCommonArgs(needName, needHost bool)

CheckCommonArgs will check if bname and bhost is set and log their value

func CreateTask

func CreateTask(taskID string) error

CreateTask add a task to task list. If taskID already exist, return an error.

func DeleteTask

func DeleteTask(taskID string) error

DeleteTask delete a task from task list. If taskID not exist, return an error.

func GetBucketHost

func GetBucketHost() string

GetBucketHost get the host of bucket where image will be stored

func GetBucketName

func GetBucketName() string

GetBucketName get the name of bucket where image will be stored

func GetBucketPath

func GetBucketPath() string

GetBucketPath get the save path of bucket which image will be stored to

func GetState

func GetState(taskID string) (r *api.State, err error)

GetState will be called when API server receive a state request. Also be called when web server receive a view request, web server decide response a finished view html or a self-renewal html based on the return state is finished state.

func GetTaskState

func GetTaskState(taskID string) (*api.State, error)

GetTaskState get state of a task. If task not exist, return an error.

func GetURL

func GetURL(taskID string, r *http.Request, isServeTLS bool, picOp *ImageOperate) (pURL *api.URL, err error)

GetURL will be called when API server receive a url request. Also be called when web server receive a view request and GetState return a finished state. web server use the return url value to render a finished view html.

func Load

func Load(plugin RikkaPlugin)

Load load a plugin to net/http

func SubLogger

func SubLogger(prefix string) *logger.Logger

SubLogger return a new sub logger from plugins logger.

Types

type HandlerWithPattern

type HandlerWithPattern struct {
	Pattern string
	Handler http.HandlerFunc
}

HandlerWithPattern is a struct combine a http.Handler with the pattern is will server. Plugins' ExtraHandlers func return an array of this and will be added to http.handler when init plugin.

type ImageOperate

type ImageOperate struct {
	Width    int
	Height   int
	Rotate   int
	OtherArg string
}

ImageOperate stand for some operate of src image, not used now.

type RikkaPlugin

type RikkaPlugin interface {
	// Init will be called when load plugin.
	Init()
	// AcceptFile will call this.
	SaveRequestHandle(*SaveRequest) (*api.TaskId, error)
	// GetState will call this.
	StateRequestHandle(string) (*api.State, error)
	// GetURL will call this.
	URLRequestHandle(q *URLRequest) (*api.URL, error)
	// Will be added into http handler list.
	ExtraHandlers() []HandlerWithPattern
}

RikkaPlugin is plugin interface, all plugin should implement those function.

type SaveRequest

type SaveRequest struct {
	File     multipart.File
	FileSize int64
	FileExt  string
}

SaveRequest is a request that want to 'save'(actually upload) a file. Plugins' SaveRequestHandle func should accept a point of instance and return a string as taskID

type URLRequest

type URLRequest struct {
	HTTPRequest *http.Request
	TaskID      string
	PicOp       *ImageOperate
	IsServeTLS  bool // only fs plugin use this field
}

URLRequest is a request ask for photo src url of a task. Plugins' URLRequestHandle func should accept a point of instance and return a string as URL

Directories

Path Synopsis
ci
cos

Jump to

Keyboard shortcuts

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