server

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Unlicense Imports: 48 Imported by: 3

Documentation

Index

Constants

View Source
const (
	STORE_DIR_NAME                 = "files"
	LOG_DIR_NAME                   = "log"
	DATA_DIR_NAME                  = "data"
	CONF_DIR_NAME                  = "conf"
	STATIC_DIR_NAME                = "static"
	CONST_STAT_FILE_COUNT_KEY      = "fileCount"
	CONST_BIG_UPLOAD_PATH_SUFFIX   = "/big/upload/"
	CONST_STAT_FILE_TOTAL_SIZE_KEY = "totalSize"
	CONST_Md5_ERROR_FILE_NAME      = "errors.md5"
	CONST_Md5_QUEUE_FILE_NAME      = "queue.md5"
	CONST_FILE_Md5_FILE_NAME       = "files.md5"
	CONST_REMOME_Md5_FILE_NAME     = "removes.md5"
	CONST_SMALL_FILE_SIZE          = 1024 * 1024
	CONST_MESSAGE_CLUSTER_IP       = "Can only be called by the cluster ip or 127.0.0.1 or admin_ips(cfg.json),current ip:%s"
)

Variables

View Source
var (
	FileName string

	DOCKER_DIR                  = ""
	STORE_DIR                   = STORE_DIR_NAME
	CONF_DIR                    = CONF_DIR_NAME
	LOG_DIR                     = LOG_DIR_NAME
	DATA_DIR                    = DATA_DIR_NAME
	STATIC_DIR                  = STATIC_DIR_NAME
	LARGE_DIR_NAME              = "haystack"
	LARGE_DIR                   = STORE_DIR + "/haystack"
	CONST_LEVELDB_FILE_NAME     = DATA_DIR + "/fileserver.db"
	CONST_LOG_LEVELDB_FILE_NAME = DATA_DIR + "/log.db"
	CONST_STAT_FILE_NAME        = DATA_DIR + "/stat.json"
	CONST_CONF_FILE_NAME        = CONF_DIR + "/cfg.json"
	CONST_SERVER_CRT_FILE_NAME  = CONF_DIR + "/server.crt"
	CONST_SERVER_KEY_FILE_NAME  = CONF_DIR + "/server.key"
	CONST_SEARCH_FILE_NAME      = DATA_DIR + "/search.txt"
	CONST_UPLOAD_COUNTER_KEY    = "__CONST_UPLOAD_COUNTER_KEY__"
)
View Source
var (
	VERSION     string
	BUILD_TIME  string
	GO_VERSION  string
	GIT_VERSION string
)
View Source
var CONST_QUEUE_SIZE = 10000

Functions

func InitServer

func InitServer()

func ParseConfig

func ParseConfig(filePath string)

func Start

func Start()

Types

type FileInfo

type FileInfo struct {
	Name      string   `json:"name"`
	ReName    string   `json:"rename"`
	Path      string   `json:"path"`
	Md5       string   `json:"md5"`
	Size      int64    `json:"size"`
	Peers     []string `json:"peers"`
	Scene     string   `json:"scene"`
	TimeStamp int64    `json:"timeStamp"`
	OffSet    int64    `json:"offset"`
	// contains filtered or unexported fields
}

type FileInfoResult

type FileInfoResult struct {
	Name    string `json:"name"`
	Md5     string `json:"md5"`
	Path    string `json:"path"`
	Size    int64  `json:"size"`
	ModTime int64  `json:"mtime"`
	IsDir   bool   `json:"is_dir"`
}

type FileLog

type FileLog struct {
	FileInfo *FileInfo
	FileName string
}

type FileResult

type FileResult struct {
	Url     string `json:"url"`
	Md5     string `json:"md5"`
	Path    string `json:"path"`
	Domain  string `json:"domain"`
	Scene   string `json:"scene"`
	Size    int64  `json:"size"`
	ModTime int64  `json:"mtime"`
	//Just for Compatibility
	Scenes  string `json:"scenes"`
	RetMsg  string `json:"retmsg"`
	RetCode int    `json:"retcode"`
	Src     string `json:"src"`
}

type GlobalConfig

