2024-08-28 14:24:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class Api::V1::SettingsController < ApiController
|
2025-02-19 15:23:11 -05:00
|
|
|
before_action :authenticate_active_api_user!, only: %i[update]
|
|
|
|
|
|
2024-08-28 14:24:35 -04:00
|
|
|
def index
|
|
|
|
|
render json: {
|
2025-12-06 14:54:49 -05:00
|
|
|
settings: current_api_user.safe_settings.config,
|
2024-08-28 14:24:35 -04:00
|
|
|
status: 'success'
|
|
|
|
|
}, status: :ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
settings_params.each { |key, value| current_api_user.settings[key] = value }
|
|
|
|
|
|
|
|
|
|
if current_api_user.save
|
2025-12-06 14:54:49 -05:00
|
|
|
render json: { message: 'Settings updated', settings: current_api_user.safe_settings.config, status: 'success' },
|
2024-12-02 10:52:05 -05:00
|
|
|
status: :ok
|
2024-08-28 14:24:35 -04:00
|
|
|
else
|
2024-12-02 10:52:05 -05:00
|
|
|
render json: { message: 'Something went wrong', errors: current_api_user.errors.full_messages },
|
2025-09-12 15:08:45 -04:00
|
|
|
status: :unprocessable_content
|
2024-08-28 14:24:35 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def settings_params
|
|
|
|
|
params.require(:settings).permit(
|
|
|
|
|
:meters_between_routes, :minutes_between_routes, :fog_of_war_meters,
|
2024-09-15 15:04:13 -04:00
|
|
|
:time_threshold_minutes, :merge_threshold_minutes, :route_opacity,
|
2024-12-02 10:52:05 -05:00
|
|
|
:preferred_map_layer, :points_rendering_mode, :live_map_enabled,
|
2025-01-10 18:42:44 -05:00
|
|
|
:immich_url, :immich_api_key, :photoprism_url, :photoprism_api_key,
|
2025-10-20 14:11:28 -04:00
|
|
|
:speed_colored_routes, :speed_color_scale, :fog_of_war_threshold,
|
2025-12-06 14:54:49 -05:00
|
|
|
:maps_v2_style, :maps_maplibre_style,
|
2025-10-20 14:11:28 -04:00
|
|
|
enabled_map_layers: []
|
2024-08-28 14:24:35 -04:00
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|