Documentation
¶
Index ¶
- Variables
- func CheckFileExists(filePath string) bool
- func CopyFile(srcPath string, dstPath string) (int64, error)
- func CreateDirectory(filePath string) error
- func DeleteFile(filePath string) error
- func EnsureDirectory(path string) error
- func Hash256FromFile(filePath string) (string, error)
- func IsFileForbidden(mimeType string) bool
- func IsThumbnailSupported(mimeType string) bool
- func MimeTypeFromFile(filePath string) (mimeType string, extension string, err error)
- func MimeTypeIsAudio(mimeType string) bool
- func MimeTypeIsImage(mimeType string) bool
- func MimeTypeIsPdf(mimeType string) bool
- func MimeTypeIsSupported(mimeType string) bool
- func MimeTypeIsTextDocument(mimeType string) bool
- func MimeTypeIsVideo(mimeType string) bool
- func MoveFile(srcPath string, dstPath string) error
- func SanitizeFilename(filename string) string
Constants ¶
This section is empty.
Variables ¶
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 ¶
CheckFileExists reports whether the filePath exists or not CheckFileExists works for files and directories
func CopyFile ¶
CopyFile simply copies a file from src to dst and returns written bytes It does not preserve file attributes (file system metadata)
func CreateDirectory ¶
CreateDirectory creates a directory from a given path
func DeleteFile ¶ added in v0.4.0
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
EnsureDirectory creates the directory if it doesn't exist
func Hash256FromFile ¶
Hash256FromFile returns a SHA-256 hash string from a given file
func IsFileForbidden ¶ added in v0.4.0
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 ¶
isThumbnailSupported checks that we can generate a thumbnail or not from this file
func MimeTypeFromFile ¶
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 MimeTypeIsImage ¶
func MimeTypeIsPdf ¶
func MimeTypeIsSupported ¶
We check this MimeType is known and supported by Djehooty
func MimeTypeIsTextDocument ¶
func MimeTypeIsVideo ¶
func MoveFile ¶ added in v0.4.0
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
SanitizeFilename removes potentially dangerous characters from filenames to prevent path traversal and other filesystem-related security issues.
Types ¶
This section is empty.