2018-09-13 07:05:13 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2018-10-31 07:14:33 +01:00
|
|
|
"net/http"
|
|
|
|
|
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) {
|
2018-12-21 04:05:14 +01:00
|
|
|
// Favicon
|
2020-05-31 02:09:52 +02:00
|
|
|
router.StaticFile("/favicon.ico", conf.FaviconsPath()+"/favicon.ico")
|
2018-09-13 11:34:56 +02:00
|
|
|
|
2018-09-24 11:27:46 +02:00
|
|
|
// Static assets like js and css files
|
2020-05-31 02:09:52 +02:00
|
|
|
router.Static("/static", conf.StaticPath())
|
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-04-22 10:27:48 +02:00
|
|
|
api.GetStatus(v1, conf)
|
2020-05-29 18:04:30 +02:00
|
|
|
api.GetConfig(v1, conf)
|
2020-04-22 10:27:48 +02:00
|
|
|
|
2019-11-08 06:53:40 +01:00
|
|
|
api.CreateSession(v1, conf)
|
|
|
|
api.DeleteSession(v1, conf)
|
|
|
|
|
2019-12-11 14:10:20 +01:00
|
|
|
api.GetPreview(v1, conf)
|
2019-05-06 23:18:10 +02:00
|
|
|
api.GetThumbnail(v1, conf)
|
2019-05-14 18:16:35 +02:00
|
|
|
api.GetDownload(v1, conf)
|
2020-05-13 15:36:42 +02:00
|
|
|
api.GetVideo(v1, conf)
|
2019-12-05 19:21:35 +01:00
|
|
|
api.CreateZip(v1, conf)
|
|
|
|
api.DownloadZip(v1, conf)
|
2019-06-09 04:37:02 +02:00
|
|
|
|
2020-01-15 04:04:33 +01:00
|
|
|
api.GetGeo(v1, conf)
|
2019-12-11 19:11:44 +01:00
|
|
|
api.GetPhoto(v1, conf)
|
2020-05-18 22:18:58 +02:00
|
|
|
api.GetPhotoYaml(v1, conf)
|
2019-12-11 19:11:44 +01:00
|
|
|
api.UpdatePhoto(v1, conf)
|
2019-06-09 04:37:02 +02:00
|
|
|
api.GetPhotos(v1, conf)
|
2019-12-05 21:06:53 +01:00
|
|
|
api.GetPhotoDownload(v1, conf)
|
2020-04-08 13:24:06 +02:00
|
|
|
api.LinkPhoto(v1, conf)
|
2019-05-06 23:18:10 +02:00
|
|
|
api.LikePhoto(v1, conf)
|
|
|
|
api.DislikePhoto(v1, conf)
|
2020-01-29 15:28:20 +01:00
|
|
|
api.AddPhotoLabel(v1, conf)
|
|
|
|
api.RemovePhotoLabel(v1, conf)
|
2020-04-17 21:20:38 +02:00
|
|
|
api.UpdatePhotoLabel(v1, conf)
|
2020-01-23 20:05:54 +01:00
|
|
|
api.GetMomentsTime(v1, conf)
|
2020-02-26 17:50:28 +01:00
|
|
|
api.GetFile(v1, conf)
|
2020-04-08 13:24:06 +02:00
|
|
|
api.LinkFile(v1, conf)
|
2020-04-21 10:23:27 +02:00
|
|
|
api.SetPhotoPrimary(v1, conf)
|
2019-06-09 04:37:02 +02:00
|
|
|
|
|
|
|
api.GetLabels(v1, conf)
|
2020-02-02 02:00:47 +01:00
|
|
|
api.UpdateLabel(v1, conf)
|
2020-04-08 13:24:06 +02:00
|
|
|
api.LinkLabel(v1, conf)
|
2019-06-09 04:37:02 +02:00
|
|
|
api.LikeLabel(v1, conf)
|
|
|
|
api.DislikeLabel(v1, conf)
|
|
|
|
api.LabelThumbnail(v1, conf)
|
2019-06-13 20:26:01 +02:00
|
|
|
|
2020-05-22 16:29:12 +02:00
|
|
|
api.GetFoldersOriginals(v1, conf)
|
|
|
|
api.GetFoldersImport(v1, conf)
|
|
|
|
|
2019-06-13 20:26:01 +02:00
|
|
|
api.Upload(v1, conf)
|
2020-01-02 03:57:28 +01:00
|
|
|
api.StartImport(v1, conf)
|
|
|
|
api.CancelImport(v1, conf)
|
2020-01-02 02:58:26 +01:00
|
|
|
api.StartIndexing(v1, conf)
|
|
|
|
api.CancelIndexing(v1, conf)
|
2019-06-15 01:35:18 +02:00
|
|
|
|
2020-01-09 02:09:54 +01:00
|
|
|
api.BatchPhotosArchive(v1, conf)
|
2020-01-06 05:45:03 +01:00
|
|
|
api.BatchPhotosRestore(v1, conf)
|
2019-06-15 03:44:10 +02:00
|
|
|
api.BatchPhotosPrivate(v1, conf)
|
2019-12-06 16:47:30 +01:00
|
|
|
api.BatchAlbumsDelete(v1, conf)
|
2020-02-04 05:18:22 +01:00
|
|
|
api.BatchLabelsDelete(v1, conf)
|
2019-06-17 21:45:06 +02:00
|
|
|
|
2019-12-05 14:11:45 +01:00
|
|
|
api.GetAlbum(v1, conf)
|
2019-12-06 11:56:24 +01:00
|
|
|
api.CreateAlbum(v1, conf)
|
|
|
|
api.UpdateAlbum(v1, conf)
|
|
|
|
api.DeleteAlbum(v1, conf)
|
2019-12-06 16:47:30 +01:00
|
|
|
api.DownloadAlbum(v1, conf)
|
2019-06-17 21:45:06 +02:00
|
|
|
api.GetAlbums(v1, conf)
|
2020-04-08 13:24:06 +02:00
|
|
|
api.LinkAlbum(v1, conf)
|
2019-06-17 21:45:06 +02:00
|
|
|
api.LikeAlbum(v1, conf)
|
|
|
|
api.DislikeAlbum(v1, conf)
|
|
|
|
api.AlbumThumbnail(v1, conf)
|
2019-12-05 12:10:30 +01:00
|
|
|
api.AddPhotosToAlbum(v1, conf)
|
|
|
|
api.RemovePhotosFromAlbum(v1, conf)
|
2019-11-12 04:34:37 +01:00
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
api.GetAccounts(v1, conf)
|
|
|
|
api.GetAccount(v1, conf)
|
2020-04-02 18:17:07 +02:00
|
|
|
api.GetAccountDirs(v1, conf)
|
2020-04-01 12:00:45 +02:00
|
|
|
api.ShareWithAccount(v1, conf)
|
2020-03-28 15:29:17 +01:00
|
|
|
api.CreateAccount(v1, conf)
|
|
|
|
api.DeleteAccount(v1, conf)
|
|
|
|
api.UpdateAccount(v1, conf)
|
|
|
|
|
2019-11-12 04:34:37 +01:00
|
|
|
api.GetSettings(v1, conf)
|
|
|
|
api.SaveSettings(v1, conf)
|
2019-11-16 16:06:34 +01:00
|
|
|
|
2020-01-24 01:33:04 +01:00
|
|
|
api.GetSvg(v1)
|
|
|
|
|
2019-11-16 16:06:34 +01:00
|
|
|
api.Websocket(v1, conf)
|
2018-09-13 07:05:13 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 04:23:16 +01:00
|
|
|
// WebDAV server for file management / sharing
|
|
|
|
if conf.WebDAVPassword() != "" {
|
|
|
|
log.Info("webdav: enabled, username: photoprism")
|
|
|
|
|
|
|
|
WebDAV(conf.OriginalsPath(), router.Group("/originals", gin.BasicAuth(gin.Accounts{
|
|
|
|
"photoprism": conf.WebDAVPassword(),
|
|
|
|
})), conf)
|
|
|
|
|
2020-04-14 18:13:37 +02:00
|
|
|
log.Info("webdav: /originals/ available")
|
2020-02-21 04:23:16 +01:00
|
|
|
|
|
|
|
if conf.ReadOnly() {
|
2020-04-14 18:13:37 +02:00
|
|
|
log.Info("webdav: /import/ not available in read-only mode")
|
2020-02-21 04:23:16 +01:00
|
|
|
} else {
|
|
|
|
WebDAV(conf.ImportPath(), router.Group("/import", gin.BasicAuth(gin.Accounts{
|
|
|
|
"photoprism": conf.WebDAVPassword(),
|
|
|
|
})), conf)
|
|
|
|
|
2020-04-14 18:13:37 +02:00
|
|
|
log.Info("webdav: /import/ available")
|
2020-02-21 04:23:16 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Info("webdav: disabled (no password set)")
|
|
|
|
}
|
|
|
|
|
2018-09-24 11:27:46 +02:00
|
|
|
// Default HTML page (client-side routing implemented via Vue.js)
|
2019-05-04 13:29:32 +02:00
|
|
|
router.NoRoute(func(c *gin.Context) {
|
2020-05-23 20:58:58 +02:00
|
|
|
clientConfig := conf.PublicClientConfig()
|
2020-05-31 02:09:52 +02:00
|
|
|
c.HTML(http.StatusOK, conf.DefaultTemplate(), gin.H{"config": clientConfig})
|
2018-09-13 07:05:13 +02:00
|
|
|
})
|
|
|
|
}
|