2021-01-08 09:02:30 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2022-09-28 09:01:17 +02:00
|
|
|
|
2022-10-13 22:11:02 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
2023-04-14 18:06:57 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/get"
|
2024-01-07 12:25:56 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/header"
|
2021-01-08 09:02:30 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// AddCountHeader adds the actual result count to the response.
|
|
|
|
func AddCountHeader(c *gin.Context, count int) {
|
|
|
|
c.Header("X-Count", strconv.Itoa(count))
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddLimitHeader adds the max result count to the response.
|
|
|
|
func AddLimitHeader(c *gin.Context, limit int) {
|
|
|
|
c.Header("X-Limit", strconv.Itoa(limit))
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddOffsetHeader adds the result offset to the response.
|
|
|
|
func AddOffsetHeader(c *gin.Context, offset int) {
|
|
|
|
c.Header("X-Offset", strconv.Itoa(offset))
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddDownloadHeader adds a header indicating the response is expected to be downloaded.
|
|
|
|
func AddDownloadHeader(c *gin.Context, fileName string) {
|
2024-01-10 12:21:43 +01:00
|
|
|
c.Header(header.ContentDisposition, fmt.Sprintf("attachment; filename=%s", fileName))
|
2021-01-08 09:02:30 +01:00
|
|
|
}
|
|
|
|
|
2024-01-14 18:28:17 +01:00
|
|
|
// AddAuthTokenHeader adds an X-Auth-Token header to the response.
|
|
|
|
func AddAuthTokenHeader(c *gin.Context, authToken string) {
|
|
|
|
c.Header(header.XAuthToken, authToken)
|
2021-01-08 09:02:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddContentTypeHeader adds a content type header to the response.
|
|
|
|
func AddContentTypeHeader(c *gin.Context, contentType string) {
|
2024-01-10 12:21:43 +01:00
|
|
|
c.Header(header.ContentType, contentType)
|
2021-01-08 09:02:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddFileCountHeaders adds file and folder counts to the response.
|
|
|
|
func AddFileCountHeaders(c *gin.Context, filesCount, foldersCount int) {
|
|
|
|
c.Header("X-Files", strconv.Itoa(filesCount))
|
|
|
|
c.Header("X-Folders", strconv.Itoa(foldersCount))
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddTokenHeaders adds preview token headers to the response.
|
2022-10-13 22:11:02 +02:00
|
|
|
func AddTokenHeaders(c *gin.Context, s *entity.Session) {
|
2023-04-14 18:06:57 +02:00
|
|
|
if get.Config().Public() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-13 22:11:02 +02:00
|
|
|
if s.PreviewToken != "" {
|
|
|
|
c.Header("X-Preview-Token", s.PreviewToken)
|
|
|
|
}
|
|
|
|
if s.DownloadToken != "" {
|
|
|
|
c.Header("X-Download-Token", s.DownloadToken)
|
|
|
|
}
|
2021-01-08 09:02:30 +01:00
|
|
|
}
|