storage

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ForbiddenMimeTypes = []string{
	"application/x-dosexec",
	"application/x-msdownload",
	"application/x-sh",
	"application/x-bat",
	"application/x-cmd",
	"text/x-python",
	"application/x-python",
	"application/x-php",
	"text/x-php",
	"application/x-ruby",
	"text/x-ruby",
}

ForbiddenMimeTypes contains the list of forbidden MIME types for file import. This list is used to prevent importing potentially dangerous files (executables, scripts, etc.).

Functions

func CheckFileExists

func CheckFileExists(filePath string) bool

CheckFileExists reports whether the filePath exists or not CheckFileExists works for files and directories

func CopyFile

func CopyFile(srcPath string, dstPath string) (int64, error)

CopyFile simply copies a file from src to dst and returns written bytes It does not preserve file attributes (file system metadata)

func CreateDirectory

func CreateDirectory(filePath string) error

CreateDirectory creates a directory from a given path

func DeleteFile added in v0.4.0

func DeleteFile(filePath string) error

DeleteFile removes a file from the filesystem Only files can be deleted, not directories. It returns an error on failure and nil on success

func EnsureDirectory added in v0.4.0

func EnsureDirectory(path string) error

EnsureDirectory creates the directory if it doesn't exist

func Hash256FromFile

func Hash256FromFile(filePath string) (string, error)

Hash256FromFile returns a SHA-256 hash string from a given file

func IsFileForbidden added in v0.4.0

func IsFileForbidden(mimeType string) bool

IsFileForbidden checks if the given MIME type is forbidden for import. The forbidden MIME types are defined in config.ForbiddenMimeTypes for centralized security management.

func IsThumbnailSupported

func IsThumbnailSupported(mimeType string) bool

isThumbnailSupported checks that we can generate a thumbnail or not from this file

func MimeTypeFromFile

func MimeTypeFromFile(filePath string) (mimeType string, extension string, err error)

MimeTypeFromFile detects the MIME type and file extension from the file content. It returns the MIME type first, then the file extension. Both are returned to avoid opening the file twice.

func MimeTypeIsAudio

func MimeTypeIsAudio(mimeType string) bool

func MimeTypeIsImage

func MimeTypeIsImage(mimeType string) bool

func MimeTypeIsPdf

func MimeTypeIsPdf(mimeType string) bool

func MimeTypeIsSupported

func MimeTypeIsSupported(mimeType string) bool

We check this MimeType is known and supported by Djehooty

func MimeTypeIsTextDocument

func MimeTypeIsTextDocument(mimeType string) bool

func MimeTypeIsVideo

func MimeTypeIsVideo(mimeType string) bool

func MoveFile added in v0.4.0

func MoveFile(srcPath string, dstPath string) error

MoveFile moves a file from src to dst and returns possible error. It preserves file attributes (file system metadata)

func SanitizeFilename added in v0.4.0

func SanitizeFilename(filename string) string

SanitizeFilename removes potentially dangerous characters from filenames to prevent path traversal and other filesystem-related security issues.

Types

This section is empty.

Jump to

Keyboard shortcuts

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