gfsapi

package
v0.0.0-...-2b2c7ec Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: BSD-3-Clause, MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OWN_USR = "USR"
)

Variables

View Source
var CFG *util.Fcfg = nil
View Source
var ShowLog bool = false
View Source
var SrvAddr = func() string {
	panic("the gfs server address is not initial")
}
View Source
var SrvArgs = func() string {
	return ""
}
View Source
var VerifyRunning int32

Functions

func AddFolder

func AddFolder(hs *routing.HTTPSession) routing.HResult

AddFolder adding fild folder adding folder by name tags and parent foilder id

@url,normal http get request

~/usr/api/addFolder?name=xx		GET

@arg,the normal query arguments

pid		O	the parent folder id
name	O	the file/folder name
desc	O	the file/folder desc
tags	O	the file/folder tags

//adding folder
~/usr/api/addFolder?name=aaa

@ret,code/data return

code	I	the common code.
data	I 	the added count, if return zero is meaning the folder is exists
the example
{
	"code": 0,
	"data": {
		"added": 1,
		"folder": {
			"desc": "",
			"fid": "",
			"id": "57d21be5c3666e08a4fe90d6",
			"name": "xx",
			"oid": "123",
			"owner": "USR",
			"pid": "",
			"status": "",
			"tags": [],
			"time": 0,
			"type": "folder"
		}
	}
}

@tag,file,info,update @author,cny,2016-08-24 @case,File System

func AdmHand

func AdmHand(pre string, mux *routing.SessionMux)

func AdmVerify

func AdmVerify(hs *routing.HTTPSession) routing.HResult

func DoAddFolder

func DoAddFolder(pid, name, desc string, tags []string) (util.Map, error)

func DoAdmStatus

func DoAdmStatus() (util.Map, error)

func DoAdmVerify

func DoAdmVerify() error

func DoFileDown

func DoFileDown(fid, mark, etype string, idx int, path string) error

func DoInfo

func DoInfo(fid, sha, md5, mark, pub string) (util.Map, error)

func DoListFile

func DoListFile(name, typ string, pid, ext, tags []string, reverseExt, pn, ps, retExtCount int) (util.Map, error)

func DoListInfo

func DoListInfo(fid, sha, md5, mark, pub []string) ([]util.Map, error)

func DoListInfoM

func DoListInfoM(fid, sha, md5, mark, pub []string, mode string) (util.Map, error)

func DoPubDown

func DoPubDown(pub, path string) error

func DoRedoTask

func DoRedoTask(fid, sha, md5, mark, pub string) error

func DoRemoveFile

func DoRemoveFile(fid string) (int, error)

func DoUpBase64

func DoUpBase64(buf, ctype, name, mark, tags, folder, desc string, pub, recorded int) (util.Map, error)

func DoUpF

func DoUpF(file, name, mark, tags, folder, desc string, pub, recorded int) (util.Map, error)

func DoUpdateFile

func DoUpdateFile(fid, name, desc string, tags []string) error

func DoUpdateFileParent

func DoUpdateFileParent(fids []string, pid string) error

func FilterTaskInfo

func FilterTaskInfo(fs []*gfsdb.F)

func ListFile

func ListFile(hs *routing.HTTPSession) routing.HResult

List/Search User File/Folder List/Search login user file or folder

@url,normal http get request

~/usr/api/listFile		GET

@arg,the normal query arguments

name			O	the search key for file name
type			O	the type in `file/folder` to show the file or folder
sort			O	the sort field, eg: -time
pid				O	the parent folder id
ext				O	the file ext splted by comma
not_ext			O	reverse ext query, default 0, 1 is query not in ext
tags			O	the file/folder tags to filter
pn				O	the page number begin of 1, default is 1
ps				O	the page size, default is 20
ret_ext_count	O	return the ext count

//
//list user file or folder
~/usr/api/listFile
//list user file
~/usr/api/listFile?type=file
//searhc file
~/usr/api/listFile?type=file&name=xx

@ret,code/data return

