filebox

package module
v0.0.0-...-1094ee4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 14 Imported by: 0

README

Filebox

Filebox could be used to provide access permission control for files, directories

You could choose filebox to satisfy below scenarios:

Scenario 1:

  • You would like to make file ~/documents/files/users.csv able to be download via link http://127.0.0.1/downloads/users.csv
  • Only Admin user able to download this file

Scenario 2:

  • You create a folder at ~/exchanges
  • Only Admin user could access files in this folder

GoDoc

Documentation

https://doc.getqor.com/plugins/filebox.html

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dir

type Dir struct {
	DirPath string
	Roles   []string
	Filebox *Filebox
}

Dir is a object to access a specific directory

func (*Dir) HasPermission

func (dir *Dir) HasPermission(ctx context.Context, mode roles.PermissionMode) bool

HasPermission used to check current user whether have permission to access directory

func (*Dir) SetPermission

func (dir *Dir) SetPermission(permission *roles.Permission) (err error)

SetPermission used to set a Permission to directory

func (*Dir) WriteFile

func (dir *Dir) WriteFile(ctx context.Context, fileName string, reader io.Reader) (file *File, err error)

WriteFile writes data to a file named by filename. If the file does not exist, WriteFile will create a new file

type File

type File struct {
	FilePath string
	Roles    []string
	Dir      *Dir
	Filebox  *Filebox
}

File is a object to access a specific file

func (*File) HasPermission

func (f *File) HasPermission(ctx context.Context, mode roles.PermissionMode) bool

HasPermission used to check current user whether have permission to access file

func (*File) Read

func (f *File) Read(ctx context.Context) (io.ReadSeeker, error)

Read will get a io reader for a specific file

func (*File) SetPermission

func (f *File) SetPermission(permission *roles.Permission) (err error)

SetPermission used to set a Permission to file

func (*File) Write

func (f *File) Write(ctx context.Context, reader io.Reader) (err error)

Write used to store reader's content to a file

type Filebox

type Filebox struct {
	BaseDir string
	Router  *xroute.Mux
	Auth    admin.Auth

	Admin *admin.Admin
	// contains filtered or unexported fields
}

Filebox is a based object contains download folder path and admin.Auth used to get current user

func New

func New(dir string) *Filebox

New a filebox struct

func (*Filebox) AccessDir

func (filebox *Filebox) AccessDir(dirPath string, roles ...string) *Dir

AccessDir will return a specific Dir object

func (*Filebox) AccessFile

func (filebox *Filebox) AccessFile(filePath string, roles ...string) *File

AccessFile will return a specific File object

func (*Filebox) Download

func (filebox *Filebox) Download(w http.ResponseWriter, req *http.Request)

Download is a handler will return a specific file

func (*Filebox) SetAuth

func (filebox *Filebox) SetAuth(auth admin.Auth)

SetAuth will set a admin.Auth struct to Filebox, used to get current user's role

Jump to

Keyboard shortcuts

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