sharenixlib

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2015 License: GPL-3.0 Imports: 29 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/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

View Source
const (
	ShareNixDebug   = true
	ShareNixVersion = "ShareNix 0.2.1a"
)

Variables

This section is empty.

Functions

func AppendToHistory

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

AppendToHistory appends the given record to sharenix.csv

func CaptureRect

func CaptureRect(rect image.Rectangle) (pic *image.RGBA, err error)

CaptureRect captures the given section of the screen and returns an uncompressed image

func CaptureScreen

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

CaptureScreen captures the default screen 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 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 FullScreenRect

func FullScreenRect() (rect image.Rectangle, err error)

FullScreenRect returns a rectangle of the entire screen

func GenerateArchivedFilename

func GenerateArchivedFilename(extension string) (string, error)

GenerateArchivedFilename returns an unique file path inside archive/ that contains the current date, time and nanotime.

func GetArchiveDir

func GetArchiveDir() (archiveDir string, err error)

GetArchiveDir returns the absolute path to the archive directory.

func GetClipboard

func GetClipboard() (*gtk.Clipboard, error)

GetClipboard returns the default display's GTK clipboard

func GetHistoryCSV

func GetHistoryCSV() (csv string, err error)

GetHistoryCSV returns the absolute path to the history csv.

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 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

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(url string, regexResults [][]string) string

ParseUrl replaces $n$ and $n,n$ tags in the given url with the proper regex matches

func Println

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

Println prints the given thext only if silent is false

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

func SendGetRequest(baseurl string, params map[string]string) (
	res *http.Response, err error)

SendGetRequest sends a GET request with params

func SendPostRequest

func SendPostRequest(baseurl string, params map[string]string) (*http.Response, error)

SendGetRequest sends a POST request with params

func SetClipboardText

func SetClipboardText(text string) (err error)

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

func SniffMimeType(filePath string) (string, error)

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

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 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

Jump to

Keyboard shortcuts

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