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/gdk-3.10 and >=go-1.3.1 You will also need my modified fork of gotk3: github.com/Francesco149/gotk3 (go get it then rename it to github.com/conformal/gotk3 so that it can be properly imported)
Index ¶
- Constants
- func AppendToHistory(url, thumbnailurl, deleteurl, filename string) (err error)
- func CaptureRect(rect image.Rectangle) (pic *image.RGBA, err error)
- func CaptureScreen() (pic *image.RGBA, err error)
- func CreateArchiveFile(extension string) (tmpfile *os.File, path string, err error)
- func DebugPrintln(a ...interface{}) (n int, err error)
- func FileExists(path string) (bool, error)
- func FullScreenRect() (rect image.Rectangle, err error)
- func GenerateArchivedFilename(extension string) (string, error)
- func GetArchiveDir() (archiveDir string, err error)
- func GetClipboard() (*gtk.Clipboard, error)
- func GetHistoryCSV() (csv string, err error)
- func GetUploadHistory() (res [][]string, err error)
- func IsImage(mimeType string) bool
- func MakeArchiveDir() error
- func Notifyf(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(url string, regexResults [][]string) string
- func Println(silent bool, a ...interface{}) (n int, err error)
- func SendFilePostRequest(url, fileParamName, filePath string, extraParams map[string]string) (res *http.Response, filename string, err error)
- func SendGetRequest(baseurl string, params map[string]string) (res *http.Response, err error)
- func SendPostRequest(baseurl string, params map[string]string) (*http.Response, error)
- func SetClipboardText(text string) (err error)
- func ShareNix(cfg *Config, mode, site string, silent, notification, open, copyurl bool) (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)
- func UploadClipboard(cfg *Config, sitecfg *SiteConfig, silent, notif bool) (res *http.Response, filename string, err error)
- func UploadFile(cfg *Config, sitecfg *SiteConfig, path string, silent, notif bool) (res *http.Response, filename string, err error)
- func UploadFullScreen(cfg *Config, sitecfg *SiteConfig, silent, notif bool) (res *http.Response, file string, err error)
- 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 SiteConfig
- type SiteNotFoundError
Constants ¶
const ()
Variables ¶
This section is empty.
Functions ¶
func AppendToHistory ¶
AppendToHistory appends the given record to sharenix.csv
func CaptureRect ¶
CaptureRect captures the given section of the screen and returns an uncompressed image
func CaptureScreen ¶
CaptureScreen captures the default screen and returns an uncompressed image
func CreateArchiveFile ¶
Creates and opens an archive file with the given extension.
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 FullScreenRect ¶
FullScreenRect returns a rectangle of the entire screen
func GenerateArchivedFilename ¶
GenerateArchivedFilename returns an unique file path inside archive/ that contains the current date, time and nanotime.
func GetArchiveDir ¶
GetArchiveDir returns the absolute path to the archive directory.
func GetClipboard ¶
GetClipboard returns the default display's GTK clipboard
func GetHistoryCSV ¶
GetHistoryCSV returns the absolute path to the history csv.
func GetUploadHistory ¶
GetUploadHistory returns all of the records in sharenix.csv
func MakeArchiveDir ¶
func MakeArchiveDir() error
MakeArchiveDir creates the archive directory if it doesn't exist already.
func Notifyf ¶
func Notifyf(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 SendFilePostRequest ¶
func SendFilePostRequest(url, fileParamName, filePath string, extraParams map[string]string) (res *http.Response, filename string, err error)
SendFilePostRequest prepares a multipart file upload POST request and sends it
func SendGetRequest ¶
SendGetRequest sends a GET request with params
func SendPostRequest ¶
SendGetRequest sends a POST request with params
func SetClipboardText ¶
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 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 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
func UploadClipboard ¶
func UploadClipboard(cfg *Config, sitecfg *SiteConfig, silent, notif bool) ( res *http.Response, filename string, 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 bool) (res *http.Response, filename string, 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 bool) ( res *http.Response, file string, 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
Types ¶
type Config ¶
type Config struct { DefaultFileUploader string DefaultImageUploader string DefaultUrlShortener string Services []SiteConfig }
A Config holds the json ShareX config for all sites plus the default upload targets
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 SiteConfig ¶
type SiteConfig struct { Name string RequestType string RequestURL string FileFormName string Arguments map[string]string ResponseType string RegexList []string URL string ThumbnailURL string DeletionURL string }
A SiteConfig holds the json ShareX config for a single site
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