mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Implement photos request for both immich and photoprism in single service class
This commit is contained in:
parent
360828250f
commit
202396a93d
5 changed files with 55 additions and 9 deletions
|
|
@ -3,11 +3,7 @@
|
|||
class Api::V1::PhotosController < ApiController
|
||||
def index
|
||||
@photos = Rails.cache.fetch("photos_#{params[:start_date]}_#{params[:end_date]}", expires_in: 1.day) do
|
||||
Immich::RequestPhotos.new(
|
||||
current_api_user,
|
||||
start_date: params[:start_date],
|
||||
end_date: params[:end_date]
|
||||
).call.reject { |asset| asset['type'].downcase == 'video' }
|
||||
Photos::Request.new(current_api_user, start_date: params[:start_date], end_date: params[:end_date]).call
|
||||
end
|
||||
|
||||
render json: @photos, status: :ok
|
||||
|
|
|
|||
|
|
@ -54,6 +54,14 @@ class User < ApplicationRecord
|
|||
tracked_points.select(:id).where.not(geodata: {}).count
|
||||
end
|
||||
|
||||
def immich_integration_configured?
|
||||
settings['immich_url'].present? && settings['immich_api_key'].present?
|
||||
end
|
||||
|
||||
def photoprism_integration_configured?
|
||||
settings['photoprism_url'].present? && settings['photoprism_api_key'].present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_api_key
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ class Photoprism::RequestPhotos
|
|||
public: true,
|
||||
quality: 3,
|
||||
after: start_date,
|
||||
count: 1000
|
||||
count: 1000,
|
||||
photo: 'yes'
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
38
app/services/photos/request.rb
Normal file
38
app/services/photos/request.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Photos::Request
|
||||
attr_reader :user, :start_date, :end_date
|
||||
|
||||
def initialize(user, start_date: '1970-01-01', end_date: nil)
|
||||
@user = user
|
||||
@start_date = start_date
|
||||
@end_date = end_date
|
||||
end
|
||||
|
||||
def call
|
||||
photos = []
|
||||
|
||||
photos << request_immich if user.immich_integration_configured?
|
||||
photos << request_photoprism if user.photoprism_integration_configured?
|
||||
|
||||
photos
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request_immich
|
||||
Immich::RequestPhotos.new(
|
||||
user,
|
||||
start_date: start_date,
|
||||
end_date: end_date
|
||||
).call.reject { |asset| asset['type'].downcase == 'video' }
|
||||
end
|
||||
|
||||
def request_photoprism
|
||||
Photoprism::RequestPhotos.new(
|
||||
user,
|
||||
start_date: start_date,
|
||||
end_date: end_date
|
||||
).call.select { |asset| asset['Type'].downcase == 'image' }
|
||||
end
|
||||
end
|
||||
|
|
@ -231,7 +231,8 @@ RSpec.describe Photoprism::RequestPhotos do
|
|||
count: '1000',
|
||||
public: 'true',
|
||||
q: '',
|
||||
quality: '3'
|
||||
quality: '3',
|
||||
photo: 'yes'
|
||||
}
|
||||
)
|
||||
.to_return(status: 200, body: first_page.to_json)
|
||||
|
|
@ -247,7 +248,8 @@ RSpec.describe Photoprism::RequestPhotos do
|
|||
public: 'true',
|
||||
q: '',
|
||||
quality: '3',
|
||||
offset: '1000'
|
||||
offset: '1000',
|
||||
photo: 'yes'
|
||||
}
|
||||
)
|
||||
.to_return(status: 200, body: second_page.to_json)
|
||||
|
|
@ -263,7 +265,8 @@ RSpec.describe Photoprism::RequestPhotos do
|
|||
public: 'true',
|
||||
q: '',
|
||||
quality: '3',
|
||||
offset: '2000'
|
||||
offset: '2000',
|
||||
photo: 'yes'
|
||||
}
|
||||
)
|
||||
.to_return(status: 200, body: empty_page.to_json)
|
||||
|
|
|
|||
Loading…
Reference in a new issue