This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/routes/routes.go

98 lines
2.1 KiB
Go

package routes
import (
"net/http"
"fmt"
"reichard.io/imagini/internal/db"
"github.com/tus/tusd/pkg/filestore"
tusd "github.com/tus/tusd/pkg/handler"
)
func RegisterRoutes() {
http.HandleFunc("/Users", usersHandler)
http.HandleFunc("/Tags", tagsHandler)
// Uploads Handler
http.Handle("/uploads/", uploadsHandler())
}
func tagsHandler(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
filters, present := query["filters"]
}
func uploadsHandler() http.Handler {
store := filestore.FileStore{
Path: "./uploads",
}
composer := tusd.NewStoreComposer()
store.UseIn(composer)
handler, err := tusd.NewHandler(tusd.Config{
BasePath: "/uploads/",
StoreComposer: composer,
NotifyCompleteUploads: true,
})
if err != nil {
panic(fmt.Errorf("Unable to create handler: %s", err))
}
go func() {
for {
event := <-handler.CompleteUploads
fmt.Printf("Upload %s finished\n", event.Upload.ID)
}
}()
return http.StripPrefix("/uploads/", handler)
}
func processMedia() {
var mi db.MediaItem
// TODO:
// - Derive Magic -> mediaType
// - Create Thumbnail
// - Pull EXIF
// - EXIFDate
// - Latitude
// - Longitude
// - TensorFlow Classification
// - https://outcrawl.com/image-recognition-api-go-tensorflow
// - Update Tags / MediaTags Table
// - Save Image
// - Update MediaItems Table
// import "github.com/disintegration/imaging"
//
// img, err := imaging.Open("original.jpg", imaging.AutoOrientation(true))
// if err != nil {
// return nil, err
// }
//
// img = imaging.Fit(img, 240, 160, imaging.Lanczos)
// err = imaging.Save(img, "thumbnail.jpg")
}
func helloHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/hello" {
http.Error(w, "404 not found.", http.StatusNotFound)
return
}
if r.Method != "GET" {
http.Error(w, "Method is not supported.", http.StatusNotFound)
return
}
fmt.Fprintf(w, "Hello!")
}