2021-02-04 06:01:21 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-02-10 03:25:46 +01:00
|
|
|
"io/ioutil"
|
|
|
|
"path"
|
2021-02-04 06:01:21 +01:00
|
|
|
|
|
|
|
photoprism "github.com/kris-nova/client-go"
|
|
|
|
"github.com/kris-nova/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-02-10 03:25:46 +01:00
|
|
|
// ---
|
|
|
|
// Log Level 4 (Most)
|
|
|
|
// Log Level 3
|
|
|
|
// Log Level 2
|
|
|
|
// Log Level 1
|
|
|
|
// Log Level 0 (Least)
|
|
|
|
//
|
2021-02-09 20:17:06 +01:00
|
|
|
logger.Level = 4
|
2021-02-10 03:25:46 +01:00
|
|
|
//
|
|
|
|
// ---
|
|
|
|
|
2021-02-09 20:17:06 +01:00
|
|
|
uuid := "pqnzigq351j2fqgn" // This is a known ID
|
2021-02-09 23:45:36 +01:00
|
|
|
client := photoprism.New("http://localhost:8080")
|
|
|
|
err := client.Auth(photoprism.NewClientAuthLogin("admin", "missy"))
|
2021-02-04 06:01:21 +01:00
|
|
|
if err != nil {
|
|
|
|
halt(4, "Error logging into API: %v", err)
|
|
|
|
}
|
2021-02-10 03:25:46 +01:00
|
|
|
|
|
|
|
// ---
|
|
|
|
// GetPhoto()
|
|
|
|
//
|
2021-02-04 06:01:21 +01:00
|
|
|
photo, err := client.V1().GetPhoto(uuid)
|
|
|
|
if err != nil {
|
|
|
|
halt(3, "Error fetching photo: %v", err)
|
|
|
|
}
|
2021-02-10 01:00:02 +01:00
|
|
|
|
2021-02-10 03:25:46 +01:00
|
|
|
// ---
|
|
|
|
// UpdatePhoto()
|
|
|
|
photo.PhotoTitle = "A really great photo!"
|
|
|
|
photo, err = client.V1().UpdatePhoto(photo)
|
|
|
|
if err != nil {
|
|
|
|
halt(2, "Error updating photo: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
// GetPhotoDownload()
|
|
|
|
file, err := client.V1().GetPhotoDownload(photo.UUID)
|
2021-02-04 06:01:21 +01:00
|
|
|
if err != nil {
|
2021-02-10 03:25:46 +01:00
|
|
|
halt(2, "Error getting photo download: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range photo.Files {
|
|
|
|
fileName := fmt.Sprintf("ignore_%s", path.Base(f.FileName))
|
|
|
|
logger.Always(fileName)
|
|
|
|
ioutil.WriteFile(fileName, file, 0666)
|
2021-02-04 06:01:21 +01:00
|
|
|
}
|
2021-02-10 03:25:46 +01:00
|
|
|
|
2021-02-04 06:01:21 +01:00
|
|
|
}
|