Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add support to fetch specific file

Neeraj Guptaa71a9f47f16b
diff --git a/internal/api/api_error.go b/internal/api/api_error.go
new file mode 100644
index 0000000000..0b59eb1809
--- /dev/null
+++ b/internal/api/api_error.go
@@ -0,0 +1,27 @@
+package api
+
+import (
+ "fmt"
+ "strings"
+)
+
+type ApiError struct {
+ Message string
+ StatusCode int
+}
+
+func (e *ApiError) Error() string {
+ return fmt.Sprintf("status %d with err: %s", e.StatusCode, e.Message)
+}
+
+func IsApiError(err error) bool {
+ _, ok := err.(*ApiError)
+ return ok
+}
+
+func IsFileNotInAlbumError(err error) bool {
+ if apiErr, ok := err.(*ApiError); ok {
+ return strings.Contains(apiErr.Message, "FILE_NOT_FOUND_IN_ALBUM")
+ }
+ return false
+}
diff --git a/internal/api/collection.go b/internal/api/collection.go
index 6af7023819..f8c4c24d4e 100644
--- a/internal/api/collection.go
+++ b/internal/api/collection.go
@@ -42,3 +42,23 @@ func (c *Client) GetFiles(ctx context.Context, collectionID, sinceTime int64) ([
}
return res.Files, res.HasMore, err
}
+
+// GetFile ..
+func (c *Client) GetFile(ctx context.Context, collectionID, fileID int64) (*File, error) {
+ var res struct {
+ File File `json:"file"`
+ }
+ r, err := c.restClient.R().
+ SetContext(ctx).
+ SetQueryParam("collectionID", strconv.FormatInt(collectionID, 10)).
+ SetQueryParam("fileID", strconv.FormatInt(fileID, 10)).
+ SetResult(&res).
+ Get("/collections/file")
+ if r.IsError() {
+ return nil, &ApiError{
+ StatusCode: r.StatusCode(),
+ Message: r.String(),
+ }
+ }
+ return &res.File, err
+}
diff --git a/internal/api/login_type.go b/internal/api/login_type.go
index 9c60d4eb16..50149aed7c 100644
--- a/internal/api/login_type.go
+++ b/internal/api/login_type.go
@@ -1,8 +1,6 @@
package api
import (
- "fmt"
-
"github.com/google/uuid"
)
@@ -15,15 +13,6 @@ type SRPAttributes struct {
IsEmailMFAEnabled bool `json:"isEmailMFAEnabled" binding:"required"`
}
-type ApiError struct {
- Message string
- StatusCode int
-}
-
-func (e *ApiError) Error() string {
- return fmt.Sprintf("status %d with err: %s", e.StatusCode, e.Message)
-}
-
type CreateSRPSessionResponse struct {
SessionID uuid.UUID `json:"sessionID" binding:"required"`
SRPB string `json:"srpB" binding:"required"`