Use POST /api/search/metadata endpoint to get geodata from Immich

This commit is contained in:
Eugene Burmakin 2024-11-18 15:41:43 +01:00
parent f24d47c9cd
commit 11762d528b
4 changed files with 104 additions and 13 deletions

View file

@ -1 +1 @@
0.16.4
0.16.5

View file

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
# 0.16.5 - 2024-11-18
### Changed
- Dawarich now uses `POST /api/search/metadata` endpoint to get geodata from Immich.
# 0.16.4 - 2024-11-12
### Added

View file

@ -40,17 +40,45 @@ class Immich::ImportGeodata
end
def retrieve_immich_data
1970.upto(Time.zone.today.year).flat_map do |year|
(1..12).map do |month_number|
url = "#{immich_api_base_url}/timeline/bucket?size=MONTH&timeBucket=#{year}-#{month_number}-01"
url = "#{immich_api_base_url}/search/metadata"
page = 1
data = []
max_pages = 1000 # Prevent infinite loop
JSON.parse(HTTParty.get(url, headers:).body)
while page <= max_pages
Rails.logger.debug "Retrieving next page: #{page}"
body = request_body(page)
response = JSON.parse(HTTParty.post(url, headers: headers, body: body).body)
items = response.dig('assets', 'items')
Rails.logger.debug "#{items.size} items found"
break if items.empty?
data << items
Rails.logger.debug "next_page: #{response.dig('assets', 'nextPage')}"
page += 1
Rails.logger.debug "#{data.flatten.size} data size"
end
data.flatten
end
def request_body(page)
{
createdAfter: '1970-01-01',
size: 1000,
page: page,
order: 'asc',
withExif: true
}
end
def parse_immich_data(immich_data)
geodata = immich_data.flatten.map do |asset|
geodata = immich_data.map do |asset|
next unless valid?(asset)
extract_geodata(asset)

View file

@ -11,10 +11,68 @@ RSpec.describe Immich::ImportGeodata do
end
let(:immich_data) do
{
"albums": {
"total": 0,
"count": 0,
"items": [],
"facets": []
},
"assets": {
"total": 1000,
"count": 1000,
"items": [
{
"id": "7fe486e3-c3ba-4b54-bbf9-1281b39ed15c",
"deviceAssetId": "IMG_9913.jpeg-1168914",
"ownerId": "f579f328-c355-438c-a82c-fe3390bd5f08",
"deviceId": "CLI",
"libraryId": nil,
"type": "IMAGE",
"originalPath": "upload/library/admin/2023/2023-06-08/IMG_9913.jpeg",
"originalFileName": "IMG_9913.jpeg",
"originalMimeType": "image/jpeg",
"thumbhash": "4RgONQaZqYaH93g3h3p3d6RfPPrG",
"fileCreatedAt": "2023-06-08T07:58:45.637Z",
"fileModifiedAt": "2023-06-08T09:58:45.000Z",
"localDateTime": "2023-06-08T09:58:45.637Z",
"updatedAt": "2024-08-24T18:20:47.965Z",
"isFavorite": false,
"isArchived": false,
"isTrashed": false,
"duration": "0:00:00.00000",
"exifInfo": {
"dateTimeOriginal": '2022-12-31T23:21:53.140Z',
"latitude": 52.0000,
"longitude": 13.0000
"make": "Apple",
"model": "iPhone 12 Pro",
"exifImageWidth": 4032,
"exifImageHeight": 3024,
"fileSizeInByte": 1168914,
"orientation": "6",
"dateTimeOriginal": "2023-06-08T07:58:45.637Z",
"modifyDate": "2023-06-08T07:58:45.000Z",
"timeZone": "Europe/Berlin",
"lensModel": "iPhone 12 Pro back triple camera 4.2mm f/1.6",
"fNumber": 1.6,
"focalLength": 4.2,
"iso": 320,
"exposureTime": "1/60",
"latitude": 52.11,
"longitude": 13.22,
"city": "Johannisthal",
"state": "Berlin",
"country": "Germany",
"description": "",
"projectionType": nil,
"rating": nil
},
"livePhotoVideoId": nil,
"people": [],
"checksum": "aL1edPVg4ZpEnS6xCRWNUY0pUS8=",
"isOffline": false,
"hasMetadata": true,
"duplicateId": "88a34bee-783d-46e4-aa52-33b75ffda375",
"resized": true
}
]
}
}.to_json
end
@ -23,8 +81,7 @@ RSpec.describe Immich::ImportGeodata do
before do
stub_request(
:any,
%r{http://immich\.app/api/timeline/bucket\?size=MONTH&timeBucket=(19[7-9][0-9]|20[0-9]{2})-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01])}
).to_return(status: 200, body: immich_data, headers: {})
'http://immich.app/api/search/metadata').to_return(status: 200, body: immich_data, headers: {})
end
it 'creates import' do