type GlobalConfig struct {
	Addr                 string   `json:"addr"`
	Peers                []string `json:"peers"`
	EnableHttps          bool     `json:"enable_https"`
	Group                string   `json:"group"`
	RenameFile           bool     `json:"rename_file"`
	ShowDir              bool     `json:"show_dir"`
	Extensions           []string `json:"extensions"`
	RefreshInterval      int      `json:"refresh_interval"`
	EnableWebUpload      bool     `json:"enable_web_upload"`
	DownloadDomain       string   `json:"download_domain"`
	EnableCustomPath     bool     `json:"enable_custom_path"`
	Scenes               []string `json:"scenes"`
	AlarmReceivers       []string `json:"alarm_receivers"`
	DefaultScene         string   `json:"default_scene"`
	Mail                 Mail     `json:"mail"`
	AlarmUrl             string   `json:"alarm_url"`
	DownloadUseToken     bool     `json:"download_use_token"`
	DownloadTokenExpire  int      `json:"download_token_expire"`
	QueueSize            int      `json:"queue_size"`
	AutoRepair           bool     `json:"auto_repair"`
	Host                 string   `json:"host"`
	FileSumArithmetic    string   `json:"file_sum_arithmetic"`
	PeerId               string   `json:"peer_id"`
	SupportGroupManage   bool     `json:"support_group_manage"`
	AdminIps             []string `json:"admin_ips"`
	AdminKey             string   `json:"admin_key"`
	EnableMergeSmallFile bool     `json:"enable_merge_small_file"`
	EnableMigrate        bool     `json:"enable_migrate"`
	EnableDistinctFile   bool     `json:"enable_distinct_file"`
	ReadOnly             bool     `json:"read_only"`
	EnableCrossOrigin    bool     `json:"enable_cross_origin"`
	EnableGoogleAuth     bool     `json:"enable_google_auth"`
	AuthUrl              string   `json:"auth_url"`
	EnableDownloadAuth   bool     `json:"enable_download_auth"`
	DefaultDownload      bool     `json:"default_download"`
	EnableTus            bool     `json:"enable_tus"`
	SyncTimeout          int64    `json:"sync_timeout"`
	EnableFsNotify       bool     `json:"enable_fsnotify"`
	EnableDiskCache      bool     `json:"enable_disk_cache"`
	ConnectTimeout       bool     `json:"connect_timeout"`
	ReadTimeout          int      `json:"read_timeout"`
	WriteTimeout         int      `json:"write_timeout"`
	IdleTimeout          int      `json:"idle_timeout"`
	ReadHeaderTimeout    int      `json:"read_header_timeout"`
	SyncWorker           int      `json:"sync_worker"`
	UploadWorker         int      `json:"upload_worker"`
	UploadQueueSize      int      `json:"upload_queue_size"`
	RetryCount           int      `json:"retry_count"`
	SyncDelay            int64    `json:"sync_delay"`
	WatchChanSize        int      `json:"watch_chan_size"`
	ImageMaxWidth        int      `json:"image_max_width"`
	ImageMaxHeight       int      `json:"image_max_height"`
	Proxies              []Proxy  `json:"proxies"`
	EnablePprofDebug     bool     `json:"enable_pprof_debug"`
}

func Config

func Config() *GlobalConfig

type HttpHandler

type HttpHandler struct{}

func (HttpHandler) ServeHTTP

func (HttpHandler) ServeHTTP(res http.ResponseWriter, req *http.Request)

type HttpProxyHandler

type HttpProxyHandler struct {
	Proxy Proxy
}

func (*HttpProxyHandler) ServeHTTP

func (h *HttpProxyHandler) ServeHTTP(res http.ResponseWriter, req *http.Request)

type JsonResult

type JsonResult struct {
	Message string      `json:"message"`
	Status  string      `json:"status"`
	Data    interface{} `json:"data"`
}

type Mail

type Mail struct {
	User     string `json:"user"`
	Password string `json:"password"`
	Host     string `json:"host"`
}

type Proxy

