Skip to content

Commit

Permalink
Development (#131)
Browse files Browse the repository at this point in the history
* addressing #119, uploading same file multiple times

* addressing #122, file delete Matadata unmarshal

* addressing #123, fix response for non-existing pod

* addressing #127, server requires postageBlockId to run

* addressing #116, non-existing dir response

* addressing #119, backup old file in case same name

* code cleanup

* code cleanup

* code cleanup

* code cleanup

* addressing #117 and #118, issues related to pod deletion (#1)

* addressing #117 and #118, issues related to pod deletion

* fix reploading deleted file

* fix #132, #133

* fixes #141, rmdir updates feed with magicword

* fixes #134

* fixes #135 & #136

* fixing #139

* fix #140, accept mutable bool in request

* minor typo

* #97 handle query param for doc-ls

* #102 handle exception for invalid json

* #106 handled panic

* related to #100, doc new podname missing

* fix #124, handle removed root directory

* handle #96

* handle #24, use shlex to parse prompt args

* fixed #19, pod deletion requires password

* check for root dir presence in mkdir

* mod tidy (#146)

* mod tidy

* manually restore vendor

* manually restore vendor

* upload err fix

* fix #86, shared pod removed from list

* minor changes

* fix #147, check read only feed before access time update in download

* fix #148, close response body in bee client

* minor file deletion test added

* #92, table name added in count response

* fix w/ deepsource recommendation

* fix w/ deepsource recommendation

* #102, add test for invalid json

* 404 on file not present

* add get endpoint for download

* fix #158

* resolve anti-pattern

* bump version
  • Loading branch information
asabya authored Dec 13, 2021
1 parent d304486 commit 5d46a2a
Show file tree
Hide file tree
Showing 71 changed files with 1,607 additions and 525 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dfs can be used for the following use cases

### User
The first step in dfs is to create a user. Every user is associated with a 12
word mnemonic based hd wallet. This wallet is passwod protected and stored in
word mnemonic based hd wallet. This wallet is password protected and stored in
the datadir. whenever a user created a pod for himself, a new key pair is created
using this mnemonic. A user can use this mnemonic and import their account in any
device and instantly see all their pods.
Expand Down
2 changes: 1 addition & 1 deletion cmd/common/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type DocRequest struct {
SimpleIndex string `json:"si,omitempty"`
CompoundIndex string `json:"ci,omitempty"`
Expression string `json:"expr,omitempty"`
Mutable string `json:"mutable,omitempty"`
Mutable bool `json:"mutable,omitempty"`
Limit string `json:"limit,omitempty"`
FileName string `json:"file_name,omitempty"`
}
13 changes: 12 additions & 1 deletion cmd/dfs-cli/cmd/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,22 @@ import (
"github.com/fairdatasociety/fairOS-dfs/pkg/api"
)

func docNew(tableName, simpleIndex, mutable string) {
func docNew(podName, tableName, simpleIndex, mutableStr string) {
mutable := true
if mutableStr != "" {
mut, err := strconv.ParseBool(mutableStr)
if err != nil {
fmt.Println("doc new: error parsing \"mutable\" string")
return
}
mutable = mut
}

docNewReq := common.DocRequest{
TableName: tableName,
SimpleIndex: simpleIndex,
Mutable: mutable,
PodName: podName,
}
jsonData, err := json.Marshal(docNewReq)
if err != nil {
Expand Down
22 changes: 19 additions & 3 deletions cmd/dfs-cli/cmd/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/c-bata/go-prompt"
"github.com/fairdatasociety/fairOS-dfs/pkg/utils"
"github.com/google/shlex"
"golang.org/x/term"
)

Expand Down Expand Up @@ -195,7 +196,14 @@ func completer(in prompt.Document) []prompt.Suggest {

func executor(in string) {
in = strings.TrimSpace(in)
blocks := strings.Split(in, " ")
blocks, err := shlex.Split(in)
if err != nil {
fmt.Println("unable to parse command")
return
}
if len(blocks) == 0 {
return
}
switch blocks[0] {
case "help":
help()
Expand Down Expand Up @@ -224,6 +232,10 @@ func executor(in string) {
fmt.Println("invalid command. Missing \"name\" argument ")
return
}
if len(blocks) == 3 {
fmt.Println("invalid command. Missing \"address\" or \"mnemonic\" argument ")
return
}
userName := blocks[2]
if len(blocks) == 4 {
address := blocks[3]
Expand Down Expand Up @@ -572,7 +584,7 @@ func executor(in string) {
if len(blocks) == 5 {
mutable = blocks[4]
}
docNew(tableName, si, mutable)
docNew(currentPod, tableName, si, mutable)
currentPrompt = getCurrentPrompt()
case "ls":
docList()
Expand Down Expand Up @@ -774,6 +786,10 @@ func executor(in string) {
compression := ""
if len(blocks) >= 5 {
compression = blocks[4]
if compression != "snappy" && compression != "gzip" {
fmt.Println("invalid value for \"compression\", should either be \"snappy\" or \"gzip\"")
return
}
}
uploadFile(fileName, currentPod, blocks[1], podDir, blockSize, compression)
currentPrompt = getCurrentPrompt()
Expand Down Expand Up @@ -945,7 +961,7 @@ func help() {
fmt.Println(" - cd <directory name>")
fmt.Println(" - ls ")
fmt.Println(" - download <destination dir in local fs, relative path of source file in pod>")
fmt.Println(" - upload <source file in local fs, destination directory in pod, block size (ex: 1Mb, 64Mb)>, compression true/false")
fmt.Println(" - upload <source file in local fs, destination directory in pod, block size (ex: 1Mb, 64Mb)>, compression snappy/gzip")
fmt.Println(" - share <file name> - shares a file with another user")
fmt.Println(" - receive <sharing reference> <pod dir> - receives a file from another user")
fmt.Println(" - receiveinfo <sharing reference> - shows the received file info before accepting the receive")
Expand Down
9 changes: 8 additions & 1 deletion cmd/dfs/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ var serverCmd = &cobra.Command{
Long: `Serves all the dfs commands through an HTTP server so that the upper layers
can consume it.`,
Run: func(cmd *cobra.Command, args []string) {
if postageBlockId == "" {
_ = cmd.Help()
fmt.Println("\npostageBlockId is required to run server")
return
}

var logger logging.Logger
switch v := strings.ToLower(verbosity); v {
case "0", "silent":
Expand Down Expand Up @@ -180,7 +186,7 @@ func startHttpService(logger logging.Logger) {
userRouter.HandleFunc("/logout", handler.UserLogoutHandler).Methods("POST")
userRouter.HandleFunc("/export", handler.ExportUserHandler).Methods("POST")
userRouter.HandleFunc("/delete", handler.UserDeleteHandler).Methods("DELETE")
userRouter.HandleFunc("/stat", handler.GetUserStatHandler).Methods("GET")
userRouter.HandleFunc("/stat", handler.UserStatHandler).Methods("GET")

// pod related handlers
baseRouter.HandleFunc("/pod/receive", handler.PodReceiveHandler).Methods("GET")
Expand Down Expand Up @@ -208,6 +214,7 @@ func startHttpService(logger logging.Logger) {
// file related handlers
fileRouter := baseRouter.PathPrefix("/file/").Subrouter()
fileRouter.Use(handler.LoginMiddleware)
fileRouter.HandleFunc("/download", handler.FileDownloadHandler).Methods("GET")
fileRouter.HandleFunc("/download", handler.FileDownloadHandler).Methods("POST")
fileRouter.HandleFunc("/upload", handler.FileUploadHandler).Methods("POST")
fileRouter.HandleFunc("/share", handler.FileShareHandler).Methods("POST")
Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ require (
github.com/ethersphere/bee v0.5.0
github.com/ethersphere/bmt v0.1.4
github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/gorilla/mux v1.7.4
github.com/gorilla/securecookie v1.1.1
github.com/hashicorp/golang-lru v0.5.4
github.com/klauspost/compress v1.10.1 // indirect
github.com/klauspost/pgzip v1.2.5
github.com/libp2p/go-libp2p-autonat-svc v0.1.0 // indirect
github.com/mattn/go-sqlite3 v1.14.6
github.com/mattn/go-tty v0.0.3 // indirect
github.com/miguelmota/go-ethereum-hdwallet v0.0.0-20200123000308-a60dcd172b4c
github.com/mitchellh/go-homedir v1.1.0
github.com/mmcloughlin/avo v0.0.0-20200803215136-443f81d77104 // indirect
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 // indirect
github.com/rs/cors v1.7.0
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.0
github.com/tidwall/pretty v1.0.2 // indirect
github.com/tinygrasshopper/bettercsv v0.0.1
github.com/tyler-smith/go-bip39 v1.0.2
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
Expand Down
Loading

0 comments on commit 5d46a2a

Please sign in to comment.