Documentation ¶
Overview ¶
Package sharenixlib contains the core functionalities of sharenix it can be used to implement custom front-ends for sharenix. NOTE: to compile this, you need gtk 2.0 and >=go-1.3.1
Index ¶
- Constants
- Variables
- func AppendToHistory(url, thumbnailurl, deleteurl, filename string) (err error)
- func ArchiveFile(path string) (err error)
- func CaptureRect(X *xgb.Conn, screenIndex int, rect image.Rectangle) (pic *image.RGBA, err error)
- func CaptureScreen(X *xgb.Conn) (pic *image.RGBA, err error)
- func CreateArchiveFile(extension string) (tmpfile *os.File, path string, err error)
- func DebugPrintf(format string, a ...interface{}) (n int, err error)
- func DebugPrintln(a ...interface{}) (n int, err error)
- func FileExists(path string) (bool, error)
- func GenerateArchivedFilename(extension string) (string, error)
- func GetArchiveDir() (res string, err error)
- func GetClipboard() *gtk.Clipboard
- func GetDate() string
- func GetExeDir() (execpath string, err error)
- func GetHistoryCSV() (res string, err error)
- func GetHome() (res string)
- func GetPluginsDir() (res string, err error)
- func GetStorageDir() (res string, err error)
- func GetUploadHistory() (res [][]string, err error)
- func IsImage(mimeType string) bool
- func MkDirIfNotExists(dir string) error
- func Notifyf(head uint32, expire time.Duration, onInit func(*gtk.Window), format string, ...) (err error)
- func ParseRegexList(input string, regexList []string) (res [][]string, err error)
- func ParseUriList(list string) (res []*url.URL)
- func ParseUrl(response []byte, url string, regexResults [][]string) string
- func Println(silent bool, a ...interface{}) (n int, err error)
- func ReplaceKeywords(input, extension string, sitecfg *SiteConfig)
- func RunPlugin(pluginName string, extraParams map[string]string) (output string, err error)
- func SendRequest(method, url, fileParamName, filePath string, extraParams map[string]string, ...) (res *http.Response, filename string, err error)
- func SetClipboardText(text string)
- func ShareNix(cfg *Config, mode, site string, ...) (url, thumburl, deleteurl string, err error)
- func ShortenUrl(cfg *Config, sitecfg *SiteConfig, url string, silent, notif bool) (res *http.Response, err error)
- func SniffMimeType(filePath string) (string, error)
- type ByX
- type Config
- func (cfg *Config) GetServiceByName(name string) *SiteConfig
- func (cfg *Config) HandleFileType(currentsitecfg *SiteConfig, filePath string, silent bool) (sitecfg *SiteConfig, err error)
- func (cfg *Config) IsDefaultSite(site string) bool
- func (cfg *Config) Parse(mode string, site string, silent bool) (sitecfg *SiteConfig, err error)
- type NotImplementedError
- type ScreenRect
- type SiteConfig
- func UploadClipboard(cfg *Config, sitecfg *SiteConfig, silent, notif, upload bool) (res *http.Response, filename string, newsitecfg *SiteConfig, err error)
- func UploadFile(cfg *Config, sitecfg *SiteConfig, path string, silent, notif, upload bool) (res *http.Response, filename string, newsitecfg *SiteConfig, err error)
- func UploadFullScreen(cfg *Config, sitecfg *SiteConfig, silent, notif, upload bool) (res *http.Response, file string, newsitecfg *SiteConfig, err error)
- type SiteNotFoundError
Constants ¶
const ( ParseRegex ParseJson ParseXml )
const (
)Variables ¶
Functions ¶
func AppendToHistory ¶
AppendToHistory appends the given record to sharenix.csv
func ArchiveFile ¶ added in v0.12.2
TODO: merge these two funcs together
func CaptureRect ¶
CaptureRect captures a section of the desired screen. Returns an uncompressed image. screenIndex = -1 gets the default screen.
func CaptureScreen ¶
CaptureScreen captures all screens and returns an uncompressed image
func CreateArchiveFile ¶
Creates and opens an archive file with the given extension.
func DebugPrintf ¶ added in v0.12.2
DebugPrintf formats and prints the given text only if ShareNix is compiled with ShareNixDebug = true
func DebugPrintln ¶
DebugPrintln prints the given text only if ShareNix is compiled with ShareNixDebug = true
func FileExists ¶
FileExists returns true if the given directory or file exists
func GenerateArchivedFilename ¶
GenerateArchivedFilename returns an unique file path inside StorageDir that contains the current date and time
func GetArchiveDir ¶
GetArchiveDir returns the absolute path to the archive directory. If "OrganizedFolders" is set to True in config sharenix will create directories in StorageDir in format /2019-02/
func GetClipboard ¶
GetClipboard returns the default display's GTK clipboard
func GetDate ¶ added in v0.12.2
func GetDate() string
Returns the current year and month in format "2019-01"
func GetHistoryCSV ¶
GetHistoryCSV returns the absolute path to the history csv.
func GetPluginsDir ¶ added in v0.12.2
GetPluginsDir returns the absolute path to the plugins directory.
func GetStorageDir ¶ added in v0.12.2
Returns the path to the storage directory
func GetUploadHistory ¶
GetUploadHistory returns all of the records in sharenix.csv
func MkDirIfNotExists ¶ added in v0.12.2
func Notifyf ¶
func Notifyf(head uint32, expire time.Duration, onInit func(*gtk.Window), format string, a ...interface{}) (err error)
Notifyf formats and shows a notification as a bordeless GTK window in the bottom right corner of the screen. Right-clicking the notification dismisses it and terminates the process. expire is the time after which the notification will expire automatically. onInit is a goroutine that will be started before the gtk main loop blocks the main thread. It takes the notification window as a parameter.
func ParseRegexList ¶
ParseRegexList parses a list of regular expressions on the given input and returns a slice of slices of strings with the match groups of each regex
func ParseUriList ¶
Parses a uri list returned by "x-special/gnome-copied-files" and returns a slice of strings with all of the file uris note: this assumes that each file uri starts with file:/// which I hope is
the standard guaranteed format for x-special/gnome-copied-files.
func ParseUrl ¶
ParseUrl replaces the following syntaxes in url and returns the modified string. - regex matches: $regex:n,n$, $regex:n$, $n,n$, $n$ - json paths: $json:some.json.element$ - xml xpaths: $xml:/root/some/xml/element$
func ReplaceKeywords ¶ added in v0.12.2
func ReplaceKeywords(input, extension string, sitecfg *SiteConfig)
ReplaceKeywords replaces various keywords in the site configuration fields $Y$/%yy: local year padded to 4 digits $M$/%mo: local month padded to 2 digits $D$/%d: local day padded to 2 digits $h$/%h: local hours padded to 2 digits $m$/%mi: local minutes padded to 2 digits $s$/%s: local seconds padded to 2 digits $n$: local nanoseconds $input$, $filename$: whatever is passed as input $extension$: whatever is passed as extension
func RunPlugin ¶ added in v0.12.2
RunPlugin starts pluginName in the plugin directory passing command-line params in the following format:
pluginName -param1Name=param1Value ... -paramXName=paramXValue param_tail
For example, calling
RunPlugin("foo", map[string]string{ "hello": "world", "someflag": "true", "_tail": "bar", })
will execute
foo -hello=world -someflag=true bar
Returns the last line outputted to stdout by the plugin and an error if any. Any trailing newlines at the end of the output are stripped.
func SendRequest ¶ added in v0.12.2
func SendRequest(method, url, fileParamName, filePath string, extraParams map[string]string, extraHeaders map[string]string, username string, password string, ) (res *http.Response, filename string, err error)
SendRequest prepares HTTP request and sends it
if fileParamName empty, no file field will be created and filePath is ignored if username is empty, no http auth header will be sent
if method is GET or PUT, the parameters will be url-encoded, otherwise they will be fields of the multi-part form
if method is PUT and filePath is set, the request body will be the contents of the file
func SetClipboardText ¶
func SetClipboardText(text string)
SetClipbboardText sets the clipboard text contents and calls clipboard.Store(). Note: this requires the program to run at least a few cycles of the main loop and it is not guaranteed to persist on all window managers once the program terminates.
func ShareNix ¶
func ShareNix(cfg *Config, mode, site string, silent, notification, open, copyurl, upload bool) ( url, thumburl, deleteurl string, err error)
ShareNix uploads a file with the given options cfg: ShareNix config mode:
f/file: upload file fs/fullscreen: screenshot entire screen and upload s/section: select screen region and upload c/clipboard: upload clipboard contents r/record: record screen region and upload u/url: shorten url
site: name of the target site silent: disables all console output except errors if enabled notification: displays a gtk notification if enabled. note that dimissing
this notification will force quit the process and the function will never return.
open: automatically opens the uploaded file in the default browser copyurl: stores the url in the clipboard after uploading
func ShortenUrl ¶
func ShortenUrl(cfg *Config, sitecfg *SiteConfig, url string, silent, notif bool) (res *http.Response, err error)
ShortenUrl shortens an url cfg: the ShareNix config sitecfg: the target site config url: url to be shortened silent: disables all console output except errors notif: if true, a notification will display during and after the request
func SniffMimeType ¶
SniffMimeType sniffs the mime type of a binary file by reading the first 512 bytes
Types ¶
type ByX ¶ added in v0.12.2
type ByX []*ScreenRect
ByX is a sorter for a slice of ScreenRect pointers.
type Config ¶
type Config struct { DefaultFileUploader string DefaultImageUploader string DefaultUrlShortener string XineramaHead uint32 `json:",omitempty"` NotificationTime float64 `json:",omitempty"` NotifyUploading bool `json:",omitempty"` NotifyCommand string `json:",omitempty"` ClipboardTime float64 `json:",omitempty"` SaveFolder string `json:",omitempty"` OrganizedFolders bool `json:",omitempty"` Services []SiteConfig }
A Config holds the json ShareX config for all sites plus the default upload targets
func LoadConfig ¶ added in v0.12.2
func (*Config) GetServiceByName ¶
func (cfg *Config) GetServiceByName(name string) *SiteConfig
GetServiceByName finds a site config by site name and returns it
func (*Config) HandleFileType ¶
func (cfg *Config) HandleFileType(currentsitecfg *SiteConfig, filePath string, silent bool) (sitecfg *SiteConfig, err error)
HandleFileType tries to find and return the most suitable site to upload the file to if a default site is currently selected.
func (*Config) IsDefaultSite ¶
IsDefaultSite returns true if the given site name is on if the default sites in the config
func (*Config) Parse ¶
Parse returns the correct SiteConfig for the current mode and sitename
Upload modes:
f/file: upload file fs/fullscreen: screenshot entire screen and upload s/section: select screen region and upload c/clipboard: upload clipboard contents r/record: record screen region and upload u/url: shorten url
type NotImplementedError ¶
type NotImplementedError struct{}
A NotImplementedError is returned when the called feature is not implemented
func (*NotImplementedError) Error ¶
func (e *NotImplementedError) Error() string
type ScreenRect ¶ added in v0.12.2
type ScreenRect struct { // Bounds of the screen (position & size) Rect image.Rectangle // Index of the screen in SetupInfo.Roots for xproto. // -1 means the default screen. ScreenIndex int }
A ScreenRect holds information about the bounds and screen index of a monitor
func ScreenRects ¶ added in v0.12.2
func ScreenRects(X *xgb.Conn) (rects []*ScreenRect, err error)
ScreenRects returns a slice of the bounds and scteen id of each monitor.
type SiteConfig ¶
type SiteConfig struct { Name string RequestType string `json:",omitempty"` Headers map[string]string `json:",omitempty"` RequestURL string FileFormName string `json:",omitempty"` Arguments map[string]string `json:",omitempty"` ResponseType string RegexList []string `json:",omitempty"` URL string `json:",omitempty"` ThumbnailURL string `json:",omitempty"` DeletionURL string `json:",omitempty"` Username string `json:",omitempty"` Password string `json:",omitempty"` }
A SiteConfig holds the json ShareX config for a single site
func UploadClipboard ¶
func UploadClipboard(cfg *Config, sitecfg *SiteConfig, silent, notif, upload bool) ( res *http.Response, filename string, newsitecfg *SiteConfig, err error)
UploadClipboard grabs an image or a file from the clipboard, saves it in the archive and uploads it cfg: the ShareNix config sitecfg: the target site config silent: disables all console output except errors notif: if true, a notification will display during and after the request
func UploadFile ¶
func UploadFile(cfg *Config, sitecfg *SiteConfig, path string, silent, notif, upload bool) ( res *http.Response, filename string, newsitecfg *SiteConfig, err error)
UploadFile uploads a file cfg: the ShareNix config sitecfg: the target site config path: file path silent: disables all console output except errors notif: if true, a notification will display during and after the request
func UploadFullScreen ¶
func UploadFullScreen(cfg *Config, sitecfg *SiteConfig, silent, notif, upload bool) ( res *http.Response, file string, newsitecfg *SiteConfig, err error)
UploadFullScreen captures a full screen screenshot, saves it in the archive and uploads it cfg: the ShareNix config sitecfg: the target site config silent: disables all console output except errors notif: if true, a notification will display during and after the request
type SiteNotFoundError ¶
type SiteNotFoundError struct {
// contains filtered or unexported fields
}
A SiteNotFoundError is returned when the target site doesn't exist in the config
func (*SiteNotFoundError) Error ¶
func (e *SiteNotFoundError) Error() string