Skip to content

Commit 28b61a9

Browse files
authored
feat(webdav): support oc:checksums (#8064 close #7472)
Ref: #7472
1 parent 0126af4 commit 28b61a9

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pkg/utils/hash.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"errors"
1111
"hash"
1212
"io"
13+
"iter"
1314

1415
"github.com/alist-org/alist/v3/internal/errs"
1516
log "github.com/sirupsen/logrus"
@@ -226,3 +227,13 @@ func (hi HashInfo) GetHash(ht *HashType) string {
226227
func (hi HashInfo) Export() map[*HashType]string {
227228
return hi.h
228229
}
230+
231+
func (hi HashInfo) All() iter.Seq2[*HashType, string] {
232+
return func(yield func(*HashType, string) bool) {
233+
for hashType, hashValue := range hi.h {
234+
if !yield(hashType, hashValue) {
235+
return
236+
}
237+
}
238+
}
239+
}

server/webdav/prop.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"encoding/xml"
1111
"errors"
12+
"fmt"
1213
"mime"
1314
"net/http"
1415
"path"
@@ -101,7 +102,7 @@ type DeadPropsHolder interface {
101102
Patch([]Proppatch) ([]Propstat, error)
102103
}
103104

104-
// liveProps contains all supported, protected DAV: properties.
105+
// liveProps contains all supported properties.
105106
var liveProps = map[xml.Name]struct {
106107
// findFn implements the propfind function of this property. If nil,
107108
// it indicates a hidden property.
@@ -160,6 +161,10 @@ var liveProps = map[xml.Name]struct {
160161
findFn: findSupportedLock,
161162
dir: true,
162163
},
164+
{Space: "http://owncloud.org/ns", Local: "checksums"}: {
165+
findFn: findChecksums,
166+
dir: false,
167+
},
163168
}
164169

165170
// TODO(nigeltao) merge props and allprop?
@@ -483,3 +488,11 @@ func findSupportedLock(ctx context.Context, ls LockSystem, name string, fi model
483488
`<D:locktype><D:write/></D:locktype>` +
484489
`</D:lockentry>`, nil
485490
}
491+
492+
func findChecksums(ctx context.Context, ls LockSystem, name string, fi model.Obj) (string, error) {
493+
checksums := ""
494+
for hashType, hashValue := range fi.GetHash().All() {
495+
checksums += fmt.Sprintf("<checksum>%s:%s</checksum>", hashType.Name, hashValue)
496+
}
497+
return checksums, nil
498+
}

0 commit comments

Comments
 (0)