bases		O	the file base info, see upload api for deatail
files		A	the user file info.
ext_count	A	the ext count info.
the example
{
    "code": 0,
    "data": {
        "bases": {
            "57bd539dc3666e997e75f288": {
                "exec": "done",
                "ext": ".mp4",
                "filename": "xx.mp4",
                "id": "57bd539dc3666e997e75f288",
                "info": {
                    "V_json": {
                        "count": 1,
                        "files": ["www/2016-08-24/u_57bd539dc3666e997e000002_js.mp4"]
                    },
                    "V_pc": {
                        "text": "www/2016-08-24/u_57bd539dc3666e997e000002_pc.mp4"
                    },
                    "code": 0
                },
                "md5": "52757d83284ca0967bc0c9e2be342c13",
                "name": "xx.mp4",
                "pub": "HI2hmt==",
                "sha": "226cf3e82860ea778ccae40a9e424be5700249e1",
                "size": 431684,
                "status": "N",
                "time": 1.472025501957e+12,
                "type": "application/octet-stream"
            }
        },
        "files": [{
            "desc": "desc",
            "fid": "57bd539dc3666e997e75f288",
            "id": "57bd539dc3666e997e75f289",
            "name": "xx.mp4",
            "oid": "123",
            "owner": "USR",
            "pid": "57bd539ac3666e997e75f287",
            "status": "N",
            "tags": ["x", "y", "z"],
            "time": 1.472025501961e+12,
            "type": "file"
        }],
		"ext_count":[{"ext":".mp4","count":1}]
    }
}

@tag,file,info,list @author,cny,2016-08-24 @case,File System

func ParseSenderL

func ParseSenderL(cfg *util.Fcfg, sender_l []string) (map[string]FSedner, error)

func ReadBase64

func ReadBase64(path string) (string, error)

func RedoTask

func RedoTask(hs *routing.HTTPSession) routing.HResult

func RemoveFile

func RemoveFile(hs *routing.HTTPSession) routing.HResult

RemoveFile remove user file or folder Remove user file or foild by id

@url,normal http get request

~/usr/api/removeFile?fid=xx		GET

@arg,the normal query arguments

fid		R	the file/folder id splited by comma

//remove file/folder
~/usr/api/removeFile?fid=x1,x2

@ret,code/data return

code	I	the common code.
the example
{
    "code": 0,
    "data": "OK"
}

@tag,file,remove @author,cny,2016-09-09 @case,File System

func SetMock

func SetMock(hs *routing.HTTPSession) routing.HResult

func TestHtml

func TestHtml(hs *routing.HTTPSession) routing.HResult

func UpdateFile

func UpdateFile(hs *routing.HTTPSession) routing.HResult

UpdateFile update user file or folder Update user file or foild by id

@url,normal http get request

~/usr/api/updateFile?fid=xx		GET

@arg,the normal query arguments

fid		R	the file/folder id
pid		O	the file/folder parent id, using ROOT to move file/folder to root
name	O	the file/folder name
desc	O	the file/folder desc
tags	O	the file/folder tags, _NONE_ to clear all tags.

//update file/folder name
~/usr/api/updateFile?fid=xx&name=aaa

@ret,code/data return

code	I	the common code.
the example
{
    "code": 0,
    "data": "OK"
}

@tag,file,info,update @author,cny,2016-08-24 @case,File System

func UpdateFileParent

func UpdateFileParent(hs *routing.HTTPSession) routing.HResult

UpdateFileParent update user file or folder parent Update user file or foild by id

@url,normal http get request

~/usr/api/updateFile?fid=xx		GET

@arg,the normal query arguments

fids	R	the file/folder id, seperate by comma
pid		O	the file/folder parent id, using ROOT to move file/folder to root

//update file/folder parent
~/usr/api/updateFileParent?fids=xx&pid=aaa

@ret,code/data return

code	I	the common code.
the example
{
    "code": 0,
    "data": "OK"
}

@tag,file,info,update @author,cny,2017-02-06 @case,File System

Types

type DefaultSender

type DefaultSender struct {
	FH  http.Handler
	Pre string
}

func NewDefaultSender

func NewDefaultSender(fh http.Handler, pre string) *DefaultSender

func NewDefaultSender2

