Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeAttachmentURL(inputURL string) (string, int, int, string)
- func EncodeAttachmentURL(baseURL string, ex int, is int, hm string) string
- func NewNWriter(onChunk func(chunk Node), chunkSize int, rest *Rest) io.WriteCloser
- func NewReader(chunks []Node, pos int64, rest *Rest) (io.ReadCloser, error)
- func NewWriter(onChunk func(chunk Node), chunkSize int, rest *Rest) io.WriteCloser
- type AttachmentResp
- type Config
- type Driver
- type Limiter
- type Message
- type NWriter
- type Node
- type Reader
- type Rest
- func (r *Rest) CreateAttachment(reader io.Reader) (*Node, error)
- func (r *Rest) CreateAttachmentNitro(reader io.Reader) (*Node, error)
- func (r *Rest) GetMessages(channelId string, messageId int64, query string, messages *[]Message) error
- func (r *Rest) ReadAttachment(att *Node, start int, end int) (io.ReadCloser, error)
- type Writer
Constants ¶
const ( UserAgent = "PostmanRuntime/7.35.0" ReqTimeout = 60 * time.Second )
const ( TokenBot = iota TokenUser TokenUserNitro TokenUserNitroBasic )
const ExtraDelay = 250 * time.Millisecond
const MaxChunkSize = 25 * 1024 * 1024
const MaxChunkSizeNitro = 500 * 1024 * 1024
const MaxChunkSizeNitroBasic = 50 * 1024 * 1024
Variables ¶
var ErrAlreadyClosed = errors.New("already closed")
ErrAlreadyClosed is returned when the reader/writer is already closed
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 ¶
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 ¶
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
Types ¶
type AttachmentResp ¶
type Driver ¶
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 ¶
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 ¶
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
type Message ¶
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
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.
type Rest ¶
type Rest struct {
// contains filtered or unexported fields
}
func (*Rest) CreateAttachment ¶
CreateAttachment uploads a file to the Discord channel using the webhook.
func (*Rest) CreateAttachmentNitro ¶
func (*Rest) GetMessages ¶
func (*Rest) ReadAttachment ¶
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 ¶
Close implements the Close method of io.Closer. It closes the Writer. If the Writer is already closed, Close returns ErrAlreadyClosed.