filesorter

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PropertyName     = "name"
	PropertyNameSolo = "name_solo"
	PropertyExt      = "ext"
	PropertyMinSize  = "minsize"
	PropertyMaxSize  = "maxsize"
	PropertyMimeType = "mime-type"
	PropertyDate     = "date"
	PropertyDrive    = "drive"
	PropertyPath     = "path"
	PropertyDir      = "dir"
	PropertyAll      = "all"
	PropertyOther    = "other"
)

Variables

View Source
var FuncMap = template.FuncMap{}

Functions

func MoveURL

func MoveURL(fl *File, targetURL string, s3configFile path.Local, testonly bool) error

MoveURL moves the given file to the given targeturl

func Run

func Run(configFile path.Local, s3configFile path.Local, isTest bool) error

Run is using the given config files and just running the movement. If isTest is true, it is just simulation and printing out, what would be done

Types

type Config

type Config struct {
	Definitions []Definition

	Rules map[string]Rule
}

Config consits of a map of rules (name to Rule), that define how and when a file is moved somewhere, and a set of defintions that define for which paths which rules do apply.

type Definition added in v0.0.3

type Definition struct {
	Sources []string
	Rules   []string // name and order of rules
}

Definition defines a set of paths (Sources) and the names of the Rules that should handle them. The first rule that matches wins.

type File added in v0.0.3

type File struct {
	Name       string
	Date       time.Time
	Path       path.Local
	Size       int
	Drive      string
	MimeType   string
	Properties map[string]string
}

func (*File) TargetURL added in v0.0.3

func (f *File) TargetURL(rules []Rule, isTest bool) (string, error)

TargetURL will be empty, if there is not matching rule

type FileProp

type FileProp string

func (FileProp) String

func (p FileProp) String() string

type Files added in v0.0.3

type Files []*File

func FindFiles

func FindFiles(dir path.Local) (Files, error)

type Matcher

type Matcher struct {
	Property Property
	Pattern  string // regexp
}

Matcher matches a property agains a regular expression (Pattern)

func (Matcher) Matches

func (m Matcher) Matches(f *File) bool

type Matchers

type Matchers []Matcher

func (Matchers) Matches

func (m Matchers) Matches(f *File) bool

type Property

type Property struct {

	// Name is the name of the property
	Name string

	// value is only relevant for comparisions, e.g. the int to compare minsize against
	Val any
}

Property is a property of a file

type Rule

type Rule struct {
	Matchers   Matchers
	URLPattern string
}

Rule defines a set of Matchers. If any of these matches, the URLPattern is applied for moving accordingly. URLPattern is a go text-template. it is given a map so all properties of a file can be accesses via {{ index . "propname" }}. The following properties are always available:

"name"         (name of the file, including extension)
"name_solo"    (name of the file, without extension)
"ext"          (extension, without the dot)
"dir"          (the name of the parent directory)
"path"         (the full path of the parent directory)
"mime-type"    (the mimetype)
"date"         (the date in format YYYY-MM-DD)
"drive"        (the mountpoint, e.g. /c/ for the windows drive C:\)

furthermore, within matchers there can be matched against

"minsize"      (matches all files with this minimum size in bytes)
"maxsize"      (matches all files up to this maximum size in bytes)

func (Rule) Matches

func (r Rule) Matches(f *File) bool

type S3Config

type S3Config struct {
	Endpoint,
	Region,
	Key,
	Secret,
	Bucket,
	SubPath,
	ClientRegion string
}

type S3Hosts added in v0.0.3

type S3Hosts struct {
	Configs map[string]S3Config // keys can be pseudo-hosts; they only must match the host in the target url
}

func (*S3Hosts) Load added in v0.0.3

func (s *S3Hosts) Load(file path.Local) error

Jump to

Keyboard shortcuts

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