api

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: 0 Imported by: 0

README

Rikka API Introduction

中文版

Note: API was added into Rikka after version 0.1.0

BTW,Rikka disable CORS by default, if you need use api in other domain, please add -corsAllowOrigin '*' argument on start (available after version 0.8.0).

Upload

Path

POST /api/upload

Params

Content-type muse be multipart/form-data.

  • uploadFile":the image file
  • password":Rikka password
  • from":request source, value must be api
Return Value

A JSON contains task ID if you request successfully, then you can get task state and final image url use the ID.

{
    "TaskID": "2016-09-02-908463234"
}

A error JSON when request failed, error message format can be found in the end of article.

Get Task State

Path

GET /api/state/<TaskID>

Params

None

Return Value

A state JSON like bellow if query successfully.

{
    "TaskID": "2016-09-02-908463234",
    "State": "state name",
    "StateCode": 1,
    "Description": "state Description"
}

A error JSON when query failed, error message format can be found in the end of article.

Get Image URL

Path

GET /api/url/<TaskID>

Params

None

Return Value

A JSON contains image URL like bellow if query successfully.

{
    "URL": "http://127.0.0.1/files/2016-09-02-908463234"
}

A error JSON when query failed, error message format can be found in the end of article.

Error JSON format

If API request error, return error JSON like bellow:

{
    "Error": "error message"
}

Documentation

Index

Constants

View Source
const (
	// Version of Rikka
	Version = "0.8.0"

	// FormKeyFile is file field name when upload image
	FormKeyFile = "uploadFile"
	// FormKeyPWD is password field name when upload image
	FormKeyPWD = "password"
	// FormKeyFrom is from field name when upload image
	FormKeyFrom = "from"

	// FromWebsite is a value of FromKeyFrom, means request comes from website
	FromWebsite = "website"
	// FromAPI is a value of FromKeyFrom, means request comes from REST API
	FromAPI = "api"
)
View Source
const (
	UploadPath = "/api/upload"
	StatePath  = "/api/state/"
	URLPath    = "/api/url/"
)

API Path

View Source
const (
	StateError     = "error"
	StateErrorCode = -1

	StateFinish            = "finish"
	StateFinishCode        = 0
	StateFinishDescription = "file upload task finish"

	StateCreate            = "just created"
	StateCreateCode        = 1
	StateCreateDescription = "the task is created just now, waiting for next operate"
)

Built-in state code and state str, description. Must be used in finish and error state.

Variables

View Source
var (
	// Upload errors
	ErrPwdErrMsg         = "error password"
	InvalidFromArgErrMsg = "from argument can only be website or api"
	NotAImgFileErrMsg    = "the file you upload is not an image"

	// Task errors
	TaskNotExistErrMsg     = "task not exist"
	TaskAlreadyExistErrMsg = "task already exist"
	TaskNotFinishErrMsg    = "task is not finished"
)

API error messages

Functions

This section is empty.

Types

type Error

type Error struct {
	Error string
}

Error struct used to build json from error string.

type State

type State struct {
	TaskID      string
	StateCode   int
	State       string
	Description string
}

State shows a state of task.

func BuildCreateState

func BuildCreateState(taskID string) *State

BuildCreateState build a standard just-create state from taskID.

func BuildErrorState

func BuildErrorState(taskID string, description string) *State

BuildErrorState build a standard error state from taskID and description.

func BuildFinishState

func BuildFinishState(taskID string) *State

BuildFinishState build a standard finished state from taskID.

type TaskId

type TaskId struct {
	TaskId string
}

TaskId struct used to build json from taskID.

type URL

type URL struct {
	URL string
}

URL struct used to build json from error URL.

Jump to

Keyboard shortcuts

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