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"
|
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"
|
2018-09-13 07:05:13 +02:00
|
|
|
)
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
func registerRoutes(router *gin.Engine, conf *config.Config) {
|
2021-01-02 18:56:15 +01:00
|
|
|
// Enables automatic redirection if the current route can't be matched but a
|
|
|
|
// 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.
|
|
|
|
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})
|
|
|
|
})
|
|
|
|
|
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
|
|
|
{
|
2020-06-25 14:54:04 +02:00
|
|
|
api.GetStatus(v1)
|
2020-12-18 20:42:12 +01:00
|
|
|
api.GetErrors(v1)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
api.GetSettings(v1)
|
|
|
|
api.SaveSettings(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
|
2020-12-18 20:42:12 +01:00
|
|
|
api.ChangePassword(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.CreateSession(v1)
|
|
|
|
api.DeleteSession(v1)
|
|
|
|
|
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)
|
|
|
|
api.CreateZip(v1)
|
|
|
|
api.DownloadZip(v1)
|
|
|
|
|
|
|
|
api.GetGeo(v1)
|
|
|
|
api.GetPhoto(v1)
|
|
|
|
api.GetPhotoYaml(v1)
|
|
|
|
api.UpdatePhoto(v1)
|
|
|
|
api.GetPhotos(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-06-02 17:25:04 +02:00
|
|
|
api.UpdateFileMarker(v1)
|
2020-07-14 11:00:49 +02:00
|
|
|
api.PhotoPrimary(v1)
|
|
|
|
api.PhotoUnstack(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
|
|
|
|
api.GetLabels(v1)
|
|
|
|
api.UpdateLabel(v1)
|
|
|
|
api.GetLabelLinks(v1)
|
|
|
|
api.CreateLabelLink(v1)
|
|
|
|
api.UpdateLabelLink(v1)
|
|
|
|
api.DeleteLabelLink(v1)
|
|
|
|
api.LikeLabel(v1)
|
|
|
|
api.DislikeLabel(v1)
|
2021-01-08 12:20:41 +01:00
|
|
|
api.LabelCover(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
|
|
|
|
api.GetFoldersOriginals(v1)
|
|
|
|
api.GetFoldersImport(v1)
|
2021-02-07 19:04:17 +01:00
|
|
|
api.GetFolderCover(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
|
|
|
|
api.Upload(v1)
|
|
|
|
api.StartImport(v1)
|
|
|
|
api.CancelImport(v1)
|
|
|
|
api.StartIndexing(v1)
|
|
|
|
api.CancelIndexing(v1)
|
|
|
|
|
2020-11-21 17:36:41 +01:00
|
|
|
api.BatchPhotosApprove(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.BatchPhotosArchive(v1)
|
|
|
|
api.BatchPhotosRestore(v1)
|
|
|
|
api.BatchPhotosPrivate(v1)
|
2021-01-24 15:28:59 +01:00
|
|
|
api.BatchPhotosDelete(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.BatchAlbumsDelete(v1)
|
|
|
|
api.BatchLabelsDelete(v1)
|
|
|
|
|
|
|
|
api.GetAlbum(v1)
|
|
|
|
api.CreateAlbum(v1)
|
|
|
|
api.UpdateAlbum(v1)
|
|
|
|
api.DeleteAlbum(v1)
|
|
|
|
api.DownloadAlbum(v1)
|
|
|
|
api.GetAlbums(v1)
|
|
|
|
api.GetAlbumLinks(v1)
|
|
|
|
api.CreateAlbumLink(v1)
|
|
|
|
api.UpdateAlbumLink(v1)
|
|
|
|
api.DeleteAlbumLink(v1)
|
|
|
|
api.LikeAlbum(v1)
|
|
|
|
api.DislikeAlbum(v1)
|
2021-01-08 12:20:41 +01:00
|
|
|
api.AlbumCover(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.CloneAlbums(v1)
|
|
|
|
api.AddPhotosToAlbum(v1)
|
|
|
|
api.RemovePhotosFromAlbum(v1)
|
|
|
|
|
|
|
|
api.GetAccounts(v1)
|
|
|
|
api.GetAccount(v1)
|
2020-06-30 12:58:56 +02:00
|
|
|
api.GetAccountFolders(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
api.ShareWithAccount(v1)
|
|
|
|
api.CreateAccount(v1)
|
|
|
|
api.DeleteAccount(v1)
|
|
|
|
api.UpdateAccount(v1)
|
|
|
|
|
2020-10-04 22:22:53 +02:00
|
|
|
api.SendFeedback(v1)
|
2019-11-16 16:06:34 +01:00
|
|
|
|
2020-01-24 01:33:04 +01:00
|
|
|
api.GetSvg(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
|
|
|
}
|
|
|
|
|
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) {
|
2020-06-22 20:15:08 +02:00
|
|
|
clientConfig := conf.PublicConfig()
|
2020-06-26 16:11:56 +02:00
|
|
|
c.HTML(http.StatusOK, conf.TemplateName(), gin.H{"config": clientConfig})
|
2018-09-13 07:05:13 +02:00
|
|
|
})
|
|
|
|
}
|