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

Merged
merged 7 commits into from
Jul 2, 2024
Merged
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 delete a file in the trash bin of NextCloud
  • Loading branch information
nono committed Jun 27, 2024
commit 7be0b1fa699a14c7f6b7f488d2bda37c5fcfd8cc
25 changes: 25 additions & 0 deletions docs/nextcloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,31 @@ HTTP/1.1 204 No Content
- 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 delete a file in the trash.

### Request

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

### Response

```http
HTTP/1.1 204 No Content
```

#### Status codes

- 204 No Content, when the file/directory has been put in the trash
- 400 Bad Request, when the account is not configured for NextCloud, or the `To` parameter is missing
- 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

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

This route can be used to empty the trash bin on NextCloud.
Expand Down
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) DeleteTrash(path string) error {
return nc.webdav.Delete("/trashbin/" + nc.userID + "/" + path)
}

func (nc *NextCloud) EmptyTrash() error {
return nc.webdav.Delete("/trashbin/" + nc.userID + "/trash")
}
Expand Down
20 changes: 20 additions & 0 deletions web/remote/nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ func nextcloudGetTrash(c echo.Context) error {
return jsonapi.DataList(c, http.StatusOK, files, nil)
}

func nextcloudDeleteTrash(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)
}

path := "/trash/" + c.Param("*")
if err := nc.DeleteTrash(path); err != nil {
return wrapNextcloudErrors(err)
}
return c.NoContent(http.StatusNoContent)
}

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