🏷️ Created File domain

This commit is contained in:
Maxim Lebedev 2023-11-09 06:44:05 +06:00
parent e74c0a0b66
commit 2cf99dcba1
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 44 additions and 0 deletions

44
internal/domain/file.go Normal file
View File

@ -0,0 +1,44 @@
package domain
import (
"mime"
"path/filepath"
"strings"
"time"
)
type File struct {
Path string
Updated time.Time
Content []byte
}
// LogicalName returns full file name without directory path.
func (f File) LogicalName() string {
return filepath.Base(f.Path)
}
// BaseFileName returns file name without extention and directory path.
func (f File) BaseFileName() string {
base := filepath.Base(f.Path)
return strings.TrimSuffix(base, filepath.Ext(base))
}
// Ext returns file extention.
func (f File) Ext() string {
if ext := filepath.Ext(f.Path); len(ext) > 1 {
return ext[1:]
}
return ""
}
// Dir returns file directory.
func (f File) Dir() string {
return filepath.Dir(f.Path)
}
func (f File) MediaType() string {
return mime.TypeByExtension(f.Ext())
}