mirror of
https://github.com/rclone/rclone.git
synced 2025-08-16 00:28:09 +02:00
.github
backend
bin
cmd
cmdtest
contrib
docs
fs
accounting
asyncreader
cache
chunkedreader
chunksize
config
dirtree
driveletter
filter
fserrors
fshttp
fspath
hash
list
log
logger
march
object
operations
rc
sync
walk
backend_config.go
backend_config_test.go
bits.go
bits_test.go
bwtimetable.go
bwtimetable_test.go
config.go
config_list.go
config_list_test.go
config_test.go
configmap.go
countsuffix.go
countsuffix_test.go
cutoffmode.go
cutoffmode_test.go
daemon_other.go
daemon_unix.go
deletemode.go
dir.go
dir_wrapper.go
direntries.go
direntries_test.go
dump.go
dump_test.go
enum.go
enum_test.go
features.go
fingerprint.go
fingerprint_test.go
fs.go
fs_test.go
log.go
log_test.go
metadata.go
metadata_mapper_code.go
metadata_test.go
mimetype.go
mount_helper.go
mount_helper_test.go
newfs.go
newfs_test.go
open_options.go
open_options_test.go
override.go
override_dir.go
override_dir_test.go
override_test.go
pacer.go
parseduration.go
parseduration_test.go
parsetime.go
parsetime_test.go
registry.go
sizesuffix.go
sizesuffix_test.go
terminalcolormode.go
terminalcolormode_test.go
tristate.go
tristate_test.go
types.go
version.go
versioncheck.go
versionsuffix.go
versiontag.go
fstest
graphics
lib
librclone
vfs
.gitattributes
.gitignore
.golangci.yml
CONTRIBUTING.md
COPYING
Dockerfile
MAINTAINERS.md
MANUAL.html
MANUAL.md
MANUAL.txt
Makefile
README.md
RELEASE.md
VERSION
go.mod
go.sum
notes.txt
rclone.1
rclone.go
This involved adding the Fs() method to DirEntry as it is needed in the metadata mapper. Unspecialised fs.Dir objects will return a new fs.Unknown from their Fs() methods as they are not specific to any given Fs.
82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
package fs
|
|
|
|
import (
|
|
"context"
|
|
"mime"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
// Add a minimal number of mime types to augment go's built in types
|
|
// for environments which don't have access to a mime.types file (e.g.
|
|
// Termux on android)
|
|
func init() {
|
|
for _, t := range []struct {
|
|
mimeType string
|
|
extensions string
|
|
}{
|
|
{"audio/flac", ".flac"},
|
|
{"audio/mpeg", ".mpga,.mpega,.mp2,.mp3,.m4a"},
|
|
{"audio/ogg", ".oga,.ogg,.opus,.spx"},
|
|
{"audio/x-wav", ".wav"},
|
|
{"image/tiff", ".tiff,.tif"},
|
|
{"video/dv", ".dif,.dv"},
|
|
{"video/fli", ".fli"},
|
|
{"video/mpeg", ".mpeg,.mpg,.mpe"},
|
|
{"video/MP2T", ".ts"},
|
|
{"video/mp4", ".mp4"},
|
|
{"video/quicktime", ".qt,.mov"},
|
|
{"video/ogg", ".ogv"},
|
|
{"video/webm", ".webm"},
|
|
{"video/x-msvideo", ".avi"},
|
|
{"video/x-matroska", ".mpv,.mkv"},
|
|
{"text/srt", ".srt"},
|
|
} {
|
|
for _, ext := range strings.Split(t.extensions, ",") {
|
|
if mime.TypeByExtension(ext) == "" {
|
|
err := mime.AddExtensionType(ext, t.mimeType)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MimeTypeFromName returns a guess at the mime type from the name
|
|
func MimeTypeFromName(remote string) (mimeType string) {
|
|
mimeType = mime.TypeByExtension(path.Ext(remote))
|
|
if !strings.ContainsRune(mimeType, '/') {
|
|
mimeType = "application/octet-stream"
|
|
}
|
|
return mimeType
|
|
}
|
|
|
|
// MimeType returns the MimeType from the object, either by calling
|
|
// the MimeTyper interface or using MimeTypeFromName
|
|
func MimeType(ctx context.Context, o DirEntry) (mimeType string) {
|
|
// Read the MimeType from the optional interface if available
|
|
if do, ok := o.(MimeTyper); ok {
|
|
mimeType = do.MimeType(ctx)
|
|
// Debugf(o, "Read MimeType as %q", mimeType)
|
|
if mimeType != "" {
|
|
return mimeType
|
|
}
|
|
}
|
|
return MimeTypeFromName(o.Remote())
|
|
}
|
|
|
|
// MimeTypeDirEntry returns the MimeType of a DirEntry
|
|
//
|
|
// It returns "inode/directory" for directories, or uses
|
|
// MimeType(Object)
|
|
func MimeTypeDirEntry(ctx context.Context, item DirEntry) string {
|
|
switch x := item.(type) {
|
|
case Object:
|
|
return MimeType(ctx, x)
|
|
case Directory:
|
|
return "inode/directory"
|
|
}
|
|
return ""
|
|
}
|