mirror of
				https://github.com/photoprism/photoprism.git
				synced 2025-10-31 04:06:43 +08:00 
			
		
		
		
	 92e6c4fe1e
			
		
	
	92e6c4fe1e
	
	
	
		
			
			Extends DownloadSettings with 4 additional options: - Name: File name pattern for downloaded files (existed) - Disabled: Disables downloads - Originals: Only download files stored in "originals" folder - MediaRaw: Include RAW image files - MediaSidecar: Include metadata sidecar files (JSON, XMP, YAML)
		
			
				
	
	
		
			72 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package api
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"net/http"
 | |
| 
 | |
| 	"github.com/gin-gonic/gin"
 | |
| 
 | |
| 	"github.com/photoprism/photoprism/internal/entity"
 | |
| 	"github.com/photoprism/photoprism/internal/query"
 | |
| 	"github.com/photoprism/photoprism/internal/service"
 | |
| 	"github.com/photoprism/photoprism/pkg/clean"
 | |
| )
 | |
| 
 | |
| // GET /s/:token/...
 | |
| func Shares(router *gin.RouterGroup) {
 | |
| 	router.GET("/:token", func(c *gin.Context) {
 | |
| 		conf := service.Config()
 | |
| 
 | |
| 		token := clean.Token(c.Param("token"))
 | |
| 
 | |
| 		links := entity.FindValidLinks(token, "")
 | |
| 
 | |
| 		if len(links) == 0 {
 | |
| 			log.Warn("share: invalid token")
 | |
| 			c.Redirect(http.StatusTemporaryRedirect, "/")
 | |
| 			return
 | |
| 		}
 | |
| 
 | |
| 		clientConfig := conf.GuestConfig()
 | |
| 		clientConfig.SiteUrl = fmt.Sprintf("%ss/%s", clientConfig.SiteUrl, token)
 | |
| 
 | |
| 		c.HTML(http.StatusOK, "share.tmpl", gin.H{"config": clientConfig})
 | |
| 	})
 | |
| 
 | |
| 	router.GET("/:token/:share", func(c *gin.Context) {
 | |
| 		conf := service.Config()
 | |
| 
 | |
| 		token := clean.Token(c.Param("token"))
 | |
| 		share := clean.Token(c.Param("share"))
 | |
| 
 | |
| 		links := entity.FindValidLinks(token, share)
 | |
| 
 | |
| 		if len(links) < 1 {
 | |
| 			log.Warn("share: invalid token or share")
 | |
| 			c.Redirect(http.StatusTemporaryRedirect, "/")
 | |
| 			return
 | |
| 		}
 | |
| 
 | |
| 		uid := links[0].ShareUID
 | |
| 		clientConfig := conf.GuestConfig()
 | |
| 
 | |
| 		if uid != share {
 | |
| 			c.Redirect(http.StatusPermanentRedirect, fmt.Sprintf("%ss/%s/%s", clientConfig.SiteUrl, token, uid))
 | |
| 			return
 | |
| 		}
 | |
| 
 | |
| 		clientConfig.SiteUrl = fmt.Sprintf("%ss/%s/%s", clientConfig.SiteUrl, token, uid)
 | |
| 		clientConfig.SitePreview = fmt.Sprintf("%s/preview", clientConfig.SiteUrl)
 | |
| 
 | |
| 		if a, err := query.AlbumByUID(uid); err == nil {
 | |
| 			clientConfig.SiteCaption = a.AlbumTitle
 | |
| 
 | |
| 			if a.AlbumDescription != "" {
 | |
| 				clientConfig.SiteDescription = a.AlbumDescription
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		c.HTML(http.StatusOK, "share.tmpl", gin.H{"config": clientConfig})
 | |
| 	})
 | |
| }
 |