teal

package module
v0.0.0-...-a2987ca Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2020 License: BSD-3-Clause Imports: 14 Imported by: 1

README

teal

godoc pkg.go.dev pxl-gophers contributions and bug requests

This is a simple library for pxl.blue, an image hosting site. Consider this library extremely unstable as pxl.blue and this library are still very early in development.

Examples

Logging in, and uploading a file
package main

import (
	"fmt"
	"os"
	"git.sr.ht/~webb/teal"
)

func main() {
	client, _ := teal.Login("username", "password")
	file, _ := os.Open("glenda.png")
	image, _ := client.UploadFile(file, "glenda.png", "install.gent.ooo")
	fmt.Println(image)
}
Getting an upload key with username and password
package main

import (
	"fmt"
	"git.sr.ht/~webb/teal"
)

func main() {
	client, _ := teal.Login("username", "password")
	fmt.Println(client.UploadKey)
}
Manually creating a barebones client and uploading a file
package main

import (
	"fmt"
	"os"
	"git.sr.ht/~webb/teal"
)

func main() {
	client := &teal.Client{
		UserAgent: "teal",
		UploadKey: "key",
	}

	file, _ := os.Open("glenda.png")
	url, _ := client.UploadFile(file, "glenda.png", "install.gent.ooo")
	fmt.Println(url)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	UploadKey string
	Session   string
	UserAgent string
	User      User
}

Client represents the client used for making http requests, including the session if used.

func Authenticate

func Authenticate(token string) (*Client, error)

Authenticate is equivalent to Login(), but instead it uses an API or session key

func Login

func Login(username string, password string) (*Client, error)

Login will login to an account with the provided credentials and give you a Client with user info back

func (*Client) GetDomains

func (c *Client) GetDomains() ([]Domain, error)

GetDomains gets an array of uploadable domains

func (*Client) UpdateAccountInfo

func (c *Client) UpdateAccountInfo() error

UpdateAccountInfo is a wrapper for GetAccountInfo() that replaces user info automatically

func (*Client) UploadFile

func (c *Client) UploadFile(ir io.Reader, name string, domain string) (*Upload, error)

UploadFile attempts to upload file from io.Reader and returns the response

type Domain

type Domain struct {
	Hostname string `json:"domain"`
	ID       int    `json:"id"`
	Public   bool   `json:"public"`
	System   bool   `json:"system"`
	OwnerID  int    `json:"ownerId"`
	Disabled bool   `json:"disabled"`
}

Domain represents a pxl.blue host.

type Upload

type Upload struct {
	ShortID        string    `json:"shortId"`
	Host           string    `json:"host"`
	Path           string    `json:"path"`
	Size           int       `json:"size"`
	UploadTime     time.Time `json:"uploadTime"`
	URL            string    `json:"url"`
	Hash           string    `json:"hash"`
	Uploader       int       `json:"uploader"`
	ContentType    string    `json:"contentType"`
	OriginalName   string    `json:"originalName"`
	UploaderIP     string    `json:"uploaderIp"`
	ID             int       `json:"id"`
	Deleted        bool      `json:"deleted"`
	DeletionReason string    `json:"deletionReason"`
	DeletionKey    string    `json:"deletionKey"`
}

Upload represents an uploaded file, referred to as an "image" in the UI

type User

type User struct {
	ID                   int       `json:"id"`
	Username             string    `json:"username"`
	Email                string    `json:"email"`
	RegistrationDate     time.Time `json:"registrationDate"`
	LastLogin            time.Time `json:"lastLogin"`
	UploadKey            string    `json:"uploadKey"`
	APIKey               string    `json:"apiKey"`
	RegistrationIP       string    `json:"registrationIp"`
	Moderator            bool      `json:"moderator"`
	Admin                bool      `json:"admin"`
	MailAccess           bool      `json:"mailAccess"`
	MailAccessExpires    time.Time `json:"mailAccessExpires"`
	MailAccountCreated   bool      `json:"mailAccountCreated"`
	MailAliasLimit       int       `json:"mailAliasLimit"`
	Banned               bool      `json:"banned"`
	BanReason            string    `json:"banReason"`
	ImageCount           int       `json:"imageCount"`
	DiscordID            string    `json:"discordId"`
	DiscordTag           string    `json:"discordTag"`
	MatrixAccountCreated bool      `json:"matrixAccountCreated"`
	DiscordLinked        bool      `json:"settings_discordLink"`
	APISecurity          bool      `json:"settings_apiIpSecurity"`
}

User holds all of the information about a user that is accessible from the profile page

func GetAccountInfo

func GetAccountInfo(session string) (*User, error)

GetAccountInfo gets info of a user of a given authentication key

Jump to

Keyboard shortcuts

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