-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: s3-compatible-api - 1. add start option and configure; 2. optmi…
…ze providers interfaces and implements; 3. rewrite the server construct function
- Loading branch information
Showing
20 changed files
with
243 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,63 @@ | ||
package handlers | ||
|
||
import ( | ||
"github.com/bittorrent/go-btfs/s3/consts" | ||
"net/http" | ||
) | ||
|
||
var defaultCorsMethods = []string{ | ||
http.MethodGet, | ||
http.MethodPut, | ||
http.MethodHead, | ||
http.MethodPost, | ||
http.MethodDelete, | ||
http.MethodOptions, | ||
http.MethodPatch, | ||
} | ||
|
||
var defaultCorsHeaders = []string{ | ||
consts.BTFSHash, | ||
consts.Date, | ||
consts.ETag, | ||
consts.ServerInfo, | ||
consts.Connection, | ||
consts.AcceptRanges, | ||
consts.ContentRange, | ||
consts.ContentEncoding, | ||
consts.ContentLength, | ||
consts.ContentType, | ||
consts.ContentMD5, | ||
consts.ContentDisposition, | ||
consts.LastModified, | ||
consts.ContentLanguage, | ||
consts.CacheControl, | ||
consts.RetryAfter, | ||
consts.AmzBucketRegion, | ||
consts.Expires, | ||
consts.Authorization, | ||
consts.Action, | ||
consts.XRequestWith, | ||
consts.Range, | ||
consts.UserAgent, | ||
"X-Amz*", | ||
"x-amz*", | ||
"*", | ||
} | ||
|
||
var defaultHeaders = map[string][]string{ | ||
consts.AccessControlAllowOrigin: []string{"*"}, | ||
consts.AccessControlAllowMethods: defaultCorsMethods, | ||
consts.AccessControlAllowHeaders: defaultCorsHeaders, | ||
consts.AccessControlExposeHeaders: defaultCorsHeaders, | ||
consts.AccessControlAllowCredentials: []string{"true"}, | ||
} | ||
|
||
type Option func(handlers *Handlers) | ||
|
||
func WithHeaders(headers map[string][]string) Option { | ||
return func(handlers *Handlers) { | ||
if headers != nil { | ||
handlers.headers = headers | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package providers | ||
|
||
import ( | ||
"errors" | ||
shell "github.com/bittorrent/go-btfs-api" | ||
"io" | ||
) | ||
|
||
var _ FileStorer = (*BtfsAPI)(nil) | ||
|
||
type BtfsAPI struct { | ||
shell *shell.Shell | ||
} | ||
|
||
func NewBtfsAPI(endpointUrl string) (api *BtfsAPI) { | ||
api = &BtfsAPI{} | ||
if endpointUrl == "" { | ||
api.shell = shell.NewLocalShell() | ||
} else { | ||
api.shell = shell.NewShell(endpointUrl) | ||
} | ||
return | ||
} | ||
|
||
func (api *BtfsAPI) Store(r io.Reader) (id string, err error) { | ||
id, err = api.shell.Add(r, shell.Pin(true)) | ||
return | ||
} | ||
|
||
func (api *BtfsAPI) Remove(id string) (err error) { | ||
ok := api.shell.Remove(id) | ||
if !ok { | ||
err = errors.New("not removed") | ||
} | ||
return | ||
} | ||
|
||
func (api *BtfsAPI) Cat(id string) (rc io.ReadCloser, err error) { | ||
rc, err = api.shell.Cat(id) | ||
return | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.