1
0
Fork 0
forked from jriou/coller

feat: Encode password

Fixes #38.

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2025-10-02 07:06:54 +02:00
commit de24146991
Signed by: jriou
GPG key ID: 9A099EDA51316854
7 changed files with 42 additions and 20 deletions

View file

@ -28,6 +28,11 @@ type NotePayload struct {
Password string `json:"password"`
}
type NoteResponse struct {
ID int64 `json:"id"`
Message string `json:"message,omitempty"`
}
func handleMain() int {
flag.Usage = usage
@ -134,16 +139,21 @@ func handleMain() int {
return internal.ReturnError(logger, "could not retreive note", err)
}
if r.StatusCode >= 300 {
return internal.ReturnError(logger, "could not retreive note", fmt.Errorf("status code %d", r.StatusCode))
}
logger.Debug("decoding body")
body, err := io.ReadAll(r.Body)
if err != nil {
return internal.ReturnError(logger, "could not read response", err)
}
if r.StatusCode != http.StatusOK {
jsonBody := &NoteResponse{}
err = json.Unmarshal(body, jsonBody)
if err != nil {
return internal.ReturnError(logger, "could not decode response", err)
}
return internal.ReturnError(logger, jsonBody.Message, nil)
}
var content []byte
if *encryptionKey != "" {
logger.Debug("decrypting note")