Skip to content

Commit

Permalink
feat: Switching to new exas model
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed May 25, 2024
1 parent 73720b1 commit 6f817e8
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 133 deletions.
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ In order to work, your user **must have** `admin` profile sets with the `-authPr

With help of different sidecars, Fibr can generate image, video and PDF thumbnails. These sidecars can be self hosted with ease. It can also extract and enrich content displayed by looking at [EXIF Data](https://en.wikipedia.org/wiki/Exif), also with the help of a little sidecar. These behaviours are opt-out (if you remove the `url` of the service, Fibr will do nothing).

For the last mile, Fibr can try to reverse geocoding the GPS data found in EXIF, using [Open Street Map](https://wiki.openstreetmap.org/wiki/Nominatim). Self-hosting this kind of service can be complicated and calling a third-party party with such sensible datas is an opt-in decision.

### Metrics

Fibr exposes a lot of metrics via OpenTelemetry gRPC mode. Common metrics are exposed: Golang statistics, HTTP statuses and response time, AMQP statuses and sidecars/metadatas actions.
Expand Down
11 changes: 5 additions & 6 deletions cmd/fibr/templates/exif.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ <h2 class="flex flex-center header no-margin">
</p>
{{ end }}

{{ if or .Exif.Geocode.HasAddress .Exif.Geocode.HasCoordinates }}
{{ if or .Exif.Coordinates .Exif.HasAddress }}
<p class="padding no-margin code">
{{ if .Exif.Geocode.HasCoordinates }}
<strong>Coordinates:</strong> <a class="primary" href="http://www.openstreetmap.org/?mlat={{ .Exif.Geocode.Latitude }}&mlon={{ .Exif.Geocode.Longitude }}&zoom=16">{{ .Exif.Geocode.Latitude }},{{ .Exif.Geocode.Longitude }}</a><br>
{{ if .Exif.Coordinates }}
<strong>Coordinates:</strong> <a class="primary" href="http://www.openstreetmap.org/?mlat={{ index .Exif.Coordinates 0 }}&mlon={{ index .Exif.Coordinates 1 }}&zoom=16">{{ index .Exif.Coordinates 0 }},{{ index .Exif.Coordinates 1 }}</a><br>
{{ end }}

<strong>Location</strong><br>
{{ range $key, $value := .Exif.Geocode.Address }}
  <em>{{ $key }}:</em> {{ $value }}<br>
{{ end }}
  <em>City:</em> {{ .Exif.GetCity }}<br>
  <em>Country:</em> {{ .Exif.GetCountry }}<br>
</p>
{{ end }}

Expand Down
20 changes: 6 additions & 14 deletions cmd/fibr/templates/story.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,27 +193,19 @@
</a>

<div class="description relative">
{{ if or (.Exif.Geocode.HasAddress) (not .Exif.Date.IsZero) }}
{{ if or (.Exif.HasAddress) (not .Exif.Date.IsZero) }}
<p class="context">
{{ if .Exif.Geocode.HasAddress }}
{{ if .Exif.HasAddress }}
<img class="icon margin-right-half" src="{{ url "/svg/location?fill=%23000000" }}" alt="location">
<span>
{{ if index .Exif.Geocode.Address "city_district" }}
{{ index .Exif.Geocode.Address "city_district" }},
{{ else }}
{{ if index .Exif.Geocode.Address "village" }}
{{ index .Exif.Geocode.Address "village" }},
{{ else }}
{{ if index .Exif.Geocode.Address "county" }}
{{ index .Exif.Geocode.Address "county" }},
{{- end }}
{{- end }}
{{- end }} {{ index .Exif.Geocode.Address "country" }}
{{ if .Exif.GetCity }}
{{ .Exif.GetCity }},
{{- end }} {{ .Exif.GetCountry }}
{{ end }}
</span>

{{ if not .Exif.Date.IsZero }}
<img class="icon margin-right-half{{ if .Exif.Geocode.HasAddress }} margin-left-half{{ end }}" src="{{ url "/svg/calendar?fill=%23000000" }}" alt="calendar">
<img class="icon margin-right-half{{ if .Exif.HasAddress }} margin-left-half{{ end }}" src="{{ url "/svg/calendar?fill=%23000000" }}" alt="calendar">
<span class="date">{{ .Exif.Date.Format "2006-01-02T15:04:05Z07:00" }}</span>
{{ end }}
</p>
Expand Down
1 change: 0 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ services:
environment:
EXAS_AMQP_URI: 'amqp://guest:guest@rabbit:5672/'
EXAS_AMQP_WAIT_TIMEOUT: '30s'
EXAS_GEOCODE_URL: 'https://nominatim.openstreetmap.org'
EXAS_STORAGE_FILE_SYSTEM_DIRECTORY: '/data'
volumes:
- '${DATA_DIR}:/data'
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/ViBiOh/ChatPotte v0.4.6
github.com/ViBiOh/absto v1.7.10
github.com/ViBiOh/auth/v2 v2.18.4
github.com/ViBiOh/exas v0.7.1
github.com/ViBiOh/exas v0.8.0
github.com/ViBiOh/flags v1.5.0
github.com/ViBiOh/httputils/v4 v4.76.0
github.com/ViBiOh/vith v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/ViBiOh/absto v1.7.10 h1:8z+F/46Y+uyddacBS9PQvHUJDev0K0LZLv4L4YgZXRQ=
github.com/ViBiOh/absto v1.7.10/go.mod h1:MWd8MRDAAUOl6wGqte7U4wugXfRGageltfchOK7K6AQ=
github.com/ViBiOh/auth/v2 v2.18.4 h1:XV825Y3oTJZrg9yBe74rLvqaCJ7bjUBoPdp4SN2CVXI=
github.com/ViBiOh/auth/v2 v2.18.4/go.mod h1:vZ00r7g+aQ8RF6fApTruQRZyKZ1n7ZSrIpo02uLrZk4=
github.com/ViBiOh/exas v0.7.1 h1:nzh6E1668OFRgoTIJZJa1RybCW64Gd918qi0Z+0Q4WA=
github.com/ViBiOh/exas v0.7.1/go.mod h1:MvIWQZXpWgg45Vsde9bMV48Kb0J8frya8vimmrkQ04E=
github.com/ViBiOh/exas v0.8.0 h1:C+3zeKH+VAK2HQxR3wvLqLxOwUXM+R3iYFlR6aJta/k=
github.com/ViBiOh/exas v0.8.0/go.mod h1:aldybvPY4yJQlvUpq6GJluGxH+7prpaJjDQ03t3VvCw=
github.com/ViBiOh/flags v1.5.0 h1:nwuFS8tAwtV6rTPpv2pCB+r12WjZYLjluW7yT+SeVpQ=
github.com/ViBiOh/flags v1.5.0/go.mod h1:39UMuTnKsIp6walgD8dK99KRCb4DJt9vPtbWehHh1T0=
github.com/ViBiOh/httputils/v4 v4.76.0 h1:fNMACQxmyPsSHFVeXitLw7BpO1Pm0yrWrTfKk2hSdvQ=
Expand Down
6 changes: 3 additions & 3 deletions pkg/crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (s Service) generateGeoJSON(ctx context.Context, w io.Writer, request provi
return
}

if !exif.Geocode.HasCoordinates() {
if exif.Coordinates == nil {
continue
}

Expand All @@ -267,8 +267,8 @@ func (s Service) generateGeoJSON(ctx context.Context, w io.Writer, request provi
commaNeeded = true
}

point.Coordinates.Latitude = exif.Geocode.Latitude
point.Coordinates.Longitude = exif.Geocode.Longitude
point.Coordinates.Latitude = exif.Coordinates[0]
point.Coordinates.Longitude = exif.Coordinates[1]

feature.Properties["url"] = request.RelativeURL(item)
feature.Properties["date"] = exif.Date.Format(time.RFC850)
Expand Down
21 changes: 6 additions & 15 deletions pkg/crud/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,20 @@ func BenchmarkServeGeoJSON(b *testing.B) {
mockExif.EXPECT().GetAllMetadataFor(gomock.Any(), gomock.Any()).Return(map[string]provider.Metadata{
"9012": {
Exif: exas.Exif{
Geocode: exas.Geocode{
Latitude: 1.0,
Longitude: 1.0,
},
Date: time.Date(2022, 0o2, 22, 22, 0o2, 22, 0, time.UTC),
Coordinates: &exas.LatLng{1.0, 1.0},
Date: time.Date(2022, 0o2, 22, 22, 0o2, 22, 0, time.UTC),
},
},
"5678": {
Exif: exas.Exif{
Geocode: exas.Geocode{
Latitude: 1.0,
Longitude: 1.0,
},
Date: time.Date(2022, 0o2, 22, 22, 0o2, 22, 0, time.UTC),
Coordinates: &exas.LatLng{1.0, 1.0},
Date: time.Date(2022, 0o2, 22, 22, 0o2, 22, 0, time.UTC),
},
},
"1234": {
Exif: exas.Exif{
Geocode: exas.Geocode{
Latitude: 1.0,
Longitude: 1.0,
},
Date: time.Date(2022, 0o2, 22, 22, 0o2, 22, 0, time.UTC),
Coordinates: &exas.LatLng{1.0, 1.0},
Date: time.Date(2022, 0o2, 22, 22, 0o2, 22, 0, time.UTC),
},
},
}, nil).AnyTimes()
Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s Service) search(r *http.Request, request provider.Request, item absto.It

items[i] = renderItem

if !hasMap && metadata.Geocode.Longitude != 0 && metadata.Geocode.Latitude != 0 {
if !hasMap && metadata.Coordinates != nil {
hasMap = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/story.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s Service) story(r *http.Request, request provider.Request, item absto.Ite

exif := exifs[file.ID]

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

Expand Down
18 changes: 3 additions & 15 deletions pkg/metadata/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
)

var (
aggregateRatio = 0.4

levels = []string{"city", "state", "country"}
)

func redisKey(item absto.Item) string {
return version.Redis("exif:" + item.ID)
}
Expand Down Expand Up @@ -111,7 +105,6 @@ func (s Service) aggregate(ctx context.Context, item absto.Item) error {
}

func (s Service) computeAndSaveAggregate(ctx context.Context, dir absto.Item) error {
directoryAggregate := newAggregate()
var minDate, maxDate time.Time

previousAggregate, _ := s.GetAggregateFor(ctx, dir)
Expand All @@ -134,21 +127,16 @@ func (s Service) computeAndSaveAggregate(ctx context.Context, dir absto.Item) er
minDate, maxDate = aggregateDate(minDate, maxDate, exifData.Date)
}

if exifData.Geocode.HasAddress() {
directoryAggregate.ingest(exifData.Geocode)
}

return nil
})
if err != nil {
return fmt.Errorf("aggregate: %w", err)
}

return s.SaveAggregateFor(ctx, dir, provider.Aggregate{
Cover: previousAggregate.Cover,
Location: directoryAggregate.value(),
Start: minDate,
End: maxDate,
Cover: previousAggregate.Cover,
Start: minDate,
End: maxDate,
})
}

Expand Down
70 changes: 0 additions & 70 deletions pkg/metadata/model.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/provider/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type ExifResponse struct {
}

type Metadata struct {
exas.Exif
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
exas.Exif
}

type Aggregate struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

var (
cacheVersion = provider.Hash("vibioh/fibr/3")[:8]
cacheVersion = provider.Hash("vibioh/fibr/4")[:8]
cachePrefix = "fibr:" + cacheVersion
)

Expand Down

0 comments on commit 6f817e8

Please sign in to comment.