webapi: Add dummy /download/start and /download/status endpoints

This commit is contained in:
Kleissner
2021-09-27 03:49:34 +02:00
parent dc093f5f6d
commit 24df8c1eb0
3 changed files with 86 additions and 0 deletions

View File

@@ -58,6 +58,8 @@ func Start(ListenAddresses []string, UseSSL bool, CertificateFile, CertificateKe
Router.HandleFunc("/search/terminate", apiSearchTerminate).Methods("GET")
Router.HandleFunc("/explore", apiExplore).Methods("GET")
Router.HandleFunc("/file/format", apiFileFormat).Methods("GET")
Router.HandleFunc("/download/start", apiDownloadStart).Methods("GET")
Router.HandleFunc("/download/status", apiDownloadStatus).Methods("GET")
for _, listen := range ListenAddresses {
go startWebServer(listen, UseSSL, CertificateFile, CertificateKey, Router, "API", TimeoutRead, TimeoutWrite)

56
webapi/Download.go Normal file
View File

@@ -0,0 +1,56 @@
/*
File Name: Download.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/
package webapi
import "net/http"
type apiResponseDownloadStatus struct {
Status int `json:"status"` // Status: 0 = Success, 1 = Error download not found
// TODO: Add progress size, total size, number of peers in swarm, etc.
}
/*
apiDownloadStart starts the download of a file. The path is the full path on disk to store the file.
The hash parameter identifies the file to download. The blockchain parameter is the node ID of the peer who shared the file on its blockchain (i.e., the "owner" of the file).
Request: GET /download/start?path=[target path on disk]&hash=[file hash to download]&blockchain=[node ID]
Result: 200 with JSON structure apiResponseDownloadStatus
*/
func apiDownloadStart(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
filePath := r.Form.Get("path")
hash := r.Form.Get("hash")
blockchain := r.Form.Get("blockchain")
if filePath == "" || hash == "" || blockchain == "" {
http.Error(w, "", http.StatusBadRequest)
return
}
// TODO
EncodeJSON(w, r, apiResponseDownloadStatus{Status: 0})
}
/*
apiDownloadStatus returns the status of an active download. The hash and blockchain parameters must be the same as /download/start.
Request: GET /download/status?hash=[file hash]&blockchain=[node ID]
Result: 200 with JSON structure apiResponseDownloadStatus
*/
func apiDownloadStatus(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
hash := r.Form.Get("hash")
blockchain := r.Form.Get("blockchain")
if hash == "" || blockchain == "" {
http.Error(w, "", http.StatusBadRequest)
return
}
// TODO
EncodeJSON(w, r, apiResponseDownloadStatus{Status: 1})
}

View File

@@ -46,6 +46,9 @@ These are the functions provided by the API:
/search/result Return search results
/search/terminate Terminate a search
/download/start Start the download of a file
/download/status Get the status of a download
/explore List recently shared files
/file/format Detect file type and format
@@ -579,6 +582,31 @@ Request: GET /search/terminate?id=[UUID]
Response: 204 Empty
```
### Start Download
This starts the download of a file. The path is the full path on disk to store the file.
The hash parameter identifies the file to download. The blockchain parameter is the node ID of the peer who shared the file on its blockchain (i.e., the "owner" of the file).
```
Request: GET /download/start?path=[target path on disk]&hash=[file hash to download]&blockchain=[node ID]
Result: 200 with JSON structure apiResponseDownloadStatus
```
```go
type apiResponseDownloadStatus struct {
Status int `json:"status"` // Status: 0 = Success, 1 = Error download not found
}
```
### Get Download Status
This returns the status of an active download. The hash and blockchain parameters must be the same as `/download/start`.
```
Request: GET /download/status?hash=[file hash]&blockchain=[node ID]
Result: 200 with JSON structure apiResponseDownloadStatus
```
## Explore
### List Recently Shared Files