Add endpoint /blockchain/self/delete/file to delete files.

This commit is contained in:
Kleissner
2021-09-19 00:57:49 +02:00
parent 06b846ca34
commit df0f57063f
4 changed files with 75 additions and 19 deletions

View File

@@ -47,8 +47,9 @@ type apiBlockchainBlockRaw struct {
}
type apiBlockchainBlockStatus struct {
Status int `json:"status"` // Status: 0 = Success, 1 = Error invalid data
Height uint64 `json:"height"` // New height of the blockchain (number of blocks).
Status int `json:"status"` // Status: 0 = Success, 1 = Error invalid data
Height uint64 `json:"height"` // Height of the blockchain (number of blocks).
Version uint64 `json:"version"` // Version of the blockchain.
}
/*
@@ -70,9 +71,9 @@ func apiBlockchainSelfAppend(w http.ResponseWriter, r *http.Request) {
records = append(records, core.BlockRecordRaw{Type: record.Type, Data: record.Data})
}
newHeight, status := core.UserBlockchainAppend(records)
newHeight, newVersion, status := core.UserBlockchainAppend(records)
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight})
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
}
type apiBlockchainBlock struct {
@@ -205,9 +206,9 @@ func apiBlockchainSelfAddFile(w http.ResponseWriter, r *http.Request) {
filesAdd = append(filesAdd, blockRecordFileFromAPI(file))
}
newHeight, status := core.UserBlockchainAddFiles(filesAdd)
newHeight, newVersion, status := core.UserBlockchainAddFiles(filesAdd)
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight})
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
}
/*
@@ -230,6 +231,29 @@ func apiBlockchainSelfListFile(w http.ResponseWriter, r *http.Request) {
EncodeJSON(w, r, result)
}
/*
apiBlockchainSelfDeleteFile deletes files with the provided IDs. Other fields are ignored.
Request: POST /blockchain/self/delete/file with JSON structure apiBlockAddFiles
Response: 200 with JSON structure apiBlockchainBlockStatus
*/
func apiBlockchainSelfDeleteFile(w http.ResponseWriter, r *http.Request) {
var input apiBlockAddFiles
if err := DecodeJSON(w, r, &input); err != nil {
return
}
var deleteIDs []uuid.UUID
for n := range input.Files {
deleteIDs = append(deleteIDs, input.Files[n].ID)
}
newHeight, newVersion, status := core.UserBlockchainDeleteFiles(deleteIDs)
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
}
// --- conversion from core to API data ---
func isFileTagKnownMetadata(tagType uint16) bool {