type Proxy struct {
	Dir    string `json:"dir"`
	Addr   string `json:"addr"`
	Origin string `json:"origin"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) AppendToDownloadQueue

func (c *Server) AppendToDownloadQueue(fileInfo *FileInfo)

func (*Server) AppendToQueue

func (c *Server) AppendToQueue(fileInfo *FileInfo)

func (*Server) AutoRepair

func (c *Server) AutoRepair(forceRepair bool)

func (*Server) BackUp

func (c *Server) BackUp(w http.ResponseWriter, r *http.Request)

func (*Server) BackUpMetaDataByDate

func (c *Server) BackUpMetaDataByDate(date string)

func (*Server) BenchMark

func (c *Server) BenchMark(w http.ResponseWriter, r *http.Request)

func (*Server) BuildFileResult

func (c *Server) BuildFileResult(fileInfo *FileInfo, r *http.Request) FileResult

func (*Server) CheckAuth

func (c *Server) CheckAuth(w http.ResponseWriter, r *http.Request) bool

func (*Server) CheckClusterStatus

func (c *Server) CheckClusterStatus()

func (*Server) CheckDownloadAuth

func (c *Server) CheckDownloadAuth(w http.ResponseWriter, r *http.Request) (bool, error)

func (*Server) CheckFileAndSendToPeer

func (c *Server) CheckFileAndSendToPeer(date string, filename string, isForceUpload bool)

func (*Server) CheckFileExist

func (c *Server) CheckFileExist(w http.ResponseWriter, r *http.Request)

func (*Server) CheckFileExistByInfo

func (c *Server) CheckFileExistByInfo(md5s string, fileInfo *FileInfo) bool

func (*Server) CheckFilesExist

func (c *Server) CheckFilesExist(w http.ResponseWriter, r *http.Request)

func (*Server) CheckScene

func (c *Server) CheckScene(scene string) (bool, error)

func (*Server) CleanAndBackUp

func (c *Server) CleanAndBackUp()

func (*Server) CleanLogLevelDBByDate

func (c *Server) CleanLogLevelDBByDate(date string, filename string)

func (*Server) ConsumerDownLoad

func (c *Server) ConsumerDownLoad()

func (*Server) ConsumerLog

func (c *Server) ConsumerLog()

func (*Server) ConsumerPostToPeer

func (c *Server) ConsumerPostToPeer()

func (*Server) ConsumerUpload

func (c *Server) ConsumerUpload()

func (*Server) CrossOrigin

func (c *Server) CrossOrigin(w http.ResponseWriter, r *http.Request)

func (*Server) Download

func (c *Server) Download(w http.ResponseWriter, r *http.Request)

func (*Server) DownloadFileToResponse

func (c *Server) DownloadFileToResponse(url string, w http.ResponseWriter, r *http.Request)

func (*Server) DownloadFromPeer

func (c *Server) DownloadFromPeer(peer string, fileInfo *FileInfo)

func (*Server) DownloadNormalFileByURI

func (c *Server) DownloadNormalFileByURI(w http.ResponseWriter, r *http.Request) (bool, error)

func (*Server) DownloadNotFound

func (c *Server) DownloadNotFound(w http.ResponseWriter, r *http.Request)

func (*Server) DownloadSmallFileByURI

func (c *Server) DownloadSmallFileByURI(w http.ResponseWriter, r *http.Request) (bool, error)

func (*Server) FormatStatInfo

func (c *Server) FormatStatInfo()

func (*Server) GenGoogleCode

func (c *Server) GenGoogleCode(w http.ResponseWriter, r *http.Request)

func (*Server) GenGoogleSecret

func (c *Server) GenGoogleSecret(w http.ResponseWriter, r *http.Request)

func (*Server) GetClusterNotPermitMessage

func (c *Server) GetClusterNotPermitMessage(r *http.Request) string

func (*Server) GetFileInfo

func (c *Server) GetFileInfo(w http.ResponseWriter, r *http.Request)

func (*Server) GetFileInfoFromLevelDB

func (c *Server) GetFileInfoFromLevelDB(key string) (*FileInfo, error)

func (*Server) GetFilePathByInfo

func (c *Server) GetFilePathByInfo(fileInfo *FileInfo, withDocker bool) string

func (*Server) GetFilePathFromRequest

func (c *Server) GetFilePathFromRequest(w http.ResponseWriter, r *http.Request) (string, string)

func (*Server) GetMd5File

func (c *Server) GetMd5File(w http.ResponseWriter, r *http.Request)

func (*Server) GetMd5sByDate

func (c *Server) GetMd5sByDate(date string, filename string) (mapset.Set, error)

func (*Server) GetMd5sForWeb

func (c *Server) GetMd5sForWeb(w http.ResponseWriter, r *http.Request)

func (*Server) GetMd5sMapByDate

func (c *Server) GetMd5sMapByDate(date string, filename string) (*goutil.CommonMap, error)

func (*Server) GetServerURI

func (c *Server) GetServerURI(r *http.Request) string

func (*Server) GetSmallFileByURI

func (c *Server) GetSmallFileByURI(w http.ResponseWriter, r *http.Request) ([]byte, bool, error)

func (*Server) GetStat

func (c *Server) GetStat() []StatDateFileInfo

func (*Server) HeartBeat

func (c *Server) HeartBeat(w http.ResponseWriter, r *http.Request)

func (*Server) Index

func (c *Server) Index(w http.ResponseWriter, r *http.Request)

func (*Server) IsExistFromLevelDB

func (c *Server) IsExistFromLevelDB(key string, db *leveldb.DB) (bool, error)

func (*Server) IsPeer

func (c *Server) IsPeer(r *http.Request) bool

func (*Server) ListDir

func (c *Server) ListDir(w http.ResponseWriter, r *http.Request)

func (*Server) LoadFileInfoByDate

func (c *Server) LoadFileInfoByDate(date string, filename string) (mapset.Set, error)

func (*Server) LoadQueueSendToPeer

func (c *Server) LoadQueueSendToPeer()

func (*Server) LoadSearchDict

func (c *Server) LoadSearchDict()

func (*Server) NotPermit

func (c *Server) NotPermit(w http.ResponseWriter, r *http.Request)

func (*Server) ParseSmallFile

func (c *Server) ParseSmallFile(filename string) (string, int64, int, error)

func (*Server) ReceiveMd5s

func (c *Server) ReceiveMd5s(w http.ResponseWriter, r *http.Request)

func (*Server) RegisterExit

func (c *Server) RegisterExit()

func (*Server) Reload

func (c *Server) Reload(w http.ResponseWriter, r *http.Request)

func (*Server) RemoveDownloading

func (c *Server) RemoveDownloading()

func (*Server) RemoveEmptyDir

func (c *Server) RemoveEmptyDir(w http.ResponseWriter, r *http.Request)

func (*Server) RemoveFile

func (c *Server) RemoveFile(w http.ResponseWriter, r *http.Request)

func (*Server) RemoveKeyFromLevelDB

func (c *Server) RemoveKeyFromLevelDB(key string, db *leveldb.DB) error

func (*Server) Repair

func (c *Server) Repair(w http.ResponseWriter, r *http.Request)

func (*Server) RepairFileInfo

func (c *Server) RepairFileInfo(w http.ResponseWriter, r *http.Request)

func (*Server) RepairFileInfoFromFile

func (c *Server) RepairFileInfoFromFile()

func (*Server) RepairStatByDate

func (c *Server) RepairStatByDate(date string) StatDateFileInfo

func (*Server) RepairStatWeb

func (c *Server) RepairStatWeb(w http.ResponseWriter, r *http.Request)

func (*Server) Report

func (c *Server) Report(w http.ResponseWriter, r *http.Request)

func (*Server) ResizeImage

func (c *Server) ResizeImage(w http.ResponseWriter, fullpath string, width, height uint)

func (*Server) ResizeImageByBytes

func (c *Server) ResizeImageByBytes(w http.ResponseWriter, data []byte, width, height uint)

func (*Server) SaveFileInfoToLevelDB

func (c *Server) SaveFileInfoToLevelDB(key string, fileInfo *FileInfo, db *leveldb.DB) (*FileInfo, error)

func (*Server) SaveFileMd5Log

func (c *Server) SaveFileMd5Log(fileInfo *FileInfo, filename string)

func (*Server) SaveSearchDict

func (c *Server) SaveSearchDict()

func (*Server) SaveSmallFile

func (c *Server) SaveSmallFile(fileInfo *FileInfo) error

func (*Server) SaveStat

func (c *Server) SaveStat()

func (*Server) SaveUploadFile

func (c *Server) SaveUploadFile(file multipart.File, header *multipart.FileHeader, fileInfo *FileInfo, r *http.Request) (*FileInfo, error)

func (*Server) Search

func (c *Server) Search(w http.ResponseWriter, r *http.Request)

Notice: performance is poor,just for low capacity,but low memory , if you want to high performance,use searchMap for search,but memory ....

func (*Server) SearchDict

func (c *Server) SearchDict(kw string) []FileInfo

func (*Server) SendToMail

func (c *Server) SendToMail(to, subject, body, mailtype string) error

func (*Server) SetDownloadHeader

func (c *Server) SetDownloadHeader(w http.ResponseWriter, r *http.Request)

func (*Server) Start

func (c *Server) Start()

func (*Server) Stat

func (c *Server) Stat(w http.ResponseWriter, r *http.Request)

func (*Server) Status

func (c *Server) Status(w http.ResponseWriter, r *http.Request)

func (*Server) Sync

func (c *Server) Sync(w http.ResponseWriter, r *http.Request)

func (*Server) SyncFileInfo

func (c *Server) SyncFileInfo(w http.ResponseWriter, r *http.Request)

func (*Server) TrimFileNameSpecialChar added in v1.4.5

func (c *Server) TrimFileNameSpecialChar(str string) string

func (*Server) Upload

func (c *Server) Upload(w http.ResponseWriter, r *http.Request)

func (*Server) VerifyGoogleCode

func (c *Server) VerifyGoogleCode(secret string, code string, discrepancy int64) bool

func (*Server) WatchFilesChange

func (c *Server) WatchFilesChange()

type StatDateFileInfo

type StatDateFileInfo struct {
	Date      string `json:"date"`
	TotalSize int64  `json:"totalSize"`
	FileCount int64  `json:"fileCount"`
}

type WrapReqResp

type WrapReqResp struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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