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) {
|
2020-06-26 16:11:56 +02:00
|
|
|
// Static assets like js, css and font files.
|
2020-05-31 02:09:52 +02:00
|
|
|
router.Static("/static", conf.StaticPath())
|
2020-07-13 15:23:54 +02:00
|
|
|
router.StaticFile("/favicon.ico", filepath.Join(conf.ImgPath(), "favicon.ico"))
|
2018-09-13 07:05:13 +02:00
|
|
|
|
2020-06-09 14:05:40 +02:00
|
|
|
// Rainbow page.
|
|
|
|
router.GET("/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
|
2019-05-04 13:29:32 +02:00
|
|
|
v1 := router.Group("/api/v1")
|
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)
|
|
|
|
|
|
|
|
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)
|
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)
|
2020-07-13 17:25:27 +02:00
|
|
|
api.LabelThumb(v1)
|
2020-06-25 14:54:04 +02:00
|
|
|
|
|
|
|
api.GetFoldersOriginals(v1)
|
|
|
|
api.GetFoldersImport(v1)
|
|
|
|
|
|
|
|
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)
|
|
|
|
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)
|
2020-07-13 17:25:27 +02:00
|
|
|
api.AlbumThumb(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.
|
|
|
|
s := router.Group("/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 {
|
2020-12-18 10:59:21 +01:00
|
|
|
WebDAV(conf.OriginalsPath(), router.Group("/originals", BasicAuth()), conf)
|
|
|
|
log.Info("webdav: /originals/ enabled, waiting for requests")
|
|
|
|
|
|
|
|
if conf.ImportPath() != "" {
|
|
|
|
WebDAV(conf.ImportPath(), router.Group("/import", BasicAuth()), conf)
|
|
|
|
log.Info("webdav: /import/ enabled, waiting for requests")
|
|
|
|
}
|
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
|
|
|
})
|
|
|
|
}
|