mirror of
https://github.com/photoprism/photoprism.git
synced 2025-09-26 21:01:58 +08:00
Code clean-up
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/photoprism/photoprism"
|
||||
"github.com/urfave/cli"
|
||||
"os"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@@ -62,4 +62,4 @@ func makeTransformImageGraph(imageFormat string) (graph *tf.Graph, input, output
|
||||
op.Const(s.SubScope("scale"), Scale))
|
||||
graph, err = s.Finalize()
|
||||
return graph, input, output, err
|
||||
}
|
||||
}
|
||||
|
@@ -135,4 +135,4 @@ func findBestLabels(probabilities []float32) []LabelResult {
|
||||
sort.Sort(ByProbability(resultLabels))
|
||||
// Return top 5 labels
|
||||
return resultLabels[:5]
|
||||
}
|
||||
}
|
||||
|
@@ -14,4 +14,4 @@ func responseError(w http.ResponseWriter, message string, code int) {
|
||||
func responseJSON(w http.ResponseWriter, data interface{}) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(data)
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const testDataPath = "testdata"
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Converter struct {
|
||||
@@ -22,7 +22,6 @@ func NewConverter(darktableCli string) *Converter {
|
||||
return &Converter{darktableCli: darktableCli}
|
||||
}
|
||||
|
||||
|
||||
func (c *Converter) ConvertAll(path string) {
|
||||
err := filepath.Walk(path, func(filename string, fileInfo os.FileInfo, err error) error {
|
||||
|
||||
@@ -66,7 +65,7 @@ func (c *Converter) ConvertToJpeg(image *MediaFile) (*MediaFile, error) {
|
||||
|
||||
extension := image.GetExtension()
|
||||
|
||||
baseFilename := image.filename[0:len(image.filename)-len(extension)]
|
||||
baseFilename := image.filename[0 : len(image.filename)-len(extension)]
|
||||
|
||||
jpegFilename := baseFilename + ".jpg"
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"os"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewConverter(t *testing.T) {
|
||||
@@ -21,11 +21,11 @@ func TestConverter_ConvertToJpeg(t *testing.T) {
|
||||
|
||||
converter := NewConverter(conf.DarktableCli)
|
||||
|
||||
jpegFilename := conf.ImportPath + "/iphone/IMG_6788.jpg"
|
||||
jpegFilename := conf.ImportPath + "/iphone/IMG_6788.jpg"
|
||||
|
||||
t.Logf("Testing RAW to JPEG converter with %s", jpegFilename)
|
||||
|
||||
imageJpeg,_ := converter.ConvertToJpeg(NewMediaFile(jpegFilename))
|
||||
imageJpeg, _ := converter.ConvertToJpeg(NewMediaFile(jpegFilename))
|
||||
|
||||
infoJpeg, err := imageJpeg.GetExifData()
|
||||
|
||||
@@ -35,13 +35,13 @@ func TestConverter_ConvertToJpeg(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "iPhone SE", infoJpeg.CameraModel)
|
||||
|
||||
rawFilemame := conf.ImportPath + "/raw/IMG_1435.CR2"
|
||||
rawFilemame := conf.ImportPath + "/raw/IMG_1435.CR2"
|
||||
|
||||
t.Logf("Testing RAW to JPEG converter with %s", rawFilemame)
|
||||
|
||||
imageRaw, _ := converter.ConvertToJpeg(NewMediaFile(rawFilemame))
|
||||
|
||||
assert.True(t, fileExists(conf.ImportPath + "/raw/IMG_1435.jpg"), "Jpeg file was not found - is Darktable installed?")
|
||||
assert.True(t, fileExists(conf.ImportPath+"/raw/IMG_1435.jpg"), "Jpeg file was not found - is Darktable installed?")
|
||||
|
||||
assert.NotEqual(t, rawFilemame, imageRaw.filename)
|
||||
|
||||
|
20
importer.go
20
importer.go
@@ -1,28 +1,28 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"os"
|
||||
"log"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Importer struct {
|
||||
originalsPath string
|
||||
removeDotFiles bool
|
||||
removeExistingFiles bool
|
||||
originalsPath string
|
||||
removeDotFiles bool
|
||||
removeExistingFiles bool
|
||||
removeEmptyDirectories bool
|
||||
}
|
||||
|
||||
func NewImporter(originalsPath string) *Importer {
|
||||
instance := &Importer{
|
||||
originalsPath: originalsPath,
|
||||
removeDotFiles: true,
|
||||
removeExistingFiles: true,
|
||||
originalsPath: originalsPath,
|
||||
removeDotFiles: true,
|
||||
removeExistingFiles: true,
|
||||
removeEmptyDirectories: true,
|
||||
}
|
||||
|
||||
@@ -116,4 +116,4 @@ func (i *Importer) GetDestinationFilename(masterFile *MediaFile, mediaFile *Medi
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewImporter(t *testing.T) {
|
||||
@@ -34,5 +34,5 @@ func TestImporter_GetDestinationFilename(t *testing.T) {
|
||||
|
||||
assert.Empty(t, err)
|
||||
|
||||
assert.Equal(t, conf.OriginalsPath + "/2018/02/20180204_180813_B0770443A5F7.cr2", filename)
|
||||
}
|
||||
assert.Equal(t, conf.OriginalsPath+"/2018/02/20180204_180813_B0770443A5F7.cr2", filename)
|
||||
}
|
||||
|
57
mediafile.go
57
mediafile.go
@@ -1,16 +1,16 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"encoding/hex"
|
||||
"github.com/brett-lempereur/ish"
|
||||
"github.com/djherbis/times"
|
||||
"github.com/steakknife/hamming"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
"github.com/djherbis/times"
|
||||
"github.com/steakknife/hamming"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -27,37 +27,37 @@ const (
|
||||
MimeTypeJpeg = "image/jpeg"
|
||||
)
|
||||
|
||||
var FileExtensions = map[string]string {
|
||||
".crw": FileTypeRaw,
|
||||
".cr2": FileTypeRaw,
|
||||
".nef": FileTypeRaw,
|
||||
".arw": FileTypeRaw,
|
||||
".dng": FileTypeRaw,
|
||||
".mov": FileTypeMovie,
|
||||
".avi": FileTypeMovie,
|
||||
".yml": FileTypeYaml,
|
||||
".jpg": FileTypeJpeg,
|
||||
var FileExtensions = map[string]string{
|
||||
".crw": FileTypeRaw,
|
||||
".cr2": FileTypeRaw,
|
||||
".nef": FileTypeRaw,
|
||||
".arw": FileTypeRaw,
|
||||
".dng": FileTypeRaw,
|
||||
".mov": FileTypeMovie,
|
||||
".avi": FileTypeMovie,
|
||||
".yml": FileTypeYaml,
|
||||
".jpg": FileTypeJpeg,
|
||||
".jpeg": FileTypeJpeg,
|
||||
".xmp": FileTypeXmp,
|
||||
".aae": FileTypeAae,
|
||||
".xmp": FileTypeXmp,
|
||||
".aae": FileTypeAae,
|
||||
}
|
||||
|
||||
type MediaFile struct {
|
||||
filename string
|
||||
dateCreated time.Time
|
||||
hash string
|
||||
fileType string
|
||||
mimeType string
|
||||
filename string
|
||||
dateCreated time.Time
|
||||
hash string
|
||||
fileType string
|
||||
mimeType string
|
||||
perceptualHash string
|
||||
tags []string
|
||||
exifData *ExifData
|
||||
tags []string
|
||||
exifData *ExifData
|
||||
}
|
||||
|
||||
func NewMediaFile(filename string) *MediaFile {
|
||||
instance := &MediaFile{
|
||||
filename: filename,
|
||||
fileType: FileTypeOther,
|
||||
}
|
||||
}
|
||||
|
||||
return instance
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func (m *MediaFile) GetDateCreated() time.Time {
|
||||
return t.ModTime()
|
||||
}
|
||||
|
||||
func (m *MediaFile) GetCameraModel () string {
|
||||
func (m *MediaFile) GetCameraModel() string {
|
||||
info, err := m.GetExifData()
|
||||
|
||||
var result string
|
||||
@@ -172,7 +172,7 @@ func (m *MediaFile) GetHash() string {
|
||||
func (m *MediaFile) GetRelatedFiles() (result []*MediaFile, masterFile *MediaFile, err error) {
|
||||
extension := m.GetExtension()
|
||||
|
||||
baseFilename := m.filename[0:len(m.filename)-len(extension)]
|
||||
baseFilename := m.filename[0 : len(m.filename)-len(extension)]
|
||||
|
||||
matches, err := filepath.Glob(baseFilename + "*")
|
||||
|
||||
@@ -195,12 +195,11 @@ func (m *MediaFile) GetRelatedFiles() (result []*MediaFile, masterFile *MediaFil
|
||||
return result, masterFile, nil
|
||||
}
|
||||
|
||||
|
||||
func (m *MediaFile) GetFilename() string {
|
||||
return m.filename
|
||||
}
|
||||
|
||||
func (m *MediaFile) SetFilename(filename string) {
|
||||
func (m *MediaFile) SetFilename(filename string) {
|
||||
m.filename = filename
|
||||
}
|
||||
|
||||
@@ -282,4 +281,4 @@ func (m *MediaFile) IsRaw() bool {
|
||||
|
||||
func (m *MediaFile) IsPhoto() bool {
|
||||
return m.IsJpeg() || m.IsRaw()
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/rwcarlsen/goexif/exif"
|
||||
"github.com/rwcarlsen/goexif/mknote"
|
||||
"time"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ExifData struct {
|
||||
@@ -70,4 +70,4 @@ func (m *MediaFile) GetExifData() (*ExifData, error) {
|
||||
}
|
||||
|
||||
return m.exifData, nil
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMediaFile_GetExifData(t *testing.T) {
|
||||
@@ -14,7 +14,7 @@ func TestMediaFile_GetExifData(t *testing.T) {
|
||||
|
||||
info, err := image1.GetExifData()
|
||||
|
||||
assert.Empty(t, err);
|
||||
assert.Empty(t, err)
|
||||
|
||||
assert.IsType(t, &ExifData{}, info)
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMediaFile_FindRelatedImages(t *testing.T) {
|
||||
@@ -25,7 +25,7 @@ func TestMediaFile_FindRelatedImages(t *testing.T) {
|
||||
|
||||
extension := result.GetExtension()
|
||||
|
||||
baseFilename := filename[0:len(filename)-len(extension)]
|
||||
baseFilename := filename[0 : len(filename)-len(extension)]
|
||||
|
||||
assert.Equal(t, expectedBaseFilename, baseFilename)
|
||||
}
|
||||
@@ -62,7 +62,6 @@ func TestMediaFile_GetPerceptiveHash(t *testing.T) {
|
||||
assert.Equal(t, 33, distance)
|
||||
}
|
||||
|
||||
|
||||
func TestMediaFile_GetMimeType(t *testing.T) {
|
||||
conf := NewTestConfig()
|
||||
|
||||
@@ -87,4 +86,4 @@ func TestMediaFile_Exists(t *testing.T) {
|
||||
mediaFile = NewMediaFile(conf.ImportPath + "/iphone/IMG_6788_XYZ.JPG")
|
||||
|
||||
assert.False(t, mediaFile.Exists())
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"log"
|
||||
)
|
||||
|
||||
func CreateThumbnail () {
|
||||
func CreateThumbnail() {
|
||||
src, err := imaging.Open("testdata/lena_512.png")
|
||||
|
||||
if err != nil {
|
||||
@@ -17,4 +17,4 @@ func CreateThumbnail () {
|
||||
|
||||
// Resize the cropped image to width = 256px preserving the aspect ratio.
|
||||
src = imaging.Resize(src, 256, 0, imaging.Lanczos)
|
||||
}
|
||||
}
|
||||
|
18
util.go
18
util.go
@@ -1,19 +1,19 @@
|
||||
package photoprism
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"os"
|
||||
"crypto/sha512"
|
||||
"io"
|
||||
"strings"
|
||||
"archive/zip"
|
||||
"log"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetExpandedFilename(filename string) string {
|
||||
|
Reference in New Issue
Block a user