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

reduce hacky reference handling in thumbnailer #3669

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changelog/unreleased/new-space-id-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Change: Use new space ID util functions
Changed code to use the new space ID util functions so that everything works with the new spaces ID format.

https://github.com/owncloud/ocis/pull/3648
https://github.com/owncloud/ocis/pull/3669
16 changes: 6 additions & 10 deletions extensions/thumbnails/pkg/service/grpc/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,16 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context,
func (g Thumbnail) stat(path, auth string) (*provider.StatResponse, error) {
ctx := metadata.AppendToOutgoingContext(context.Background(), revactx.TokenHeader, auth)

var ref *provider.Reference
if strings.Contains(path, "!") {
parsed, err := storagespace.ParseReference(path)
if err != nil {
return nil, err
}
ref = &parsed
} else {
ref = &provider.Reference{
ref, err := storagespace.ParseReference(path)
if err != nil {
// If the path is not a spaces reference try to handle it like a plain
// path reference.
ref = provider.Reference{
Path: path,
}
}

req := &provider.StatRequest{Ref: ref}
req := &provider.StatRequest{Ref: &ref}
rsp, err := g.cs3Client.Stat(ctx, req)
if err != nil {
g.logger.Error().Err(err).Str("path", path).Msg("could not stat file")
Expand Down
17 changes: 6 additions & 11 deletions extensions/thumbnails/pkg/thumbnail/imgsource/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"net/http"
"strings"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
Expand Down Expand Up @@ -44,20 +43,16 @@ func (s CS3) Get(ctx context.Context, path string) (io.ReadCloser, error) {
if !ok {
return nil, errors.New("cs3source: authorization missing")
}
var ref *provider.Reference
if strings.Contains(path, "!") {
parsed, err := storagespace.ParseReference(path)
if err != nil {
return nil, err
}
ref = &parsed
} else {
ref = &provider.Reference{
ref, err := storagespace.ParseReference(path)
if err != nil {
// If the path is not a spaces reference try to handle it like a plain
// path reference.
ref = provider.Reference{
Path: path,
}
}
ctx = metadata.AppendToOutgoingContext(context.Background(), revactx.TokenHeader, auth)
rsp, err := s.client.InitiateFileDownload(ctx, &provider.InitiateFileDownloadRequest{Ref: ref})
rsp, err := s.client.InitiateFileDownload(ctx, &provider.InitiateFileDownloadRequest{Ref: &ref})

if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion extensions/webdav/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (g Webdav) SpacesThumbnail(w http.ResponseWriter, r *http.Request) {
}
t := r.Header.Get(TokenHeader)

fullPath := tr.Identifier + "!" + tr.Filepath
fullPath := tr.Identifier + tr.Filepath
rsp, err := g.thumbnailsClient.GetThumbnail(r.Context(), &thumbnailssvc.GetThumbnailRequest{
Filepath: strings.TrimLeft(tr.Filepath, "/"),
ThumbnailType: extensionToThumbnailType(strings.TrimLeft(tr.Extension, ".")),
Expand Down