From adcc3af192d72d6acf8af83593160fe6d3f77579 Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Thu, 18 Jul 2024 18:34:30 +0200 Subject: [PATCH] Add restore_path to files in NextCloud trash --- docs/nextcloud.md | 3 ++- model/nextcloud/nextcloud.go | 42 +++++++++++++++++++----------------- pkg/webdav/webdav.go | 4 ++++ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/docs/nextcloud.md b/docs/nextcloud.md index fef8fce107a..2f8ee528906 100644 --- a/docs/nextcloud.md +++ b/docs/nextcloud.md @@ -466,7 +466,8 @@ Content-Type: application/vnd.api+json "name": "Old", "path": "/trash/Old.d93571568", "updated_at": "Tue, 25 Jun 2024 14:31:44 GMT", - "etag": "1719326384" + "etag": "1719326384", + "restore_path": "/Old" }, "meta": {}, "links": { diff --git a/model/nextcloud/nextcloud.go b/model/nextcloud/nextcloud.go index 22701cb2e92..db2d16e955e 100644 --- a/model/nextcloud/nextcloud.go +++ b/model/nextcloud/nextcloud.go @@ -33,16 +33,17 @@ const ( ) type File struct { - DocID string `json:"id,omitempty"` - Type string `json:"type"` - Name string `json:"name"` - Path string `json:"path"` - Size uint64 `json:"size,omitempty"` - Mime string `json:"mime,omitempty"` - Class string `json:"class,omitempty"` - UpdatedAt string `json:"updated_at,omitempty"` - ETag string `json:"etag,omitempty"` - url string + DocID string `json:"id,omitempty"` + Type string `json:"type"` + Name string `json:"name"` + Path string `json:"path"` + Size uint64 `json:"size,omitempty"` + Mime string `json:"mime,omitempty"` + Class string `json:"class,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + ETag string `json:"etag,omitempty"` + RestorePath string `json:"restore_path,omitempty"` + url string } func (f *File) ID() string { return f.DocID } @@ -205,16 +206,17 @@ func (nc *NextCloud) ListTrashed(path string) ([]jsonapi.Object, error) { mime, class = vfs.ExtractMimeAndClassFromFilename(item.TrashedName) } file := &File{ - DocID: item.ID, - Type: item.Type, - Name: item.TrashedName, - Path: filepath.Join(path, filepath.Base(item.Href)), - Size: item.Size, - Mime: mime, - Class: class, - UpdatedAt: item.LastModified, - ETag: item.ETag, - url: nc.buildTrashedURL(item, path), + DocID: item.ID, + Type: item.Type, + Name: item.TrashedName, + Path: filepath.Join(path, filepath.Base(item.Href)), + Size: item.Size, + Mime: mime, + Class: class, + UpdatedAt: item.LastModified, + ETag: item.ETag, + RestorePath: item.RestorePath, + url: nc.buildTrashedURL(item, path), } files = append(files, file) } diff --git a/pkg/webdav/webdav.go b/pkg/webdav/webdav.go index abbf3171003..fb0591bd6a6 100644 --- a/pkg/webdav/webdav.go +++ b/pkg/webdav/webdav.go @@ -243,6 +243,7 @@ func (c *Client) List(path string) ([]Item, error) { Href: href, Name: props.Name, TrashedName: props.TrashedName, + RestorePath: "/" + props.RestorePath, LastModified: props.LastModified, ETag: props.ETag, } @@ -266,6 +267,7 @@ type Item struct { Href string Name string TrashedName string + RestorePath string Size uint64 ContentType string LastModified string @@ -287,6 +289,7 @@ type props struct { Type xml.Name `xml:"prop>resourcetype>collection"` Name string `xml:"prop>displayname"` TrashedName string `xml:"prop>trashbin-filename"` + RestorePath string `xml:"prop>trashbin-original-location"` Size string `xml:"prop>getcontentlength"` ContentType string `xml:"prop>getcontenttype"` LastModified string `xml:"prop>getlastmodified"` @@ -305,6 +308,7 @@ const ListFilesPayload = ` + `