added md5 sums to the local file upload indexing
This commit is contained in:
parent
643729af1f
commit
2808c85147
@ -44,7 +44,7 @@ func Run() {
|
|||||||
logErrorAndExit(err, 5)
|
logErrorAndExit(err, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = synchronizeImages(filesystemNodes, categories)
|
err = synchronizeImages(context, filesystemNodes, categories)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logErrorAndExit(err, 6)
|
logErrorAndExit(err, 6)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,10 @@ import (
|
|||||||
|
|
||||||
func synchronizeImages(context *AppContext, fileSystem map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*category.PiwigoCategory) error {
|
func synchronizeImages(context *AppContext, fileSystem map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*category.PiwigoCategory) error {
|
||||||
|
|
||||||
imageFiles := getImageList(fileSystem)
|
imageFiles, err := localFileStructure.GetImageList(fileSystem)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
missingFiles := findMissingImages(imageFiles)
|
missingFiles := findMissingImages(imageFiles)
|
||||||
uploadImages(missingFiles)
|
uploadImages(missingFiles)
|
||||||
@ -17,7 +20,7 @@ func synchronizeImages(context *AppContext, fileSystem map[string]*localFileStru
|
|||||||
return errors.New("synchronizeImages: NOT IMPLEMENTED")
|
return errors.New("synchronizeImages: NOT IMPLEMENTED")
|
||||||
}
|
}
|
||||||
|
|
||||||
func findMissingImages(imageFiles []string) []string {
|
func findMissingImages(imageFiles []*localFileStructure.ImageNode) []string {
|
||||||
|
|
||||||
logrus.Warnln("Finding missing images (NotImplemented)")
|
logrus.Warnln("Finding missing images (NotImplemented)")
|
||||||
|
|
||||||
@ -27,15 +30,3 @@ func findMissingImages(imageFiles []string) []string {
|
|||||||
func uploadImages(missingFiles []string) {
|
func uploadImages(missingFiles []string) {
|
||||||
logrus.Warnln("Uploading missing images (NotImplemented)")
|
logrus.Warnln("Uploading missing images (NotImplemented)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getImageList(fileSystem map[string]*localFileStructure.FilesystemNode) []string {
|
|
||||||
imageFiles := []string{}
|
|
||||||
|
|
||||||
for _, file := range fileSystem {
|
|
||||||
if !file.IsDir {
|
|
||||||
imageFiles = append(imageFiles, file.Key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return imageFiles
|
|
||||||
}
|
|
||||||
|
30
internal/pkg/localFileStructure/checksumCalculator.go
Normal file
30
internal/pkg/localFileStructure/checksumCalculator.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package localFileStructure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"fmt"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func calculateFileCheckSums(filePath string) (string, error) {
|
||||||
|
f, err := os.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Could not open file %s", filePath)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
h := md5.New()
|
||||||
|
if _, err := io.Copy(h, f); err != nil {
|
||||||
|
logrus.Errorf("Could calculate md5 sum of file %s", filePath)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
md5sum := fmt.Sprintf("%x", md5.Sum(nil))
|
||||||
|
|
||||||
|
logrus.Tracef("Calculated md5 sum of %s - %s", filePath, md5sum)
|
||||||
|
|
||||||
|
return md5sum, nil
|
||||||
|
}
|
@ -21,19 +21,21 @@ func ScanLocalFileStructure(path string) (map[string]*FilesystemNode, error) {
|
|||||||
numberOfDirectories := 0
|
numberOfDirectories := 0
|
||||||
numberOfImages := 0
|
numberOfImages := 0
|
||||||
|
|
||||||
err = filepath.Walk(fullPathRoot, func(p string, info os.FileInfo, err error) error {
|
err = filepath.Walk(fullPathRoot, func(path string, info os.FileInfo, err error) error {
|
||||||
if fullPathRoot == p {
|
if fullPathRoot == path {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Only allow jpg and png files here
|
//TODO: Only allow jpg and png files here
|
||||||
|
|
||||||
key := strings.Replace(p, fullPathReplace, "", 1)
|
key := strings.Replace(path, fullPathReplace, "", 1)
|
||||||
|
|
||||||
fileMap[p] = &FilesystemNode{
|
fileMap[path] = &FilesystemNode{
|
||||||
Key: key,
|
Key: key,
|
||||||
Name: info.Name(),
|
Path: path,
|
||||||
IsDir: info.IsDir(),
|
Name: info.Name(),
|
||||||
|
IsDir: info.IsDir(),
|
||||||
|
ModTime: info.ModTime(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
|
31
internal/pkg/localFileStructure/imageList.go
Normal file
31
internal/pkg/localFileStructure/imageList.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package localFileStructure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetImageList(fileSystem map[string]*FilesystemNode) ([]*ImageNode, error) {
|
||||||
|
imageFiles := []*ImageNode{}
|
||||||
|
|
||||||
|
for _, file := range fileSystem {
|
||||||
|
if file.IsDir {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
md5sum, err := calculateFileCheckSums(file.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Debugf("Image %s - %s - %s", md5sum, file.ModTime.Format(time.RFC3339), file.Path)
|
||||||
|
|
||||||
|
imageFiles = append(imageFiles, &ImageNode{
|
||||||
|
Path: file.Path,
|
||||||
|
ModTime: file.ModTime,
|
||||||
|
Md5Sum: md5sum,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageFiles, nil
|
||||||
|
}
|
@ -1,13 +1,24 @@
|
|||||||
package localFileStructure
|
package localFileStructure
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type FilesystemNode struct {
|
type FilesystemNode struct {
|
||||||
Key string
|
Key string
|
||||||
Name string
|
Path string
|
||||||
IsDir bool
|
Name string
|
||||||
|
IsDir bool
|
||||||
|
ModTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *FilesystemNode) String() string {
|
func (n *FilesystemNode) String() string {
|
||||||
return fmt.Sprintf("FilesystemNode: %s", n.Key)
|
return fmt.Sprintf("FilesystemNode: %s", n.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImageNode struct {
|
||||||
|
Path string
|
||||||
|
ModTime time.Time
|
||||||
|
Md5Sum string
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,11 @@ func ImageUploadRequired(context *piwigo.PiwigoContext, files []string) (bool, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
http://pictures.haefelfinger.net/ws.php?format=json
|
http://pictures.haefelfinger.net/ws.php?format=json
|
||||||
{
|
{
|
||||||
"md5sum_list": "d327416a83452b91764ed2888a5630a3,6d5f122e2b98bc1a192850e89fc2ae8c,40bfe8dd8349ccdedd4a939f9191cafa"
|
"md5sum_list": "d327416a83452b91764ed2888a5630a3,6d5f122e2b98bc1a192850e89fc2ae8c,40bfe8dd8349ccdedd4a939f9191cafa"
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package picture
|
package picture
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
http://pictures.haefelfinger.net/ws.php?format=json
|
http://pictures.haefelfinger.net/ws.php?format=json
|
||||||
{
|
{
|
||||||
@ -8,4 +7,4 @@ http://pictures.haefelfinger.net/ws.php?format=json
|
|||||||
"original_sum": "1234567",
|
"original_sum": "1234567",
|
||||||
"position": "1"
|
"position": "1"
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user