Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage the Nextcloud trash #4432

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a route to empty the trash bin on NextCloud
  • Loading branch information
nono committed Jun 27, 2024
commit d3419daeb76d4ff2e4d1e31fad3f92128b77661d
18 changes: 18 additions & 0 deletions docs/nextcloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,21 @@ HTTP/1.1 204 No Content
- 401 Unauthorized, when authentication to the NextCloud fails
- 404 Not Found, when the account is not found or the file/directory is not found on the NextCloud
- 409 Conflict, when a directory or file already exists where the file/directory should be restored on the NextCloud.

## DELETE /remote/nextcloud/:account/trash

This route can be used to empty the trash bin on NextCloud.

### Request

```http
DELETE /remote/nextcloud/4ab2155707bb6613a8b9463daf00381b/trash HTTP/1.1
Host: cozy.example.net
Authorization: Bearer eyJhbG...
```

### Response

```http
HTTP/1.1 204 No Content
```
4 changes: 4 additions & 0 deletions model/nextcloud/nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func (nc *NextCloud) Restore(path string) error {
return nc.webdav.Move(path, dst)
}

func (nc *NextCloud) EmptyTrash() error {
return nc.webdav.Delete("/trashbin/" + nc.userID + "/trash")
}

func (nc *NextCloud) ListFiles(path string) ([]jsonapi.Object, error) {
items, err := nc.webdav.List("/files/" + nc.userID + "/" + path)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions web/remote/nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ func nextcloudGetTrash(c echo.Context) error {
return jsonapi.DataList(c, http.StatusOK, files, nil)
}

func nextcloudEmptyTrash(c echo.Context) error {
inst := middlewares.GetInstance(c)
if err := middlewares.AllowWholeType(c, permission.DELETE, consts.Files); err != nil {
return err
}

accountID := c.Param("account")
nc, err := nextcloud.New(inst, accountID)
if err != nil {
return wrapNextcloudErrors(err)
}

if err := nc.EmptyTrash(); err != nil {
return wrapNextcloudErrors(err)
}
return c.NoContent(http.StatusNoContent)
}

func nextcloudGet(c echo.Context) error {
inst := middlewares.GetInstance(c)
if err := middlewares.AllowWholeType(c, permission.GET, consts.Files); err != nil {
Expand Down Expand Up @@ -287,6 +305,7 @@ func nextcloudRestore(c echo.Context) error {
func nextcloudRoutes(router *echo.Group) {
group := router.Group("/nextcloud/:account")
group.GET("/trash/*", nextcloudGetTrash)
group.DELETE("/trash", nextcloudEmptyTrash)
group.GET("/*", nextcloudGet)
group.PUT("/*", nextcloudPut)
group.DELETE("/*", nextcloudDelete)
Expand Down