func NewDefaultSender2(dir, pre string) *DefaultSender

func (*DefaultSender) DoH

func (d *DefaultSender) DoH(hs *routing.HTTPSession, rf *gfsdb.F, etype string, dl bool, idx int) routing.HResult

func (*DefaultSender) Send

func (d *DefaultSender) Send(hs *routing.HTTPSession, rf *gfsdb.F, etype string, dl bool, idx int) routing.HResult

func (*DefaultSender) String

func (d *DefaultSender) String() string

type FBase

type FBase interface {
	NewFile(hs *routing.HTTPSession, filename string) (string, string)
	AbsPath(hs *routing.HTTPSession, path string) string
}

type FBaseImpl

type FBaseImpl struct {
	Base string
	Pre  string
	Subs map[string]string
}

func NewFBaseImpl

func NewFBaseImpl(base, pre string) *FBaseImpl

func (*FBaseImpl) AbsPath

func (f *FBaseImpl) AbsPath(hs *routing.HTTPSession, path string) string

func (*FBaseImpl) NewFile

func (f *FBaseImpl) NewFile(hs *routing.HTTPSession, filename string) (string, string)

func (*FBaseImpl) ParseSubs

func (f *FBaseImpl) ParseSubs(fcfg *util.Fcfg, sec string) int

type FSH

type FSH struct {
	Base    FBase
	Key     string
	Host    string
	Mode    os.FileMode
	SenderL map[string]FSedner
}

func NewFSH

func NewFSH(base FBase) *FSH

func NewFSH2

func NewFSH2(fcfg *util.Fcfg) (*FSH, error)

func (*FSH) AddSender

func (f *FSH) AddSender(alias string, s FSedner)

func (*FSH) DoSend

func (f *FSH) DoSend(hs *routing.HTTPSession, rf *gfsdb.F, etype string, dl bool, idx int) routing.HResult

func (*FSH) Down

func (f *FSH) Down(hs *routing.HTTPSession) routing.HResult

File Download(Private) Download file by file id or file mark, It always is used to download private file. it can be intercepted by filter.AttrFilter to do access control.

@url,normal http get request

~/usr/api/dload?fid=xxx		GET

@arg,the normal query arguments, at least one arguments is setted on fid/mark

fid		O	the file id
mark	O	the file mark, it is specified when file is uploaded
dl		O	force download file, not open in browser, default is 0, 1 is forced.
type	O	the extern file type, it always is used to download extern file which is created by convert task.
idx		O	the extern file index on file list, default is 0.
~/usr/api/dload?fid=xxx&type=Abc&idx=1&dl=1

@ret,normal http file stream return.

not example.

@tag,file,download,private @author,cny,2016-03-04 @case,File System

func (*FSH) Hand

func (f *FSH) Hand(pre string, mux *routing.SessionMux)

func (*FSH) Info

func (f *FSH) Info(hs *routing.HTTPSession) routing.HResult

File Info Get the file information by file id/mark/sha/md5, the file informantion container file normal info like SHA1,MD5,size and the extern file info.

@url,normal http get request

~/pub/api/info?fid=xxx		GET

@arg,the normal query arguments, at least one arguments is setted on fid/mark/sha/md5

fid		O	the file id
mark	O	the file mark, it is specified when file is uploaded
sha		O	the file SHA.
md5		O	the file MD5.
pub		O	the file pub.
~/pub/api/info?fid=xxx

@ret,code/data return

