117 lines
3.2 KiB
Go
117 lines
3.2 KiB
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
func RegisterRoutes() {
|
|
http.HandleFunc("/MediaItems", mediaItemsHandler)
|
|
http.HandleFunc("/Upload", uploadHandler)
|
|
http.HandleFunc("/Albums", albumsHandler)
|
|
http.HandleFunc("/Logout", logoutHandler)
|
|
http.HandleFunc("/Login", loginHandler)
|
|
http.HandleFunc("/Users", usersHandler)
|
|
http.HandleFunc("/Tags", tagsHandler)
|
|
http.HandleFunc("/Info", infoHandler)
|
|
http.HandleFunc("/Me", meHandler)
|
|
}
|
|
|
|
// Examples:
|
|
// [POST] /Login { user: <USER_OR_EMAIL>, password: <PASSWORD> }
|
|
// [POST] /Logout
|
|
// [GET] /MediaItems
|
|
|
|
// commonMiddleware := []Middleware{
|
|
// logMiddleware,
|
|
// authMiddleware,
|
|
// }
|
|
// http.Handle("/Users", MultipleMiddleware(usersHandler, commonMiddleware...))
|
|
// http.Handle("/Uploads/", MultipleMiddleware(uploadsHandler, commonMiddleware...))
|
|
|
|
// // http.HandleFunc("/uploads/", uploadsHandler())
|
|
// http.Handle("/Uploads/", func(next http.Handler) http.Handler {
|
|
// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// _, ok := ValidateUserToken(r)
|
|
|
|
// if ok {
|
|
// next.ServeHTTP(w, r)
|
|
// } else {
|
|
// w.WriteHeader(http.StatusUnauthorized)
|
|
// }
|
|
// })
|
|
// }(http.StripPrefix("/Uploads/", tusHandler)))
|
|
|
|
// Filter Example:
|
|
// query := r.URL.Query()
|
|
// filters, present := query["filters"]
|
|
|
|
// HTTP Errors
|
|
// if r.Method != "GET" {
|
|
// http.Error(w, "Method is not supported.", http.StatusNotFound)
|
|
// return
|
|
// }
|
|
// if r.URL.Path != "/hello" {
|
|
// http.Error(w, "404 not found.", http.StatusNotFound)
|
|
// return
|
|
// }
|
|
|
|
// 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 func(w http.ResponseWriter, r *http.Request) {
|
|
// // http.StripPrefix("/Uploads/", handler).ServeHTTP(w, r)
|
|
// // };
|
|
//
|
|
// 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")
|
|
// }
|