forked from jriou/coller
feat: Encode password
Fixes #38. Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
f721e56371
commit
de24146991
7 changed files with 42 additions and 20 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue