fix
This commit is contained in:
1 parent
feebf7d3c1
commit
486502852e
41 files changed
+1311
-259
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/catalog"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/company"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/feeds"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/processing"
|
||||
"github.com/go-chi/chi/v5"
|
||||
@@ -53,11 +54,16 @@ func (s *Server) handleCreateFeed(w http.ResponseWriter, r *http.Request) {
|
||||
FeedType string `json:"feed_type"`
|
||||
SyncIntervalMinutes int `json:"sync_interval_minutes"`
|
||||
RequestHeaders map[string]string `json:"request_headers"`
|
||||
ContentLanguage string `json:"content_language"`
|
||||
}
|
||||
if err := DecodeJSON(r, &body); err != nil {
|
||||
Error(w, http.StatusBadRequest, "invalid json")
|
||||
return
|
||||
}
|
||||
if body.ContentLanguage != "" && !company.IsAllowedLanguage(body.ContentLanguage) {
|
||||
Error(w, http.StatusBadRequest, "unsupported content language")
|
||||
return
|
||||
}
|
||||
item, err := s.Feeds.Create(r.Context(), cid, feeds.CreateInput{
|
||||
Name: body.Name,
|
||||
URL: body.URL,
|
||||
@@ -65,6 +71,7 @@ func (s *Server) handleCreateFeed(w http.ResponseWriter, r *http.Request) {
|
||||
FeedType: body.FeedType,
|
||||
SyncIntervalMinutes: body.SyncIntervalMinutes,
|
||||
RequestHeaders: body.RequestHeaders,
|
||||
ContentLanguage: company.NormalizeLanguage(body.ContentLanguage),
|
||||
})
|
||||
if err != nil {
|
||||
ClientOrLog(w, http.StatusBadRequest, "could not create feed", err, feeds.ClientError)
|
||||
@@ -84,6 +91,11 @@ func (s *Server) createFeedFromMultipart(w http.ResponseWriter, r *http.Request,
|
||||
feedType := strings.TrimSpace(r.FormValue("feed_type"))
|
||||
itemPath := strings.TrimSpace(r.FormValue("item_path"))
|
||||
interval, _ := strconv.Atoi(strings.TrimSpace(r.FormValue("sync_interval_minutes")))
|
||||
contentLanguage := strings.TrimSpace(r.FormValue("content_language"))
|
||||
if contentLanguage != "" && !company.IsAllowedLanguage(contentLanguage) {
|
||||
Error(w, http.StatusBadRequest, "unsupported content language")
|
||||
return
|
||||
}
|
||||
headers := map[string]string{}
|
||||
if raw := strings.TrimSpace(r.FormValue("request_headers")); raw != "" {
|
||||
if err := json.Unmarshal([]byte(raw), &headers); err != nil {
|
||||
@@ -147,6 +159,7 @@ func (s *Server) createFeedFromMultipart(w http.ResponseWriter, r *http.Request,
|
||||
SyncIntervalMinutes: interval,
|
||||
Options: options,
|
||||
RequestHeaders: headers,
|
||||
ContentLanguage: company.NormalizeLanguage(contentLanguage),
|
||||
})
|
||||
if err != nil {
|
||||
ClientOrLog(w, http.StatusBadRequest, "could not create feed", err, feeds.ClientError)
|
||||
@@ -186,6 +199,13 @@ func (s *Server) handleUpdateFeed(w http.ResponseWriter, r *http.Request) {
|
||||
Error(w, http.StatusBadRequest, "invalid json")
|
||||
return
|
||||
}
|
||||
if raw, exists := body["content_language"]; exists {
|
||||
code, ok := raw.(string)
|
||||
if !ok || (code != "" && !company.IsAllowedLanguage(code)) {
|
||||
Error(w, http.StatusBadRequest, "unsupported content language")
|
||||
return
|
||||
}
|
||||
}
|
||||
item, err := s.Feeds.Update(r.Context(), cid, id, body)
|
||||
if err != nil {
|
||||
if feeds.IsNotFound(err) {
|
||||
|
||||
Reference in new issue
Block a user