diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 490cca3..27937a4 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,10 @@
-
+
-
+
+
@@ -112,7 +113,6 @@
-
@@ -137,7 +137,8 @@
-
+
+
true
diff --git a/pkg/internal/models/pools.go b/pkg/internal/models/pools.go
index 49009e8..46f0780 100644
--- a/pkg/internal/models/pools.go
+++ b/pkg/internal/models/pools.go
@@ -21,4 +21,5 @@ type AttachmentPoolConfig struct {
ExistLifecycle *int64 `json:"exist_lifecycle"`
AllowCrossPoolIngress bool `json:"allow_cross_pool_ingress"`
AllowCrossPoolEgress bool `json:"allow_cross_pool_egress"`
+ PublicIndexable bool `json:"public_indexable"`
}
diff --git a/pkg/internal/server/api/attachment_dir_api.go b/pkg/internal/server/api/index_api.go
similarity index 73%
rename from pkg/internal/server/api/attachment_dir_api.go
rename to pkg/internal/server/api/index_api.go
index 2e1d24b..efec1bb 100644
--- a/pkg/internal/server/api/attachment_dir_api.go
+++ b/pkg/internal/server/api/index_api.go
@@ -1,6 +1,9 @@
package api
import (
+ "fmt"
+ "github.com/spf13/viper"
+ "gorm.io/datatypes"
"strings"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
@@ -41,6 +44,12 @@ func listAttachment(c *fiber.Ctx) error {
// Do sort this when doesn't filter by the id
// Because the sort will mess up the result
tx = tx.Order("created_at DESC")
+
+ // Do not expose un-public indexable attachments
+ prefix := viper.GetString("database.prefix")
+ tx = tx.
+ Joins(fmt.Sprintf("JOIN %sattachment_pools ON %sattachment_pools.id = %sattachments.pool_id", prefix, prefix, prefix)).
+ Where(datatypes.JSONQuery(fmt.Sprintf("%sattachment_pools.config", prefix)).Equals(true, "public_indexable"))
}
if len(c.Query("author")) > 0 {
@@ -52,8 +61,12 @@ func listAttachment(c *fiber.Ctx) error {
}
}
- if usage := c.Query("usage"); len(usage) > 0 {
- tx = tx.Where("usage IN ?", strings.Split(usage, " "))
+ if pools := c.Query("pools"); len(pools) > 0 {
+ prefix := viper.GetString("database.prefix")
+ poolAliases := strings.Split(pools, ",")
+ tx = tx.
+ Joins(fmt.Sprintf("JOIN %sattachment_pools ON %sattachment_pools.id = %sattachments.pool_id", prefix, prefix, prefix)).
+ Where(fmt.Sprintf("%sattachment_pools.alias IN ?", prefix), poolAliases)
}
if original := c.QueryBool("original", false); original {