s3browser-backend/internal/helper.go
2021-08-16 01:40:01 +02:00

37 lines
700 B
Go

package s3browser
import (
"context"
"fmt"
"path/filepath"
"github.com/graph-gophers/dataloader"
)
func invalidateCache(ctx context.Context, id string) error {
loader, ok := ctx.Value("loader").(map[string]*dataloader.Loader)
if !ok {
return fmt.Errorf("Failed to get loader from context")
}
loader["getFile"].Clear(ctx, dataloader.StringKey(id))
loader["listObjects"].Clear(ctx, dataloader.StringKey(id))
loader["getFiles"].Clear(ctx, dataloader.StringKey(getPathFromId(id)))
return nil
}
func getPathFromId(id string) string {
dir := filepath.Dir(id)
if dir == "." {
return "/"
}
return dir + "/"
}
func getFilenameFromID(id string) string {
return filepath.Base(id)
}