2026-03-12 23:49:16 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
lint: fix remaining errcheck issues across multiple files
- Fix renderShim errcheck in district.go, image.go
- Fix txn.Rollback/Commit in publicreport.go, notification, review, signal, upload
- Fix addError calls in csv/flyover.go, csv/pool.go
- Fix cW/write calls in logger.go, recoverer.go, voipms.go
- Fix resendInitialText, handleWaitingTextJobs, setPhoneStatus in text/send.go, text.go
- Fix populateDistrictURI/populateReportURI in resource files
2026-05-09 03:06:56 +00:00
|
|
|
"fmt"
|
2026-03-12 23:49:16 +00:00
|
|
|
"io/ioutil"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
2026-05-09 02:21:53 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
2026-03-12 23:49:16 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform/file"
|
|
|
|
|
"github.com/aarondl/opt/omit"
|
|
|
|
|
"github.com/aarondl/opt/omitnull"
|
|
|
|
|
"github.com/google/uuid"
|
2026-04-01 16:57:33 +00:00
|
|
|
"github.com/gorilla/mux"
|
2026-03-12 23:49:16 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func apiImagePost(w http.ResponseWriter, r *http.Request, u platform.User) {
|
2026-04-01 16:57:33 +00:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
|
id := vars["uuid"]
|
2026-03-12 23:49:16 +00:00
|
|
|
noteUUID, err := uuid.Parse(id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, "Failed to decode the uuid", http.StatusBadRequest)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var payload NoteImagePayload
|
|
|
|
|
body, err := ioutil.ReadAll(r.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, "Failed to read the payload", http.StatusBadRequest)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := json.Unmarshal(body, &payload); err != nil {
|
|
|
|
|
//debugSaveRequest(body, err, "Image note POST JSON decode error")
|
|
|
|
|
http.Error(w, "Failed to decode the payload", http.StatusBadRequest)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ctx := r.Context()
|
|
|
|
|
setter := models.NoteImageSetter{
|
2026-03-19 20:49:17 +00:00
|
|
|
Created: omit.From(payload.Created),
|
|
|
|
|
CreatorID: omit.From(int32(u.ID)),
|
|
|
|
|
Deleted: omitnull.FromPtr(payload.Deleted),
|
|
|
|
|
DeletorID: omitnull.FromPtr(payload.DeletorID),
|
2026-03-22 01:22:44 +00:00
|
|
|
OrganizationID: omit.From(u.Organization.ID),
|
2026-03-19 20:49:17 +00:00
|
|
|
Version: omit.From(payload.Version),
|
|
|
|
|
UUID: omit.From(noteUUID),
|
2026-03-12 23:49:16 +00:00
|
|
|
}
|
|
|
|
|
err = platform.NoteImageCreate(ctx, u, setter)
|
|
|
|
|
if err != nil {
|
lint: fix remaining errcheck issues across multiple files
- Fix renderShim errcheck in district.go, image.go
- Fix txn.Rollback/Commit in publicreport.go, notification, review, signal, upload
- Fix addError calls in csv/flyover.go, csv/pool.go
- Fix cW/write calls in logger.go, recoverer.go, voipms.go
- Fix resendInitialText, handleWaitingTextJobs, setPhoneStatus in text/send.go, text.go
- Fix populateDistrictURI/populateReportURI in resource files
2026-05-09 03:06:56 +00:00
|
|
|
if err := renderShim(w, r, errRender(err)); err != nil {
|
|
|
|
|
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
|
|
|
|
}
|
2026-03-12 23:49:16 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
w.WriteHeader(http.StatusAccepted)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func apiImageContentGet(w http.ResponseWriter, r *http.Request, u platform.User) {
|
2026-04-01 16:57:33 +00:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
|
u_str := vars["uuid"]
|
2026-03-12 23:49:16 +00:00
|
|
|
imageUUID, err := uuid.Parse(u_str)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error().Err(err).Msg("Failed to parse image UUID")
|
|
|
|
|
http.Error(w, "Failed to parse image UUID", http.StatusBadRequest)
|
|
|
|
|
}
|
2026-04-01 21:23:28 +00:00
|
|
|
file.ImageFileToWriter(file.CollectionPublicImage, imageUUID, w)
|
2026-03-12 23:49:16 +00:00
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
}
|
|
|
|
|
func apiImageContentPost(w http.ResponseWriter, r *http.Request, u platform.User) {
|
2026-04-01 16:57:33 +00:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
|
u_str := vars["uuid"]
|
2026-03-12 23:49:16 +00:00
|
|
|
imageUUID, err := uuid.Parse(u_str)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error().Err(err).Msg("Failed to parse image UUID")
|
|
|
|
|
http.Error(w, "Failed to parse image UUID", http.StatusBadRequest)
|
|
|
|
|
}
|
2026-04-01 21:23:28 +00:00
|
|
|
err = file.ImageFileFromReader(file.CollectionImageRaw, imageUUID, r.Body)
|
2026-03-12 23:49:16 +00:00
|
|
|
if err != nil {
|
lint: fix remaining errcheck issues across multiple files
- Fix renderShim errcheck in district.go, image.go
- Fix txn.Rollback/Commit in publicreport.go, notification, review, signal, upload
- Fix addError calls in csv/flyover.go, csv/pool.go
- Fix cW/write calls in logger.go, recoverer.go, voipms.go
- Fix resendInitialText, handleWaitingTextJobs, setPhoneStatus in text/send.go, text.go
- Fix populateDistrictURI/populateReportURI in resource files
2026-05-09 03:06:56 +00:00
|
|
|
if err := renderShim(w, r, errRender(err)); err != nil {
|
|
|
|
|
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
|
|
|
|
}
|
2026-03-12 23:49:16 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
log.Printf("Saved image file %s\n", imageUUID)
|
2026-05-09 02:21:53 +00:00
|
|
|
lint.Fprintf(w, "PNG uploaded successfully")
|
2026-03-12 23:49:16 +00:00
|
|
|
}
|