base			O	the file base information
exec			O	the converter executing information, not this field when the task is not started/done or get task status fail.
err				S	the error inforamtion when get converter task status fail.
exec.total		F	the converter task process rate
exec.detail		O	the sub task process rate
base.filename 	S	the uploaed file name
base.id			S	the file id
base.mark		A	the file mark list.
base.md5		S	the file MD5 hash
base.name		S	the special name
base.sha		S	the file SHA1 hash.
base.size		I	the file size.
base.time		I	the file upload time
base.type		S	the file mime type.
base.pub		S	the file public path.
the example
{
	"code": 0,
	"data": {
		"exec": {
			"detail": {
				"V_json": 0,
				"V_pc": 0
			},
			"total": 0
		},
		"base": {
			"exec": "running",
			"ext": ".mp4",
			"filename": "../../ffcm/xx.mp4",
			"id": "56d9a4eec3666e4e02af307f",
			"info": {},
			"mark": ["xxa"],
			"md5": "52757d83284ca0967bc0c9e2be342c13",
			"name": "../../ffcm/xx.mp4",
			"path": "www/u_56d9a4eec3666e4e02000001.mp4",
			"pub": "F/bDRYOA==",
			"sha": "226cf3e82860ea778ccae40a9e424be5700249e1",
			"size": 431684,
			"status": "N",
			"time": 1.457104110367e+12,
			"type": "application/octet-stream"
		}
	}
}

@tag,file,info @author,cny,2016-03-05 @case,File System

func (*FSH) ListInfo

func (f *FSH) ListInfo(hs *routing.HTTPSession) routing.HResult

List File Info Get the file information by file id/mark/sha/md5, the file informantion container file normal info like SHA1,MD5,size and the extern file info.

@url,normal http get request

~/pub/api/listInfo?fid=xxx,xxk		GET

@arg,the normal query arguments, at least one arguments is setted on fid/mark/sha/md5

fid		O	the file id split by comma
mark	O	the file mark split by comma, it is specified when file is uploaded
sha		O	the file SHA split by comma.
md5		O	the file MD5 split by comma.
pub		O	the file pub split by comma.
mode	O	the return data mode, default is list, it will return map value by special key value with setting mode is one of fid/mark/sha/md5/pub
~/pub/api/listInfo?fid=xxx,xx

@ret,code/data return

base			O	the file base information
exec			O	the converter executing information, not this field when the task is not started/done or get task status fail.
err				S	the error inforamtion when get converter task status fail.
exec.total		F	the converter task process rate
exec.detail		O	the sub task process rate
base.filename 	S	the uploaed file name
base.id			S	the file id
base.mark		A	the file mark list.
base.md5		S	the file MD5 hash
base.name		S	the special name
base.sha		S	the file SHA1 hash.
base.size		I	the file size.
base.time		I	the file upload time
base.type		S	the file mime type.
base.pub		S	the file public path.
the example
{
	"code": 0,
	"data": [{
		"exec": {
			"detail": {
				"V_json": 0,
				"V_pc": 0
			},
			"total": 0
		},
		"base": {
			"exec": "running",
			"ext": ".mp4",
			"filename": "../../ffcm/xx.mp4",
			"id": "56d9a4eec3666e4e02af307f",
			"info": {},
			"mark": ["xxa"],
			"md5": "52757d83284ca0967bc0c9e2be342c13",
			"name": "../../ffcm/xx.mp4",
			"path": "www/u_56d9a4eec3666e4e02000001.mp4",
			"pub": "F/bDRYOA==",
			"sha": "226cf3e82860ea778ccae40a9e424be5700249e1",
			"size": 431684,
			"status": "N",
			"time": 1.457104110367e+12,
			"type": "application/octet-stream"
		}
	}]
}

@tag,file,info,list @author,cny,2016-04-15 @case,File System

func (*FSH) Pub

func (f *FSH) Pub(hs *routing.HTTPSession) routing.HResult

File Download(Public) Download file by file public path, It always is used to download public file.

@url,normal http get request

~/<public path>/<extern type>/<file index>		GET

@arg,the normal query path,

dl		O	force download file, not open in browser, default is 0, 1 is forced.
~/F/F/bDRYOA==.jpg?dl=1

@ret,normal http file stream return.

not example.

@tag,file,download,public @author,cny,2016-03-04 @case,File System

func (*FSH) Up

func (f *FSH) Up(hs *routing.HTTPSession) routing.HResult

File Upload Upload file by multipart file or base64 body.

the argument container two path the http body and query parameter.

the body can use two mode in multipart/base64.

the http request content type must be setted as multipart/form-data when using multipart mode.

the http request content type must be setted as data contenty type, when using the base64 mode.

@url,http post

~/usr/api/uload		POST	multipart/form-data

