fsmod

package
v0.0.0-...-1dc26ce Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GenericErrorCode         = 100
	StatusNotFoundCode       = 404
	StatusInvalidRequestCode = 400
)
View Source
const (
	TEXT_FILE   = "text"
	BINARY_FILE = "binary"
	IMAGE_FILE  = "image"
	PDF_FILE    = "pdf"
	HTML_FILE   = "html"
)

Variables

This section is empty.

Functions

func HandleCreateFile

func HandleCreateFile(req protocol.Request, channel protocol.TransportChannel, conf Conf.Config)

func HandleReadFile

func HandleReadFile(req protocol.Request, channel protocol.TransportChannel, conf Conf.Config)

func ValidateReadFileParams

func ValidateReadFileParams(params ReadFileParams) error

Types

type CreateFileErrorResponse

type CreateFileErrorResponse struct {
	protocol.Response

	Error protocol.Error `json:"error"`
}

type CreateFileParams

type CreateFileParams struct {
	/**
	 * The name of the file to create
	 */
	Name string `json:"name"`
	/**
	 * The content of the file
	 */
	Content string `json:"content"`
	/**
	 * if directories should be created if not present, default is false
	 */
	CreateDirs bool `json:"create-dirs,omitempty"`
	/**
	 * The permissions of the directory, should be sent as decimal number like 438 (octal 0666).
	 * Default is 0755, only used if create-dirs is true
	 */
	CreateDirPermissions int `json:"create-dir-permissions,omitempty"`
	/**
	 * The directory where the file should be created
	 */
	Dir string `json:"dir,omitempty"`
	/**
	 * The type of the file, e.g. text, image, etc.
	 * Not always possible to infer from the extension, it might not be present
	 */
	FileType string `json:"file-type,omitempty"`
	/**
	 * The permissions of the file, should be sent as decimal number like 438 (octal 0666)
	 */
	Permissions int `json:"permissions,omitempty"`
	/**
	 * If the file should be overwritten if it already exists, default is false
	 */
	Overwrite bool `json:"overwrite,omitempty"`
}

func NewCreateFileParams

func NewCreateFileParams(params map[string]any, conf Conf.Config) *CreateFileParams

type CreateFileRequest

type CreateFileRequest struct {
	protocol.Request

	Params CreateFileParams `json:"params"`
}

type CreateFileSuccessResponse

type CreateFileSuccessResponse struct {
	protocol.Response

	Result File `json:"result"`
}

func NewCreateFileSuccessResponse

func NewCreateFileSuccessResponse(req protocol.Request, file *File) *CreateFileSuccessResponse

type File

type File struct {
	/**
	 * Name of the file
	 */
	Name string `json:"name"`
	/**
	 * Absolute path of the parent directory of the file
	 */
	Dir string `json:"dir"`
	/**
	 * The content of the file
	 */
	Content string `json:"content"`
	/**
	 * The size of the file in bytes
	 */
	Size int `json:"size"`
	/**
	 * The type of the file, e.g. text, image, etc.
	 */
	FileType string `json:"fileType"`
	/**
	 * The version number of this document (it will increase after each
	 * change, including undo/redo).
	 */
	Version int `json:"version"`
	/**
	 * The extension of the TextFile
	 */
	Extension string `json:"extension"`
	/**
	 * A map for storing any additional data
	 */
	MetaData map[string]any `json:"metaData"`
	/**
	 * The MIME type of the file
	 */
	MIMEType MIMEType `json:"mimeType"`
	/**
	 * The permissions of the file, e.g. 0777
	 */
	Permissions int `json:"permissions"`
}

func CreateFile

func CreateFile(params *CreateFileParams) (*File, error)

func NewFile

func NewFile() *File

func NewFileFromCreateFileParams

func NewFileFromCreateFileParams(fileParams *CreateFileParams) *File

func ReadFile

func ReadFile(params *ReadFileParams) (*File, error)

type FileNotFoundError

type FileNotFoundError struct {
	FileName   string
	StatusCode int
	Message    string
}

FileNotFoundError is an error type for file not found

func NewFileNotFoundError

func NewFileNotFoundError(fileName string) *FileNotFoundError

func (*FileNotFoundError) Error

func (e *FileNotFoundError) Error() string

type GenericError

type GenericError struct {
	StatusCode int
	Message    string
}

GenericError is an error type for generic errors

func NewGenericError

func NewGenericError() *GenericError

func (*GenericError) Error

func (e *GenericError) Error() string

type InvalidParamsError

type InvalidParamsError struct {
	StatusCode int
	Message    string
}

InvalidParamsError is an error type for invalid parameters

func NewInvalidParamsError

func NewInvalidParamsError() *InvalidParamsError

func (*InvalidParamsError) Error

func (e *InvalidParamsError) Error() string

type MIMEType

type MIMEType string
const (
	MIMETextPlain      MIMEType = "text/plain"
	MIMETextHTML       MIMEType = "text/html"
	MIMEImageJPEG      MIMEType = "image/jpeg"
	MIMEImagePNG       MIMEType = "image/png"
	MIMEApplicationPDF MIMEType = "application/pdf"
)

func (MIMEType) String

func (mt MIMEType) String() string

type ReadFileErrorResponse

type ReadFileErrorResponse struct {
	protocol.Response

	Error error `json:"error"`
}

func NewReadFileErrorResponse

func NewReadFileErrorResponse(req protocol.Request, error error) *ReadFileErrorResponse

type ReadFileParams

type ReadFileParams struct {
	/**
	 * The path of the file to read
	 */
	Name string `json:"path"`
	/**
	 * The path of the parent directory of the file
	 */
	Dir string `json:"dir"`
	/**
	 * If set to true, reads the file as binary (base64 string), otherwise as text.
	 * Default is false (read as text)
	 */
	Binary bool `json:"binary,omitempty"`
	/**
	 * Specifies the maximum number of bytes to read from the file.
	 * If not set or zero, it is read until the end of the file.
	 */
	MaxBytes int64 `json:"max-bytes,omitempty"`
	/**
	 * Specifies the offset from where to start reading the file.
	 * If not set or zero, the file is read from the beginning.
	 */
	Offset int64 `json:"offset,omitempty"`
	/**
	 * If set to true, checks if the file exists before reading.
	 * Default is false.
	 */
	CheckExists bool `json:"check-exists,omitempty"`
}

func NewReadFileParams

func NewReadFileParams(params map[string]any, conf Conf.Config) *ReadFileParams

type ReadFileRequest

type ReadFileRequest struct {
	protocol.Request

	Params ReadFileParams `json:"params"`
}

type ReadFileSuccessResponse

type ReadFileSuccessResponse struct {
	protocol.Response

	Result File `json:"result"`
}

func NewReadFileSuccessResponse

func NewReadFileSuccessResponse(req protocol.Request, file *File) *ReadFileSuccessResponse

type TextFile

type TextFile struct {
	File
	Content string `json:"text"`
}

Jump to

Keyboard shortcuts

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