discordfs

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

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

Go to latest
Published: Oct 6, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

README

discordfs

Installation

To compile the CLI executable:

go build -o discfs ./cmd

The executable looks for a config file in your home folder. On UNIX-like systems (Linux, the BSDs, MacOS) it's $home (/home/username), on Windows it's %USERPROFILE% (C:\\Users\\username)

Create a file called disc.yaml in your home folder and write:

token: "<your-bot-token>"
channel: "<channel-id>"

Alternatively you can set a different location for the config file with discfs --config="<config-file>"

Development

Create a file named secrets.go in the root folder of the project and write:

package discordfs

const authToken = `<your-bot-token>`
const channelId = `<channel-id>`

TestNewDownload looks for test cases in the test_files folder of the project. You can:

  • Populate this folder with test files that also exist on the cloud channel. They must have the same name as the ones on the cloud
  • Comment out the test. It's not necessary, TestUploadAndDelete fulfills the same purpose

Documentation

Index

Constants

View Source
const (
	B = 1 << (iota * 10)
	KB
	MB
	GB
	TB
)
View Source
const Root = "/"

Variables

View Source
var ErrFileNotFound = errors.New("file couldn't be found")

Functions

func GetCloudChannel

func GetCloudChannel(s *dg.Session) (*dg.Channel, error)

GetCloudChannel looks through all the channels the bot is in and returns the first one it thinks to be a valid cloud channel

func IsCloudChannel

func IsCloudChannel(s *dg.Session, channelID string) (bool, error)

Types

type ChunkInfo

type ChunkInfo struct {
	File        FileInfo    `json:"file"`
	Part        PartInfo    `json:"part"`
	Compression Compression `json:"compression"`
	Url         string      `json:"-"`
}

type Compression

type Compression struct {
	Level CompressionLevel `json:"level"`
	Type  CompressionType  `json:"type"`
}

type CompressionLevel

type CompressionLevel int16

func (CompressionLevel) MarshalJSON

func (c CompressionLevel) MarshalJSON() ([]byte, error)

func (CompressionLevel) String

func (c CompressionLevel) String() string

func (*CompressionLevel) UnmarshalJSON

func (c *CompressionLevel) UnmarshalJSON(input []byte) error

type CompressionType

type CompressionType int16
const (
	EachChunk CompressionType = iota << 8
	WholeFile
)

func (CompressionType) MarshalJSON

func (c CompressionType) MarshalJSON() ([]byte, error)

func (CompressionType) String

func (c CompressionType) String() string

func (*CompressionType) UnmarshalJSON

func (c *CompressionType) UnmarshalJSON(input []byte) error

type DiscFile

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

DiscFile is a lazy file descriptor. It downloads the file it points to only when Read() is called

func (*DiscFile) Close

func (df *DiscFile) Close() error

func (DiscFile) ConcreteStat

func (df DiscFile) ConcreteStat() (FileInfo, error)

func (*DiscFile) Read

func (df *DiscFile) Read(input []byte) (int, error)

func (DiscFile) Stat

func (df DiscFile) Stat() (fs.FileInfo, error)

type DiscFolder

type DiscFolder struct{ FileInfo }

func (DiscFolder) Info

func (df DiscFolder) Info() (fs.FileInfo, error)

func (DiscFolder) Type

func (df DiscFolder) Type() fs.FileMode

type DiscStorage

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

DiscStorage contains the necessary information to connect to the cloud channel

func NewStorage

func NewStorage(s *dg.Session, channelId string) DiscStorage

NewStorage builds a new DiscStorage

func (DiscStorage) Delete

func (st DiscStorage) Delete(filename string) error

func (DiscStorage) DoesFileExist

func (st DiscStorage) DoesFileExist(filename string) (bool, error)

DoesFileExist checks if a file exists on the cloud channel

func (DiscStorage) GetFile

func (st DiscStorage) GetFile(filename string) (*DiscFile, error)

Open returns a DiscFile if found on the channel

func (DiscStorage) ListFiles

func (st DiscStorage) ListFiles(folder string) ([]FileInfo, error)

ListFiles lists all the files `st` can find

func (DiscStorage) Open

func (st DiscStorage) Open(filename string) (fs.File, error)

func (DiscStorage) ReadDir

func (st DiscStorage) ReadDir(dir string) ([]fs.DirEntry, error)

func (DiscStorage) Receive

func (st DiscStorage) Receive(into io.Writer, filename string) error

ReceiveAllAtOnce looks for the file named `name` in the channel with the provided `channelID` with the provided session, storing the result into `into`. It writes each piece into `into` as soon as it comes todo: remove duplication between this and ReceiveAllAtOnce()?

func (DiscStorage) ReceiveAllAtOnce

func (st DiscStorage) ReceiveAllAtOnce(into io.Writer, filename string) error

ReceiveAllAtOnce looks for the file named `name` in the channel with the provided `channelID` with the provided session, storing the result into `into`. It first downloads the whole file, then writes it all at once into `into`. If you'd rather get each piece as soon as it arrives try using Receive()

func (DiscStorage) ReceiveCompressed

func (st DiscStorage) ReceiveCompressed(into io.Writer, filename string) error

func (DiscStorage) Send

func (st DiscStorage) Send(file io.Reader, info FileInfo, chunkSize int) error

Send splits the `file` into chunks of size `chunkSize` and sends each one

func (DiscStorage) SendCompressed

func (st DiscStorage) SendCompressed(file io.Reader, info FileInfo, chunkSize int) error

func (DiscStorage) SendFile

func (st DiscStorage) SendFile(file *os.File, chunkSize int) error

SendFile is a frontend to `Send` that doesn't ask you for a name or a file size

func (DiscStorage) Stat

func (st DiscStorage) Stat(filename string) (fs.FileInfo, error)

type FileChunk

type FileChunk struct {
	Info     ChunkInfo
	Contents []byte
}

type FileInfo

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

func NewFileInfo

func NewFileInfo(filePath string, pubblished time.Time, size int) FileInfo

func (FileInfo) FullPath

func (f FileInfo) FullPath() string

func (FileInfo) IsDir

func (f FileInfo) IsDir() bool

func (FileInfo) MarshalJSON

func (fi FileInfo) MarshalJSON() ([]byte, error)

field names `Name` and `Size` are necessary for fs.FileInfo, se we make them unexported

func (FileInfo) ModTime

func (f FileInfo) ModTime() time.Time

func (FileInfo) Mode

func (f FileInfo) Mode() fs.FileMode

func (FileInfo) Name

func (f FileInfo) Name() string

func (FileInfo) Size

func (f FileInfo) Size() int64

func (FileInfo) Sys

func (f FileInfo) Sys() interface{}

func (*FileInfo) UnmarshalJSON

func (fi *FileInfo) UnmarshalJSON(data []byte) error

type PartInfo

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

func (PartInfo) MarshalJSON

func (pi PartInfo) MarshalJSON() ([]byte, error)

func (*PartInfo) UnmarshalJSON

func (pi *PartInfo) UnmarshalJSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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