add accntcli

This commit is contained in:
2026-03-07 19:11:20 +02:00
parent 46bcc465ee
commit efdabf3efc
23 changed files with 698 additions and 96 deletions
+5 -1
View File
@@ -38,6 +38,10 @@ func (cli *Client) GetFile(ctx context.Context, rawpath string, writer io.Writer
return exist, err
}
contentLength := resp.Header.Get("Content-Length")
if contentLength == "" {
err := fmt.Errorf("Content-Length header is missing")
return exist, err
}
blobSize, err := strconv.ParseInt(contentLength, 10, 64)
if err != nil {
return exist, err
@@ -45,7 +49,7 @@ func (cli *Client) GetFile(ctx context.Context, rawpath string, writer io.Writer
recSize, err := Copy(ctx, writer, resp.Body)
if blobSize != recSize {
err := fmt.Errorf("Mismatch declared and actual body size, %d and %d", blobSize, recSize)
err := fmt.Errorf("Mismatch declared and actual body size: %d and %d", blobSize, recSize)
return exist, err
}
exist = true
+5 -1
View File
@@ -38,6 +38,10 @@ func (cli *Client) ListCollections(ctx context.Context, rawpath string) ([]byte,
return list, err
}
contentLength := resp.Header.Get("Content-Length")
if contentLength == "" {
err := fmt.Errorf("Content-Length header is missing")
return list, err
}
blobSize, err := strconv.ParseInt(contentLength, 10, 64)
if err != nil {
return list, err
@@ -45,7 +49,7 @@ func (cli *Client) ListCollections(ctx context.Context, rawpath string) ([]byte,
buffer := bytes.NewBuffer(nil)
recSize, err := Copy(ctx, buffer, resp.Body)
if blobSize != recSize {
err := fmt.Errorf("Mismatch declared and actual body size, %d and %d", blobSize, recSize)
err := fmt.Errorf("Mismatch declared and actual body size: %d and %d", blobSize, recSize)
return list, err
}
list = buffer.Bytes()
+5 -1
View File
@@ -38,6 +38,10 @@ func (cli *Client) ListFiles(ctx context.Context, rawpath string) ([]byte, error
return list, err
}
contentLength := resp.Header.Get("Content-Length")
if contentLength == "" {
err := fmt.Errorf("Content-Length header is missing")
return list, err
}
blobSize, err := strconv.ParseInt(contentLength, 10, 64)
if err != nil {
return list, err
@@ -45,7 +49,7 @@ func (cli *Client) ListFiles(ctx context.Context, rawpath string) ([]byte, error
buffer := bytes.NewBuffer(nil)
recSize, err := Copy(ctx, buffer, resp.Body)
if blobSize != recSize {
err := fmt.Errorf("Mismatch declared and actual body size, %d and %d", blobSize, recSize)
err := fmt.Errorf("Mismatch declared and actual body size: %d and %d", blobSize, recSize)
return list, err
}
list = buffer.Bytes()
+14 -14
View File
@@ -13,15 +13,15 @@ const (
PathTypeRegexp = "regexp"
)
type Repository struct {
type Referer struct {
urlobj *url.URL
user, pass string
resource string
values url.Values
}
func ParsePath(rawpath string) (*Repository, error) {
repo := &Repository{
func ParsePath(rawpath string) (*Referer, error) {
repo := &Referer{
values: url.Values{},
}
if !strings.Contains(rawpath, "://") {
@@ -43,7 +43,7 @@ func ParsePath(rawpath string) (*Repository, error) {
return repo, err
}
func (repo *Repository) Raw() string {
func (repo *Referer) Raw() string {
res := path.Join(repo.urlobj.Host, repo.resource)
query := repo.values.Encode()
if query != "" {
@@ -52,47 +52,47 @@ func (repo *Repository) Raw() string {
return res
}
func (repo *Repository) SetResource(resource string) {
func (repo *Referer) SetResource(resource string) {
repo.resource = path.Join("/", resource)
}
func (repo *Repository) JoinResource(resource string) {
func (repo *Referer) JoinResource(resource string) {
repo.resource = path.Join("/", repo.resource, resource)
}
func (repo *Repository) PathType(typ string) {
func (repo *Referer) PathType(typ string) {
repo.values.Set("pathType", typ)
}
func (repo *Repository) DryRun(yesno bool) {
func (repo *Referer) DryRun(yesno bool) {
repo.values.Set("dryRun", strconv.FormatBool(yesno))
}
func (repo *Repository) File() string {
func (repo *Referer) File() string {
curl := repo.urlobj.JoinPath("/v3/api/file/", repo.resource)
return curl.String()
}
func (repo *Repository) Files() string {
func (repo *Referer) Files() string {
curl := repo.urlobj.JoinPath("/v3/api/files/", repo.resource)
return curl.String()
}
func (repo *Repository) Collection() string {
func (repo *Referer) Collection() string {
curl := repo.urlobj.JoinPath("/v3/api/collection/", repo.resource)
return curl.String()
}
func (repo *Repository) Collections() string {
func (repo *Referer) Collections() string {
curl := repo.urlobj.JoinPath("/v3/api/collections/", repo.resource)
return curl.String()
}
func (repo *Repository) Userinfo() (string, string) {
func (repo *Referer) Userinfo() (string, string) {
return repo.user, repo.pass
}
func (repo *Repository) SetUserinfo(user, pass string) {
func (repo *Referer) SetUserinfo(user, pass string) {
if user != "" && pass != "" {
repo.user, repo.pass = user, pass
}