Skip to content

Commit

Permalink
Backend: Repond with new URL when changing image notes and extended d…
Browse files Browse the repository at this point in the history
…escription
  • Loading branch information
AgustinSRG committed Oct 17, 2024
1 parent b0446d9 commit 2f4c118
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
21 changes: 20 additions & 1 deletion backend/api_media_extended_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"encoding/json"
"fmt"
"net/http"
"os"
"strconv"
Expand All @@ -15,6 +16,10 @@ type ExtendedDescriptionSetBody struct {
ExtendedDescription string `json:"ext_desc"`
}

type ExtendedDescriptionSetResponse struct {
Url string `json:"url"`
}

func api_setExtendedDescription(response http.ResponseWriter, request *http.Request) {
session := GetSessionFromRequest(request)

Expand Down Expand Up @@ -47,6 +52,10 @@ func api_setExtendedDescription(response http.ResponseWriter, request *http.Requ

assetData := []byte(p.ExtendedDescription)

result := ThumbnailAPIResponse{
Url: "",
}

if len(assetData) > 0 {
// Encrypt the description file

Expand Down Expand Up @@ -146,6 +155,7 @@ func api_setExtendedDescription(response http.ResponseWriter, request *http.Requ

meta.HasExtendedDescription = true
meta.ExtendedDescriptionAsset = desc_asset
result.Url = "/assets/b/" + fmt.Sprint(media_id) + "/" + fmt.Sprint(desc_asset) + "/ext_desc.txt" + "?fp=" + GetVault().credentials.GetFingerprint()

// Save
err = media.EndWrite(meta, session.key, false)
Expand Down Expand Up @@ -226,5 +236,14 @@ func api_setExtendedDescription(response http.ResponseWriter, request *http.Requ

// Response

response.WriteHeader(200)
jsonResult, err := json.Marshal(result)

if err != nil {
LogError(err)

ReturnAPIError(response, 500, "INTERNAL_ERROR", "Internal server error, Check the logs for details.")
return
}

ReturnAPI_JSON(response, request, jsonResult)
}
21 changes: 20 additions & 1 deletion backend/api_media_image_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"encoding/json"
"fmt"
"net/http"
"os"
"strconv"
Expand All @@ -19,6 +20,10 @@ type ImageNote struct {
Text string `json:"text"`
}

type ImageNotesSetResponse struct {
Url string `json:"url"`
}

func api_setImageNotes(response http.ResponseWriter, request *http.Request) {
session := GetSessionFromRequest(request)

Expand Down Expand Up @@ -58,6 +63,10 @@ func api_setImageNotes(response http.ResponseWriter, request *http.Request) {
return
}

result := ImageNotesSetResponse{
Url: "",
}

// Encrypt the notes file

notes_encrypted_file, err := EncryptAssetData(assetData, session.key)
Expand Down Expand Up @@ -164,6 +173,7 @@ func api_setImageNotes(response http.ResponseWriter, request *http.Request) {

meta.HasImageNotes = true
meta.ImageNotesAsset = notes_asset
result.Url = "/assets/b/" + fmt.Sprint(media_id) + "/" + fmt.Sprint(notes_asset) + "/notes.json" + "?fp=" + GetVault().credentials.GetFingerprint()

// Save
err = media.EndWrite(meta, session.key, false)
Expand All @@ -181,5 +191,14 @@ func api_setImageNotes(response http.ResponseWriter, request *http.Request) {

// Response

response.WriteHeader(200)
jsonResult, err := json.Marshal(result)

if err != nil {
LogError(err)

ReturnAPIError(response, 500, "INTERNAL_ERROR", "Internal server error, Check the logs for details.")
return
}

ReturnAPI_JSON(response, request, jsonResult)
}
12 changes: 12 additions & 0 deletions backend/doc/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,12 @@ paths:
description: Not found
200:
description: Success
schema:
properties:
url:
type: string
description: "New notes URL"
example: "/assets/b/0/0/notes.json"

"/api/media/{id}/edit/ext_desc":
post:
Expand Down Expand Up @@ -895,6 +901,12 @@ paths:
description: Not found
200:
description: Success
schema:
properties:
url:
type: string
description: "New extended description URL"
example: "/assets/b/0/0/ext_desc.txt"

"/api/media/{id}/edit/thumbnail":
post:
Expand Down

0 comments on commit 2f4c118

Please sign in to comment.