aboutsummaryrefslogtreecommitdiff
path: root/storage.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2022-09-10 17:33:30 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2022-09-10 17:33:30 +0200
commit3451d56ead6e57f503962b876c89284f1fb73a90 (patch)
tree172599f1f3acd77bc918c55403eb78255ced43e6 /storage.go
parent544bbeeaf836436305cbed87ae1019511de62535 (diff)
downloadporg-3451d56ead6e57f503962b876c89284f1fb73a90.tar.gz
porg-3451d56ead6e57f503962b876c89284f1fb73a90.tar.bz2
porg-3451d56ead6e57f503962b876c89284f1fb73a90.zip
ref: Create a storage interface
This `Storage` interface will define all the interactions with the storage system. For now I plan to support native file system through go's standard library and Nextcloud through *webdav*. So this is the first step in that direction.
Diffstat (limited to 'storage.go')
-rw-r--r--storage.go68
1 files changed, 0 insertions, 68 deletions
diff --git a/storage.go b/storage.go
deleted file mode 100644
index 28637da..0000000
--- a/storage.go
+++ /dev/null
@@ -1,68 +0,0 @@
-package main
-
-import (
- "crypto/sha256"
- "fmt"
- "io"
- "os"
-
- "github.com/barasher/go-exiftool"
-)
-
-type File struct {
- Path string
- SHA256 string
- Time string
-}
-
-type Storage interface {
- Upsert(file *File) error
- LoadByPath(path string) *File
-}
-
-func NewFile(path string) *File {
- return &File{Path: path}
-}
-
-func (file *File) CalculateSHA256() error {
- f, err := os.Open(file.Path)
- if err != nil {
- return err
- }
- defer f.Close()
-
- h := sha256.New()
- if _, err := io.Copy(h, f); err != nil {
- return err
- }
-
- file.SHA256 = fmt.Sprintf("%x", h.Sum(nil))
-
- return nil
-}
-
-func (file *File) SetTime() error {
-
- et, err := exiftool.NewExiftool()
- if err != nil {
- return err
- }
- defer et.Close()
-
- fileInfos := et.ExtractMetadata(file.Path)
-
- for _, fileInfo := range fileInfos {
- if fileInfo.Err != nil {
- fmt.Printf("Error concerning %v: %v\n", fileInfo.File, fileInfo.Err)
- continue
- }
-
- v, ok := fileInfo.Fields["DateTimeOriginal"]
- if ok {
- t, _ := v.(string)
- file.Time = t
- }
- }
-
- return nil
-}