sharenixlib

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: GPL-3.0 Imports: 44 Imported by: 0

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

View Source
const (
	ParseRegex
	ParseJson
	ParseXml
)
View Source
const (
	ShareNixVersion = "ShareNix 0.12.0a"
)

Variables

View Source
var ShareNixDebug = false

Functions

func AppendToHistory

func AppendToHistory(url, thumbnailurl, deleteurl, filename string) (
	err error)

AppendToHistory appends the given record to sharenix.csv

func ArchiveFile added in v0.12.2

func ArchiveFile(path string) (err error)

TODO: merge these two funcs together

func CaptureRect

func CaptureRect(X *xgb.Conn, screenIndex int, rect image.Rectangle) (
	pic *image.RGBA, err error)

CaptureRect captures a section of the desired screen. Returns an uncompressed image. screenIndex = -1 gets the default screen.

func CaptureScreen

func CaptureScreen(X *xgb.Conn) (pic *image.RGBA, err error)

CaptureScreen captures all screens and returns an uncompressed image

func CreateArchiveFile

func CreateArchiveFile(extension string) (
	tmpfile *os.File, path string, err error)

Creates and opens an archive file with the given extension.

func DebugPrintf added in v0.12.2

func DebugPrintf(format string, a ...interface{}) (n int, err error)

DebugPrintf formats and prints the given text only if ShareNix is compiled with ShareNixDebug = true

func DebugPrintln

func DebugPrintln(a ...interface{}) (n int, err error)

DebugPrintln prints the given text only if ShareNix is compiled with ShareNixDebug = true

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if the given directory or file exists

func GenerateArchivedFilename

func GenerateArchivedFilename(extension string) (string, error)

GenerateArchivedFilename returns an unique file path inside StorageDir that contains the current date and time

func GetArchiveDir

func GetArchiveDir() (res string, err error)

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

func GetClipboard() *gtk.Clipboard

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 GetExeDir added in v0.12.2

func GetExeDir() (execpath string, err error)

func GetHistoryCSV

func GetHistoryCSV() (res string, err error)

GetHistoryCSV returns the absolute path to the history csv.

func GetHome added in v0.12.2

func GetHome() (res string)

func GetPluginsDir added in v0.12.2

func GetPluginsDir() (res string, err error)

GetPluginsDir returns the absolute path to the plugins directory.

func GetStorageDir added in v0.12.2

func GetStorageDir() (res string, err error)

Returns the path to the storage directory

func GetUploadHistory

func GetUploadHistory() (res [][]string, err error)

GetUploadHistory returns all of the records in sharenix.csv

func IsImage

func IsImage(mimeType string) bool

IsImage determines if a mime type is an image or not

func MkDirIfNotExists added in v0.12.2

func MkDirIfNotExists(dir string) error

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

func ParseRegexList(input string, regexList []string) (
	res [][]string, err error)

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

func ParseUriList(list string) (res []*url.URL)

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

func ParseUrl(response []byte, url string, regexResults [][]string) string

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 Println

func Println(silent bool, a ...interface{}) (n int, err error)

Println prints the given thext only if silent is false

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

func RunPlugin(pluginName string,
	extraParams map[string]string) (output string, err error)

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

func SniffMimeType(filePath string) (string, error)

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.

func (ByX) Len added in v0.12.2

func (a ByX) Len() int

func (ByX) Less added in v0.12.2

func (a ByX) Less(i, j int) bool

func (ByX) Swap added in v0.12.2

func (a ByX) Swap(i, j int)

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 LoadConfig() (cfg *Config, err error)

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

func (cfg *Config) IsDefaultSite(site string) bool

IsDefaultSite returns true if the given site name is on if the default sites in the config

func (*Config) Parse

func (cfg *Config) Parse(mode string, site string, silent bool) (
	sitecfg *SiteConfig, err error)

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

Jump to

Keyboard shortcuts

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