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

@ -38,7 +38,6 @@ type NotePayload struct {
type NoteResponse struct {
ID int64 `json:"id"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
}
type Config struct {
@ -192,8 +191,12 @@ func handleMain() int {
}
logger.Debug("encoding content")
encoded := internal.Encode(content)
p.Content = encoded
encodedContent := internal.Encode(content)
p.Content = encodedContent
logger.Debug("encoding password")
encodedPassword := internal.Encode([]byte(*password))
p.Password = encodedPassword
payload, err := json.Marshal(p)
if err != nil {
@ -241,7 +244,7 @@ func handleMain() int {
}
if r.StatusCode != http.StatusOK {
return internal.ReturnError(logger, jsonBody.Message, fmt.Errorf("%s", jsonBody.Error))
return internal.ReturnError(logger, jsonBody.Message, nil)
}
logger.Debug("finding note location")

View file

@ -82,7 +82,7 @@ Return content of a note encrypted by the given encryption key.
Return content of a protected note encrypted by the given encryption key.
Body (JSON):
* **password** (string): password used to protect the note (required)
* **password** (string): base64 encoded password used to protect the note (required)
### GET /api/note/\<id\>
@ -97,7 +97,7 @@ Return content of a protected note.
If the note is encrypted, the encrypted value is returned (application/octet-stream). Otherwise, the text is returned (text/plain).
Body (JSON):
* **password** (string): password used to protect the note (required)
* **password** (string): base64 encoded password used to protect the note (required)
### Errors

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")