Skip to content

Commit

Permalink
Reverse geocoding is now under feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilyOrg committed Aug 3, 2023
1 parent 1168370 commit d89cb90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
10 changes: 10 additions & 0 deletions defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ tags:
# exif:
# enable: true

geo:
# Reverse geocode coordinates to location names. Runs fully locally
# via the "rgeo" Golang library. Currently only supported in the
# timeline layout.
#
# Can delay startup by up to a minute as the local geolocation
# database is loaded.
#
# reverse_geocode: true

media:
# Extract metadata from this many files concurrently
concurrent_meta_loads: 8
Expand Down
21 changes: 15 additions & 6 deletions internal/image/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

var ErrNotFound = errors.New("not found")
var ErrNotAnImage = errors.New("not a supported image extension, might be video")
var ErrUnavailable = errors.New("unavailable")

type ImageId uint32

Expand Down Expand Up @@ -109,9 +110,14 @@ type Caches struct {
Image CacheConfig
}

type Geo struct {
ReverseGeocode bool `json:"reverse_geocode"`
}

type Config struct {
DataDir string
AI clip.AI
Geo Geo
TagConfig tag.Config `json:"-"`

ExifToolCount int `json:"exif_tool_count"`
Expand Down Expand Up @@ -169,12 +175,12 @@ func NewSource(config Config, migrations embed.FS, migrationsThumbs embed.FS) *S
source.imageInfoCache = newInfoCache()
source.pathCache = newPathCache()

r, err := rgeo.New(rgeo.Provinces10, rgeo.Cities10)

if err != nil {
// Handle error
fmt.Println("RGEO ERR", err)
} else {
if config.Geo.ReverseGeocode {
log.Println("rgeo loading")
r, err := rgeo.New(rgeo.Provinces10, rgeo.Cities10)
if err != nil {
log.Fatalf("failed to initialize rgeo: %s", err)
}
source.rg = r
}

Expand Down Expand Up @@ -285,6 +291,9 @@ func NewSource(config Config, migrations embed.FS, migrationsThumbs embed.FS) *S
}

func (source *Source) ReverseGeocode(l s2.LatLng) (string, error) {
if source.rg == nil {
return "", ErrUnavailable
}
location, err := source.rg.ReverseGeocode([]float64{l.Lng.Degrees(), l.Lat.Degrees()})
if err != nil {
return "", err
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ type AppConfig struct {
Render render.Render `json:"render"`
Media image.Config `json:"media"`
AI clip.AI `json:"ai"`
Geo image.Geo `json:"geo"`
Tags tag.Config `json:"tags"`
TileRequests TileRequestConfig `json:"tile_requests"`
}
Expand Down Expand Up @@ -1065,6 +1066,7 @@ func loadConfiguration(path string) AppConfig {
}

appConfig.Media.AI = appConfig.AI
appConfig.Media.Geo = appConfig.Geo
appConfig.Tags.Enable = appConfig.Tags.Enable || appConfig.Tags.Enabled

return appConfig
Expand Down

0 comments on commit d89cb90

Please sign in to comment.