feat(webdav): support oc:checksums (#8064 close #7472)

Ref: #7472
This commit is contained in:
shniubobo 2025-03-14 16:21:07 +00:00 committed by GitHub
parent 0126af4de0
commit 28b61a93fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import (
"errors"
"hash"
"io"
"iter"
"github.com/alist-org/alist/v3/internal/errs"
log "github.com/sirupsen/logrus"
@ -226,3 +227,13 @@ func (hi HashInfo) GetHash(ht *HashType) string {
func (hi HashInfo) Export() map[*HashType]string {
return hi.h
}
func (hi HashInfo) All() iter.Seq2[*HashType, string] {
return func(yield func(*HashType, string) bool) {
for hashType, hashValue := range hi.h {
if !yield(hashType, hashValue) {
return
}
}
}
}

View File

@ -9,6 +9,7 @@ import (
"context"
"encoding/xml"
"errors"
"fmt"
"mime"
"net/http"
"path"
@ -101,7 +102,7 @@ type DeadPropsHolder interface {
Patch([]Proppatch) ([]Propstat, error)
}
// liveProps contains all supported, protected DAV: properties.
// liveProps contains all supported properties.
var liveProps = map[xml.Name]struct {
// findFn implements the propfind function of this property. If nil,
// it indicates a hidden property.
@ -160,6 +161,10 @@ var liveProps = map[xml.Name]struct {
findFn: findSupportedLock,
dir: true,
},
{Space: "http://owncloud.org/ns", Local: "checksums"}: {
findFn: findChecksums,
dir: false,
},
}
// TODO(nigeltao) merge props and allprop?
@ -483,3 +488,11 @@ func findSupportedLock(ctx context.Context, ls LockSystem, name string, fi model
`<D:locktype><D:write/></D:locktype>` +
`</D:lockentry>`, nil
}
func findChecksums(ctx context.Context, ls LockSystem, name string, fi model.Obj) (string, error) {
checksums := ""
for hashType, hashValue := range fi.GetHash().All() {
checksums += fmt.Sprintf("<checksum>%s:%s</checksum>", hashType.Name, hashValue)
}
return checksums, nil
}