ddrv

package
v0.0.0-...-cf2fa2e Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserAgent  = "PostmanRuntime/7.35.0"
	ReqTimeout = 60 * time.Second
)
View Source
const (
	TokenBot = iota
	TokenUser
	TokenUserNitro
	TokenUserNitroBasic
)
View Source
const ExtraDelay = 250 * time.Millisecond
View Source
const MaxChunkSize = 25 * 1024 * 1024
View Source
const MaxChunkSizeNitro = 500 * 1024 * 1024
View Source
const MaxChunkSizeNitroBasic = 50 * 1024 * 1024

Variables

View Source
var ErrAlreadyClosed = errors.New("already closed")

ErrAlreadyClosed is returned when the reader/writer is already closed

View Source
var ErrClosed = errors.New("is closed")

ErrClosed is returned when a writer or reader is closed and caller is trying to read or write

Functions

func DecodeAttachmentURL

func DecodeAttachmentURL(inputURL string) (string, int, int, string)

DecodeAttachmentURL parses the input URL and extracts the query parameters. It returns the cleaned URL, `ex` and `is` as integers, `hm` as a string, and an error if any.

func EncodeAttachmentURL

func EncodeAttachmentURL(baseURL string, ex int, is int, hm string) string

EncodeAttachmentURL takes a base URL, `ex`, `is`, and `hm` as inputs, and returns the modified URL.

func NewNWriter

func NewNWriter(onChunk func(chunk Node), chunkSize int, rest *Rest) io.WriteCloser

func NewReader

func NewReader(chunks []Node, pos int64, rest *Rest) (io.ReadCloser, error)

NewReader creates new Reader instance which implements io.ReadCloser.

func NewWriter

func NewWriter(onChunk func(chunk Node), chunkSize int, rest *Rest) io.WriteCloser

NewWriter writes data to discord

Types

type AttachmentResp

type AttachmentResp struct {
	Attachments []struct {
		UploadUrl      string `json:"upload_url"`
		UploadFileName string `json:"upload_filename"`
	} `json:"attachments"`
}

type Config

type Config struct {
	Tokens    []string
	TokenType int
	Channels  []string
	ChunkSize int
	Nitro     bool
}

type Driver

type Driver struct {
	Rest      *Rest
	ChunkSize int
}

func New

func New(cfg *Config) (*Driver, error)

func (*Driver) NewNWriter

func (d *Driver) NewNWriter(onChunk func(chunk Node)) io.WriteCloser

NewNWriter creates a new ddrv.NWriter instance that implements an io.WriterCloser. This allows for writing large files to Discord as small, manageable chunks. NWriter buffers bytes into memory and writes data to discord in parallel

func (*Driver) NewReader

func (d *Driver) NewReader(chunks []Node, pos int64) (io.ReadCloser, error)

NewReader creates a new Reader instance that implements an io.ReaderCloser. This allows for reading large files from Discord that were split into small chunks.

func (*Driver) NewWriter

func (d *Driver) NewWriter(onChunk func(chunk Node)) io.WriteCloser

NewWriter creates a new ddrv.Writer instance that implements an io.WriterCloser. This allows for writing large files to Discord as small, manageable chunks.

func (*Driver) UpdateNodes

func (d *Driver) UpdateNodes(chunks []*Node) error

UpdateNodes finds expired chunks and updates chunk signature in given chunks slice

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter() *Limiter

func (*Limiter) Acquire

func (l *Limiter) Acquire(path string)

func (*Limiter) Release

func (l *Limiter) Release(path string, headers http.Header)

type Message

type Message struct {
	Id          string `json:"id"`
	Attachments []Node `json:"attachments"`
}

Message represents a Discord message and contains attachments (files uploaded within the message).

type NWriter

type NWriter struct {
	// contains filtered or unexported fields
}

NWriter buffers bytes into memory and writes data to discord in parallel at the cost of high-memory usage. Expected memory usage - (chunkSize * number of channels) + 20% bytes

func (*NWriter) Close

func (w *NWriter) Close() error

func (*NWriter) Write

func (w *NWriter) Write(p []byte) (int, error)

type Node

type Node struct {
	NId   int64  // not used in ddrv package itself but for data providers
	URL   string `json:"url"`  // URL where the data is stored
	Size  int    `json:"size"` // Size of the data
	Start int64  // Start position of the data in the overall data sequence
	End   int64  // End position of the data in the overall data sequence
	MId   int64  `json:"mid"` // Node message id
	Ex    int    `json:"ex"`  // Node link expiry time
	Is    int    `json:"is"`  // Node link issued time
	Hm    string `json:"hm"`  // Node link signature
}

Node represents a Discord attachment URL and Size

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader is a structure that manages the reading of a sequence of Chunks. It reads chunks in order, closing each one after it's Read and moving on to the next.

func (*Reader) Close

func (r *Reader) Close() error

Close implements the Close method of io.Closer. It closes the Reader. If the Reader is already closed, Close returns ErrAlreadyClosed.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read reads data from the current chunk into p. If it reaches the end of a chunk, it moves to the next one. It reads until p is full or there are no more chunks to Read from.

type Rest

type Rest struct {
	// contains filtered or unexported fields
}

func NewRest

func NewRest(tokens []string, channels []string, chunkSize int, nitro bool) *Rest

func (*Rest) CreateAttachment

func (r *Rest) CreateAttachment(reader io.Reader) (*Node, error)

CreateAttachment uploads a file to the Discord channel using the webhook.

func (*Rest) CreateAttachmentNitro

func (r *Rest) CreateAttachmentNitro(reader io.Reader) (*Node, error)

func (*Rest) GetMessages

func (r *Rest) GetMessages(channelId string, messageId int64, query string, messages *[]Message) error

func (*Rest) ReadAttachment

func (r *Rest) ReadAttachment(att *Node, start int, end int) (io.ReadCloser, error)

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer implements io.WriteCloser. It streams data in chunks to Discord server channels using webhook

func (*Writer) Close

func (w *Writer) Close() error

Close implements the Close method of io.Closer. It closes the Writer. If the Writer is already closed, Close returns ErrAlreadyClosed.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write implements the Write method of io.Writer. It writes p to the Writer. If p is larger than the remaining space in the current chunk, Write splits p across multiple chunks as needed. Returns the total number of bytes from p that were written.

Jump to

Keyboard shortcuts

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