Skip to content

Commit

Permalink
feat(story): Adding map icon if possible
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed May 19, 2022
1 parent 6ea3757 commit e2f7829
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
6 changes: 6 additions & 0 deletions cmd/fibr/templates/story.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
</a>

<span class="flex-grow"></span>

{{ if .HasMap }}
<a class="padding" href="#map" download>
<img class="icon" src="{{ url "/svg/map?fill=aliceblue" }}" alt="View on map">
</a>
{{ end }}
</div>

<ul id="files" class="no-margin no-padding">
Expand Down
23 changes: 19 additions & 4 deletions pkg/crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (a App) handleDir(w http.ResponseWriter, r *http.Request, request provider.
return a.Stats(w, r, request, message)
}

items, err := a.listFiles(r, request)
items, err := a.listFiles(r, request, item)
if err != nil {
return errorReturn(request, err)
}
Expand Down Expand Up @@ -131,14 +131,14 @@ func (a App) handleDir(w http.ResponseWriter, r *http.Request, request provider.

provider.SetPrefsCookie(w, request)

if request.Display == provider.StoryDisplay {
if request.IsStory() {
return a.story(r, request, item, items)
}

return a.List(r.Context(), request, message, item, items)
}

func (a App) listFiles(r *http.Request, request provider.Request) (items []absto.Item, err error) {
func (a App) listFiles(r *http.Request, request provider.Request, item absto.Item) (items []absto.Item, err error) {
ctx := r.Context()
if a.tracer != nil {
var span trace.Span
Expand All @@ -152,6 +152,21 @@ func (a App) listFiles(r *http.Request, request provider.Request) (items []absto
items, err = a.storageApp.List(ctx, request.Filepath())
}

if request.IsStory() {
thumbnails, err := a.thumbnailApp.ListDirLarge(ctx, item)
if err != nil {
logger.WithField("item", item.Pathname).Error("unable to list large thumbnails: %s", err)
}

storyItems := items[:0]
for _, item := range items {
if _, ok := thumbnails[a.thumbnailApp.PathForLarge(item)]; ok {
storyItems = append(storyItems, item)
}
}
items = storyItems
}

sort.Sort(provider.ByHybridSort(items))

return items, err
Expand All @@ -166,7 +181,7 @@ func (a App) serveGeoJSON(w http.ResponseWriter, r *http.Request, request provid
ctx := r.Context()

var hash string
if query.GetBool(r, "search") {
if query.GetBool(r, "search") || request.IsStory() {
hash = a.exifHash(ctx, items)
} else if exifs, err := a.exifApp.ListDir(ctx, item); err == nil {
hash = sha.New(exifs)
Expand Down
15 changes: 6 additions & 9 deletions pkg/crud/story.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ func (a App) story(r *http.Request, request provider.Request, item absto.Item, f
defer span.End()
}

thumbnails, err := a.thumbnailApp.ListDirLarge(ctx, item)
if err != nil {
logger.WithField("item", item.Pathname).Error("unable to list thumbnail: %s", err)
}

items := make([]provider.StoryItem, 0, len(files))
var cover map[string]any
var hasMap bool

for _, item := range files {
if _, ok := thumbnails[a.thumbnailApp.PathForLarge(item)]; !ok {
continue
}

if cover == nil {
cover = map[string]any{
"Img": provider.StorageToRender(item, request),
Expand All @@ -45,6 +37,10 @@ func (a App) story(r *http.Request, request provider.Request, item absto.Item, f
logger.WithField("item", item.Pathname).Error("unable to get exif: %s", err)
}

if !hasMap && exif.Geocode.HasCoordinates() {
hasMap = true
}

items = append(items, provider.StorageToStory(item, request, exif))
}

Expand All @@ -55,6 +51,7 @@ func (a App) story(r *http.Request, request provider.Request, item absto.Item, f
"Files": items,
"Cover": cover,
"Request": request,
"HasMap": hasMap,
"ThumbnailLargeSize": a.thumbnailApp.LargeThumbnailSize(),
}), nil
}
5 changes: 5 additions & 0 deletions pkg/provider/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func (r Request) RelativeURL(item absto.Item) string {
return strings.TrimPrefix(pathname, r.Path)
}

// IsStory returns true if request is story mode
func (r Request) IsStory() bool {
return r.Display == StoryDisplay
}

// AbsoluteURL compute absolute URL for the given name
func (r Request) AbsoluteURL(name string) string {
return Join("/", r.Share.ID, r.Path, name)
Expand Down

0 comments on commit e2f7829

Please sign in to comment.