mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-21 20:27:51 +01:00
Automatically delete files from Warehouse in case there are no other references when deleting files from the blockchain via /blockchain/self/delete/file.
New function blockchain.FileExists. blockchain.DeleteFiles now returns list of deleted files.
This commit is contained in:
@@ -184,6 +184,7 @@ func apiBlockchainSelfListFile(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
/*
|
||||
apiBlockchainSelfDeleteFile deletes files with the provided IDs. Other fields are ignored.
|
||||
It will automatically delete the file in the Warehouse if there are no other references.
|
||||
|
||||
Request: POST /blockchain/self/delete/file with JSON structure apiBlockAddFiles
|
||||
Response: 200 with JSON structure apiBlockchainBlockStatus
|
||||
@@ -200,7 +201,16 @@ func apiBlockchainSelfDeleteFile(w http.ResponseWriter, r *http.Request) {
|
||||
deleteIDs = append(deleteIDs, input.Files[n].ID)
|
||||
}
|
||||
|
||||
newHeight, newVersion, status := core.UserBlockchain.DeleteFiles(deleteIDs)
|
||||
newHeight, newVersion, deletedFiles, status := core.UserBlockchain.DeleteFiles(deleteIDs)
|
||||
|
||||
// If successfully deleted from the blockchain, delete from the Warehouse in case there are no other references.
|
||||
if status == blockchain.BlockchainStatusOK {
|
||||
for n := range deletedFiles {
|
||||
if files, status := core.UserBlockchain.FileExists(deletedFiles[n].Hash); status == blockchain.BlockchainStatusOK && len(files) == 0 {
|
||||
core.UserWarehouse.DeleteFile(deletedFiles[n].Hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user