Skip to content

Commit

Permalink
Add restore_path to files in NextCloud trash (#4447)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono authored Jul 22, 2024
2 parents 5838219 + adcc3af commit 1ca1184
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
3 changes: 2 additions & 1 deletion docs/nextcloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
42 changes: 22 additions & 20 deletions model/nextcloud/nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/webdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -266,6 +267,7 @@ type Item struct {
Href string
Name string
TrashedName string
RestorePath string
Size uint64
ContentType string
LastModified string
Expand All @@ -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"`
Expand All @@ -305,6 +308,7 @@ const ListFilesPayload = `<?xml version="1.0"?>
<d:getcontenttype />
<oc:fileid />
<nc:trashbin-filename />
<nc:trashbin-original-location />
</d:prop>
</d:propfind>
`
Expand Down

0 comments on commit 1ca1184

Please sign in to comment.