2018-09-13 07:05:13 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2018-10-31 07:14:33 +01:00
|
|
|
"net/http"
|
2020-07-13 15:23:54 +02:00
|
|
|
"path/filepath"
|
2018-10-31 07:14:33 +01:00
|
|
|
|
2018-09-13 07:05:13 +02:00
|
|
|
"github.com/gin-gonic/gin"
|
2022-07-05 23:13:34 +02:00
|
|
|
|
2018-09-24 21:14:15 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/api"
|
2019-05-06 23:18:10 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2022-07-05 23:13:34 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
2018-09-13 07:05:13 +02:00
|
|
|
)
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
func registerRoutes(router *gin.Engine, conf *config.Config) {
|
2022-01-05 11:40:44 +01:00
|
|
|
// Enables automatic redirection if the current route cannot be matched but a
|
2021-01-02 18:56:15 +01:00
|
|
|
// handler for the path with (without) the trailing slash exists.
|
|
|
|
router.RedirectTrailingSlash = true
|
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
// Static assets like js, css and font files.
|
2021-07-05 16:41:43 +02:00
|
|
|
router.Static(conf.BaseUri(config.StaticUri), conf.StaticPath())
|
|
|
|
router.StaticFile(conf.BaseUri("/favicon.ico"), filepath.Join(conf.ImgPath(), "favicon.ico"))
|
2018-09-13 07:05:13 +02:00
|
|
|
|
2021-07-05 16:41:43 +02:00
|
|
|
// PWA Manifest.
|
|
|
|
router.GET(conf.BaseUri("/manifest.json"), func(c *gin.Context) {
|
|
|
|
c.Header("Cache-Control", "no-store")
|
|
|
|
c.Header("Content-Type", "application/json")
|
|
|
|
|
|
|
|
clientConfig := conf.PublicConfig()
|
|
|
|
c.HTML(http.StatusOK, "manifest.json", gin.H{"config": clientConfig})
|
|
|
|
})
|
|
|
|
|
|
|
|
// PWA Service Worker.
|
|
|
|
router.GET(conf.BaseUri("/sw.js"), func(c *gin.Context) {
|
2021-01-08 19:11:50 +01:00
|
|
|
c.Header("Cache-Control", "no-store")
|
|
|
|
c.File(filepath.Join(conf.BuildPath(), "sw.js"))
|
|
|
|
})
|
|
|
|
|
2021-07-05 16:41:43 +02:00
|
|
|
// Rainbow Page.
|
2022-05-27 18:15:18 +02:00
|
|
|
router.GET(conf.BaseUri("/_rainbow"), func(c *gin.Context) {
|
2020-06-22 20:15:08 +02:00
|
|
|
clientConfig := conf.PublicConfig()
|
2020-06-09 14:05:40 +02:00
|
|
|
c.HTML(http.StatusOK, "rainbow.tmpl", gin.H{"config": clientConfig})
|
|
|
|
})
|
|
|
|
|
2022-05-27 18:15:18 +02:00
|
|
|
// Splash Screen.
|
|
|
|
router.GET(conf.BaseUri("/_splash"), func(c *gin.Context) {
|
|
|
|
clientConfig := conf.PublicConfig()
|
|
|
|
c.HTML(http.StatusOK, "splash.tmpl", gin.H{"config": clientConfig})
|
|
|
|
})
|
|
|
|
|
2018-09-13 07:05:13 +02:00
|
|
|
// JSON-REST API Version 1
|
2021-07-05 16:41:43 +02:00
|
|
|
v1 := router.Group(conf.BaseUri(config.ApiUri))
|
2018-09-13 07:05:13 +02:00
|
|
|
{
|
2021-09-18 15:32:39 +02:00
|
|
|
// Config options.
|
2020-12-19 01:54:29 +01:00
|
|
|
api.GetConfig(v1)
|
2020-12-18 20:42:12 +01:00
|
|
|
api.GetConfigOptions(v1)
|
|
|
|
api.SaveConfigOptions(v1)
|
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// User profile and settings.
|
2020-12-18 20:42:12 +01:00
|
|
|
api.GetSettings(v1)
|
|
|
|
api.SaveSettings(v1)
|
|
|
|
api.ChangePassword(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.CreateSession(v1)
|
|
|
|
api.DeleteSession(v1)
|
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// External account management.
|
|
|
|
api.SearchAccounts(v1)
|
|
|
|
api.GetAccount(v1)
|
|
|
|
api.GetAccountFolders(v1)
|
|
|
|
api.ShareWithAccount(v1)
|
|
|
|
api.CreateAccount(v1)
|
|
|
|
api.DeleteAccount(v1)
|
|
|
|
api.UpdateAccount(v1)
|
|
|
|
|
|
|
|
// Thumbnails and downloads.
|
2020-07-13 17:25:27 +02:00
|
|
|
api.GetThumb(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.GetDownload(v1)
|
|
|
|
api.GetVideo(v1)
|
2022-07-21 15:16:20 +02:00
|
|
|
api.ZipCreate(v1)
|
|
|
|
api.ZipDownload(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// Photos.
|
|
|
|
api.SearchPhotos(v1)
|
2021-11-26 13:59:10 +01:00
|
|
|
api.SearchGeo(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.GetPhoto(v1)
|
|
|
|
api.GetPhotoYaml(v1)
|
|
|
|
api.UpdatePhoto(v1)
|
|
|
|
api.GetPhotoDownload(v1)
|
|
|
|
api.GetPhotoLinks(v1)
|
|
|
|
api.CreatePhotoLink(v1)
|
|
|
|
api.UpdatePhotoLink(v1)
|
|
|
|
api.DeletePhotoLink(v1)
|
|
|
|
api.ApprovePhoto(v1)
|
|
|
|
api.LikePhoto(v1)
|
|
|
|
api.DislikePhoto(v1)
|
|
|
|
api.AddPhotoLabel(v1)
|
|
|
|
api.RemovePhotoLabel(v1)
|
|
|
|
api.UpdatePhotoLabel(v1)
|
|
|
|
api.GetMomentsTime(v1)
|
|
|
|
api.GetFile(v1)
|
2020-10-04 14:21:40 +02:00
|
|
|
api.DeleteFile(v1)
|
2021-08-21 16:36:00 +02:00
|
|
|
api.UpdateMarker(v1)
|
|
|
|
api.ClearMarkerSubject(v1)
|
2020-07-14 11:00:49 +02:00
|
|
|
api.PhotoPrimary(v1)
|
|
|
|
api.PhotoUnstack(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// Albums.
|
|
|
|
api.SearchAlbums(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.GetAlbum(v1)
|
2021-09-18 15:32:39 +02:00
|
|
|
api.AlbumCover(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.CreateAlbum(v1)
|
|
|
|
api.UpdateAlbum(v1)
|
|
|
|
api.DeleteAlbum(v1)
|
|
|
|
api.DownloadAlbum(v1)
|
|
|
|
api.GetAlbumLinks(v1)
|
|
|
|
api.CreateAlbumLink(v1)
|
|
|
|
api.UpdateAlbumLink(v1)
|
|
|
|
api.DeleteAlbumLink(v1)
|
|
|
|
api.LikeAlbum(v1)
|
|
|
|
api.DislikeAlbum(v1)
|
|
|
|
api.CloneAlbums(v1)
|
|
|
|
api.AddPhotosToAlbum(v1)
|
|
|
|
api.RemovePhotosFromAlbum(v1)
|
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// Labels.
|
|
|
|
api.SearchLabels(v1)
|
|
|
|
api.LabelCover(v1)
|
|
|
|
api.UpdateLabel(v1)
|
|
|
|
api.GetLabelLinks(v1)
|
|
|
|
api.CreateLabelLink(v1)
|
|
|
|
api.UpdateLabelLink(v1)
|
|
|
|
api.DeleteLabelLink(v1)
|
|
|
|
api.LikeLabel(v1)
|
|
|
|
api.DislikeLabel(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// Folders.
|
2021-11-26 14:28:50 +01:00
|
|
|
api.SearchFoldersOriginals(v1)
|
|
|
|
api.SearchFoldersImport(v1)
|
2021-09-18 15:32:39 +02:00
|
|
|
api.FolderCover(v1)
|
2019-11-16 16:06:34 +01:00
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// People and other subjects.
|
|
|
|
api.SearchSubjects(v1)
|
|
|
|
api.GetSubject(v1)
|
|
|
|
api.UpdateSubject(v1)
|
|
|
|
api.LikeSubject(v1)
|
|
|
|
api.DislikeSubject(v1)
|
|
|
|
|
|
|
|
// Faces.
|
|
|
|
api.SearchFaces(v1)
|
|
|
|
api.GetFace(v1)
|
|
|
|
api.UpdateFace(v1)
|
2020-01-24 01:33:04 +01:00
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// Indexing and importing.
|
|
|
|
api.Upload(v1)
|
|
|
|
api.StartImport(v1)
|
|
|
|
api.CancelImport(v1)
|
|
|
|
api.StartIndexing(v1)
|
|
|
|
api.CancelIndexing(v1)
|
|
|
|
|
|
|
|
// Batch operations.
|
|
|
|
api.BatchPhotosApprove(v1)
|
|
|
|
api.BatchPhotosArchive(v1)
|
|
|
|
api.BatchPhotosRestore(v1)
|
|
|
|
api.BatchPhotosPrivate(v1)
|
|
|
|
api.BatchPhotosDelete(v1)
|
|
|
|
api.BatchAlbumsDelete(v1)
|
|
|
|
api.BatchLabelsDelete(v1)
|
|
|
|
|
|
|
|
// Other.
|
|
|
|
api.GetSvg(v1)
|
|
|
|
api.GetStatus(v1)
|
|
|
|
api.GetErrors(v1)
|
2022-04-03 12:37:43 +02:00
|
|
|
api.DeleteErrors(v1)
|
2021-09-18 15:32:39 +02:00
|
|
|
api.SendFeedback(v1)
|
2022-07-19 16:58:43 +02:00
|
|
|
api.Connect(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.Websocket(v1)
|
2018-09-13 07:05:13 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 14:26:36 +02:00
|
|
|
// Configure link sharing.
|
2021-07-05 16:41:43 +02:00
|
|
|
s := router.Group(conf.BaseUri("/s"))
|
2020-06-22 20:15:08 +02:00
|
|
|
{
|
2020-06-26 14:26:36 +02:00
|
|
|
api.Shares(s)
|
|
|
|
api.SharePreview(s)
|
2020-06-22 20:15:08 +02:00
|
|
|
}
|
|
|
|
|
2020-06-09 14:05:40 +02:00
|
|
|
// WebDAV server for file management, sync and sharing.
|
2020-12-18 10:59:21 +01:00
|
|
|
if conf.DisableWebDAV() {
|
|
|
|
log.Info("webdav: server disabled")
|
2020-02-21 04:23:16 +01:00
|
|
|
} else {
|
2021-07-05 16:41:43 +02:00
|
|
|
WebDAV(conf.OriginalsPath(), router.Group(conf.BaseUri(WebDAVOriginals), BasicAuth()), conf)
|
|
|
|
log.Infof("webdav: %s/ enabled, waiting for requests", conf.BaseUri(WebDAVOriginals))
|
2020-12-18 10:59:21 +01:00
|
|
|
|
|
|
|
if conf.ImportPath() != "" {
|
2021-07-05 16:41:43 +02:00
|
|
|
WebDAV(conf.ImportPath(), router.Group(conf.BaseUri(WebDAVImport), BasicAuth()), conf)
|
|
|
|
log.Infof("webdav: %s/ enabled, waiting for requests", conf.BaseUri(WebDAVImport))
|
2020-12-18 10:59:21 +01:00
|
|
|
}
|
2020-02-21 04:23:16 +01:00
|
|
|
}
|
|
|
|
|
2022-07-05 23:13:34 +02:00
|
|
|
// Initialize package extensions.
|
|
|
|
for _, ext := range Extensions() {
|
|
|
|
if err := ext.init(router, conf); err != nil {
|
|
|
|
log.Warnf("server: failed to initialize extension %s (%s)", clean.Log(ext.name), err)
|
|
|
|
} else {
|
|
|
|
log.Debugf("server: extension %s initialized", clean.Log(ext.name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 14:05:40 +02:00
|
|
|
// Default HTML page for client-side rendering and routing via VueJS.
|
2019-05-04 13:29:32 +02:00
|
|
|
router.NoRoute(func(c *gin.Context) {
|
2021-11-25 17:24:53 +01:00
|
|
|
signUp := gin.H{"message": config.MsgSponsor, "url": config.SignUpURL}
|
|
|
|
values := gin.H{"signUp": signUp, "config": conf.PublicConfig()}
|
|
|
|
c.HTML(http.StatusOK, conf.TemplateName(), values)
|
2018-09-13 07:05:13 +02:00
|
|
|
})
|
|
|
|
}
|