mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-19 19:47:49 +01:00
webapi: New function /blockchain/file/update
blockchain: Add readme.md. Add function ReplaceFiles.
This commit is contained in:
@@ -48,6 +48,7 @@ func Start(ListenAddresses []string, UseSSL bool, CertificateFile, CertificateKe
|
||||
Router.HandleFunc("/blockchain/self/add/file", apiBlockchainSelfAddFile).Methods("POST")
|
||||
Router.HandleFunc("/blockchain/self/list/file", apiBlockchainSelfListFile).Methods("GET")
|
||||
Router.HandleFunc("/blockchain/self/delete/file", apiBlockchainSelfDeleteFile).Methods("POST")
|
||||
Router.HandleFunc("/blockchain/file/update", apiBlockchainFileUpdate).Methods("POST")
|
||||
Router.HandleFunc("/profile/list", apiProfileList).Methods("GET")
|
||||
Router.HandleFunc("/profile/read", apiProfileRead).Methods("GET")
|
||||
Router.HandleFunc("/profile/write", apiProfileWrite).Methods("POST")
|
||||
|
||||
@@ -215,6 +215,41 @@ func apiBlockchainSelfDeleteFile(w http.ResponseWriter, r *http.Request) {
|
||||
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
|
||||
}
|
||||
|
||||
/*
|
||||
apiBlockchainSelfUpdateFile updates files that are already published on the blockchain.
|
||||
|
||||
Request: POST /blockchain/file/update with JSON structure apiBlockAddFiles
|
||||
Response: 200 with JSON structure apiBlockchainBlockStatus
|
||||
400 if invalid input
|
||||
*/
|
||||
func apiBlockchainFileUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
var input apiBlockAddFiles
|
||||
if err := DecodeJSON(w, r, &input); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var filesAdd []blockchain.BlockRecordFile
|
||||
|
||||
for _, file := range input.Files {
|
||||
// Verify that the file exists in the warehouse. Folders are exempt from this check as they are only virtual.
|
||||
if !file.IsVirtualFolder() {
|
||||
if hashA, err := warehouse.ValidateHash(file.Hash); err != nil {
|
||||
http.Error(w, "", http.StatusBadRequest)
|
||||
return
|
||||
} else if _, _, valid := core.UserWarehouse.FileExists(hashA); !valid {
|
||||
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: blockchain.BlockchainStatusNotInWarehouse})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
filesAdd = append(filesAdd, blockRecordFileFromAPI(file))
|
||||
}
|
||||
|
||||
newHeight, newVersion, status := core.UserBlockchain.ReplaceFiles(filesAdd)
|
||||
|
||||
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
|
||||
}
|
||||
|
||||
// ---- metadata functions ----
|
||||
|
||||
// GetMetadata returns the specified metadata or nil if not available.
|
||||
|
||||
@@ -36,6 +36,7 @@ These are the functions provided by the API:
|
||||
/blockchain/self/add/file Add file to the blockchain
|
||||
/blockchain/self/list/file List all files stored on the blockchain
|
||||
/blockchain/self/delete/file Delete files from the blockchain
|
||||
/blockchain/file/update Updates files on the blockchain
|
||||
|
||||
/profile/list List all profile fields
|
||||
/profile/read Read a profile field
|
||||
@@ -240,6 +241,8 @@ Each file must be already stored in the Warehouse (virtual folders are exempt).
|
||||
|
||||
If the block record encoding fails for any file, this function aborts with the status code StatusCorruptBlockRecord. In case the function aborts, the blockchain remains unchanged.
|
||||
|
||||
Do not add the same file with the same ID multiple times. Doing so will create double entries. This function does not check if the file is already stored on the blockchain. Storing multiple files with the same file hash, but different IDs, is perfectly fine.
|
||||
|
||||
```
|
||||
Request: POST /blockchain/self/add/file with JSON structure apiBlockAddFiles
|
||||
Response: 200 with JSON structure apiBlockchainBlockStatus
|
||||
@@ -372,6 +375,18 @@ Example response indicating success:
|
||||
}
|
||||
```
|
||||
|
||||
### Update File
|
||||
|
||||
This updates files that are already published on the blockchain. This is useful for example when changing a file name or description.
|
||||
Just like with the add file function, the file must be already stored in the Warehouse, otherwise this function fails.
|
||||
|
||||
Note as this replaces the previous file record on the blockchain, all details (including special metadata fields) must be included.
|
||||
|
||||
```
|
||||
Request: POST /blockchain/file/update with JSON structure apiBlockAddFiles
|
||||
Response: 200 with JSON structure apiBlockchainBlockStatus
|
||||
```
|
||||
|
||||
## Profile Functions
|
||||
|
||||
User profile data such as the username, email address, and picture are stored on the blockchain. Profile fields are text (UTF-8) or binary encoded, depending on the type.
|
||||
|
||||
Reference in New Issue
Block a user