@arg,the normal query arguments, at least one arguments is setted on fid/mark/sha/md5

pub			O	whether create public path
base64		O	using bas64 upload mode, default is 0.
name		O	specie the file name.
mark		O	add mark to file.
tags		O	add tag to file, split by comma
desc		O	the file description.
folder		O	special the folder where the fill will be stored.
recorded	O	whether record file to user file list or not, 1 is recorded, default 0
~/usr/api/uload?pub=1&name=xxx.mp4&mark=xxa

@ret,code/data return

base			O	the file base information, see the /pub/api/info for the detail.
added			I	whether the file be added.
file			O	the file information to user.
data			S	the public url.
file.id			S	the file id
file.folder		S	the folder id.
file.name		S	the special name
file.oid		S	the owner id
file.owner		S	the owner type.
file.tags		A	the file tag.
file.exec		S	the convter executing status in running/err/done, if the file type is not supported to convert return null.
file_added		I	whether the file record is added in user resource library or not.

The json example result when success.
{
	"code": 0,
	"added": 1,
	"base": {
		"exec": "running",
		"ext": ".mp4",
		"filename": "../../ffcm/xx.mp4",
		"id": "56da302dc3666e525fd7b05d",
		"info": {},
		"mark": ["xxa"],
		"md5": "52757d83284ca0967bc0c9e2be342c13",
		"name": "../../ffcm/xx.mp4",
		"path": "www/u_56da302dc3666e525f000001.mp4",
		"pub": "F/=uXWqA==",
		"sha": "226cf3e82860ea778ccae40a9e424be5700249e1",
		"size": 431684,
		"status": "N",
		"time": 1.457139757875e+12,
		"type": "application/octet-stream"
	},
	"file": {
		"desc": "desc",
		"fid": "56da302dc3666e525fd7b05d",
		"floder": "56da302ac3666e525fd7b05c",
		"id": "56da302dc3666e525fd7b05e",
		"name": "../../ffcm/xx.mp4",
		"oid": "123",
		"owner": "USR",
		"status": "N",
		"tags": ["x", "y", "z"],
		"time": 1.457139757961e+12
	},
	"data": "http://127.0.0.1:57013/F/=uXWqA=="
}

@tag,file,upload @author,cny,2016-03-05 @case,File System

User upload,delete,move file or folder.

type FSedner

type FSedner interface {
	String() string
	Send(hs *routing.HTTPSession, rf *gfsdb.F, etype string, dl bool, idx int) routing.HResult
}

type JsonSender

type JsonSender struct {
	*DefaultSender
}

func NewJsonSender

func NewJsonSender(sender *DefaultSender) *JsonSender

func (*JsonSender) Send

func (t *JsonSender) Send(hs *routing.HTTPSession, rf *gfsdb.F, etype string, dl bool, idx int) routing.HResult

func (*JsonSender) String

func (t *JsonSender) String() string

type MarkdownSender

type MarkdownSender struct {
	Base        string
	Supported   map[string]int
	MarkdownCmd string
	Errf        *template.Template
	Delay       int64
	Timeout     int64
	Running     bool
	// contains filtered or unexported fields
}

func NewMarkdownSender

func NewMarkdownSender(base, supported, mardkwon string) *MarkdownSender

func (*MarkdownSender) ParseErrf

func (m *MarkdownSender) ParseErrf(errf string) error

func (*MarkdownSender) Send

func (m *MarkdownSender) Send(hs *routing.HTTPSession, rf *gfsdb.F, etype string, dl bool, idx int) routing.HResult

func (*MarkdownSender) String

func (m *MarkdownSender) String() string

func (*MarkdownSender) TimeoutLoop

func (m *MarkdownSender) TimeoutLoop()

type TextSender

type TextSender struct {
	*DefaultSender
}

func NewTextSender

func NewTextSender(sender *DefaultSender) *TextSender

func (*TextSender) Send

func (t *TextSender) Send(hs *routing.HTTPSession, rf *gfsdb.F, etype string, dl bool, idx int) routing.HResult

func (*TextSender) String

func (t *TextSender) String() string

Jump to

Keyboard shortcuts

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