-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
Currently uses in memory caching and loads the file from the local filesystem.
If the file is not cached we have to get it from somewhere. For that I implemented a webdav file source which gets the file from reva.
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
w.Write([]byte("Hello ocis-thumbnails!")) | ||
encoder := thumbnails.EncoderForType(fileType) | ||
if encoder == nil { | ||
// TODO: better error responses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use https://golang.org/pkg/net/http/#Error here and in all subsequent cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. But since the API will be changed in another PR anyways I would leave it like that for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 a bit of nitty-gritty regarding functionality and style. Other than that looks good. Still need to run it locally tho.
pkg/flagset/flagset.go
Outdated
@@ -89,7 +89,7 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { | |||
}, | |||
&cli.StringFlag{ | |||
Name: "debug-addr", | |||
Value: "0.0.0.0:9114", | |||
Value: "0.0.0.0:9194", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure to reserve a port range here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I wanted to change that back... But yes we should define a port for the service.
pkg/thumbnails/storage/filesystem.go
Outdated
// NewFileSystemStorage creates a new instanz of FileSystem | ||
func NewFileSystemStorage(cfg config.FileSystemStorage) FileSystem { | ||
return FileSystem{ | ||
dir: cfg.RootDirectory, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work on non UNIX systems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave UNIX by default and on a Before
hook check the host OS and update config
func (s FileSystem) Set(key string, img []byte) error { | ||
path := filepath.Join(s.dir, key) | ||
dir := filepath.Dir(path) | ||
if err := os.MkdirAll(dir, 0700); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it need execution permissions? or can this be set to 0600
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, execution permission is needed to be able to read or write files in the directory.
pkg/thumbnails/storage/filesystem.go
Outdated
|
||
f, err := os.Create(path) | ||
if err != nil { | ||
fmt.Println(err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a proper logger
pkg/service/v0/service.go
Outdated
} | ||
|
||
m.Route(options.Config.HTTP.Root, func(r chi.Router) { | ||
r.Get("/", svc.Dummy) | ||
r.Get("/thumbnails", svc.Thumbnails) | ||
}) | ||
|
||
return svc | ||
} | ||
|
||
// Thumbnails defines implements the business logic for Service. | ||
type Thumbnails struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change annotation to:
Thumbnails implements the business logic for Service.
Also use the singular, as in Thumbnail
💃
pkg/service/v0/service.go
Outdated
width, _ := strconv.Atoi(query.Get("width")) | ||
height, _ := strconv.Atoi(query.Get("height")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add error handling here, make it more explicit where a failure might happen
pkg/service/v0/service.go
Outdated
height, _ := strconv.Atoi(query.Get("height")) | ||
fileType := query.Get("type") | ||
filePath := query.Get("file_path") | ||
etag := query.Get("etag") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking I'd declare a struct
and try to unmarshal the request query string onto it, then operate with typed fields. It is the same concept you're doing here but a bit more explicit. We could give it a try together
pkg/service/v0/service.go
Outdated
if encoder == nil { | ||
// TODO: better error responses | ||
w.WriteHeader(http.StatusBadRequest) | ||
w.Write([]byte("can't encode that")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a logger from ocis-pkg
so we have persisted logs and not only the user can see it. I'm also fond of using the passive voice, as in:
can't be encoded
Furthermore the error message is not informative enough, since you're checking whether the fileType
is supported or not by fetching an encoder for it, it should read more like:
encoding for filetype: .XYZ is not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to replace that when the proper API is implemented.
} | ||
|
||
// NewContext creates a new SourceContext instance | ||
func NewContext() SourceContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you considered using context.Context
here? You can still store key-values on a typed and thread safe manner 🗡
} | ||
|
||
func mapToStorageContext(ctx Context) storage.Context { | ||
sCtx := storage.Context{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as with the previous context.Context
comment. By adopting that idiom you could even chain them like middlewares
Also don't forget to add a changelog 💃 |
The only things left now are the things I want to change in another PR when I'll implement the proper API. Or should I do it here? |
So now I added the grpc service. @refs could you have another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for adding traces and metrics!
} else { | ||
logger.Debug(). | ||
Msg("") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover? or intended to populate this with a message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I copied it from ocis-hello.
I thought it would then log at least the stuff from line 30 and 31
Can generate thumbnails and store them in the filesystem.
Still missing:
Example request: