add tags
This commit is contained in:
@@ -3,22 +3,22 @@ package config
|
||||
import "os"
|
||||
|
||||
type Config struct {
|
||||
Port string
|
||||
DatabaseURL string
|
||||
OCREndpoint string
|
||||
UploadDir string
|
||||
HMACSecret string
|
||||
ServerHost string
|
||||
Port string
|
||||
DatabaseURL string
|
||||
OCREndpoint string
|
||||
UploadDir string
|
||||
HMACSecret string
|
||||
ServerHost string
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
return &Config{
|
||||
Port: envOr("PORT", "8080"),
|
||||
DatabaseURL: envOr("DATABASE_URL", "postgres://localhost:5432/vaultdrop?sslmode=disable"),
|
||||
OCREndpoint: envOr("OCR_ENDPOINT", "http://localhost:9090"),
|
||||
UploadDir: envOr("UPLOAD_DIR", "./uploads"),
|
||||
HMACSecret: envOr("HMAC_SECRET", "thisismyrandomstring"),
|
||||
ServerHost: envOr("SERVER_HOST", "http://192.168.1.17:8080"),
|
||||
Port: envOr("PORT", "8080"),
|
||||
DatabaseURL: envOr("DATABASE_URL", "postgres://localhost:5432/vaultdrop?sslmode=disable"),
|
||||
OCREndpoint: envOr("OCR_ENDPOINT", "http://localhost:9090"),
|
||||
UploadDir: envOr("UPLOAD_DIR", "./uploads"),
|
||||
HMACSecret: envOr("HMAC_SECRET", "thisismyrandomstring"),
|
||||
ServerHost: envOr("SERVER_HOST", "http://192.168.1.17:8080"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,14 +140,20 @@ func (h *FileHandler) AddTags(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
var body struct {
|
||||
Tags []string `json:"tags" binding:"required"`
|
||||
Tags []string `json:"tags" binding:"required"`
|
||||
TagType string `json:"tag_type"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_BODY", "Body must contain a 'tags' array")
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.files.AddTags(id, body.Tags); err != nil {
|
||||
tagType := body.TagType
|
||||
if tagType == "" {
|
||||
tagType = "none"
|
||||
}
|
||||
|
||||
if err := h.files.AddTags(id, body.Tags, tagType); err != nil {
|
||||
api.Error(c, http.StatusInternalServerError, "DB_ERROR", "Failed to add tags")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -122,14 +122,14 @@ func (s *FileService) UpdateOCRText(id, text string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *FileService) AddTags(fileID string, tagNames []string) error {
|
||||
func (s *FileService) AddTags(fileID string, tagNames []string, tagType string) error {
|
||||
for _, name := range tagNames {
|
||||
tag, err := s.queries.GetTagByName(context.Background(), name)
|
||||
if err == sql.ErrNoRows {
|
||||
tag, err = s.queries.CreateTag(context.Background(), db.CreateTagParams{
|
||||
ID: uuid.New().String(),
|
||||
TagName: name,
|
||||
TagType: "none",
|
||||
TagType: tagType,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("create tag %q: %w", name, err)
|
||||
|
||||
Reference in New Issue
Block a user