Add JSON API support for user data exports (#2786)

This commit is contained in:
Rob Zolkos
2026-04-08 08:17:24 -04:00
committed by GitHub
parent 98b6bdcfb7
commit 8201c2a4bd
5 changed files with 183 additions and 3 deletions
@@ -7,11 +7,20 @@ class Users::DataExportsController < ApplicationController
CURRENT_EXPORT_LIMIT = 10
def show
respond_to do |format|
format.html
format.json { @export ? render(:show) : head(:not_found) }
end
end
def create
@user.data_exports.create!(account: Current.account).build_later
redirect_to @user, notice: "Export started. You'll receive an email when it's ready."
@export = @user.data_exports.create!(account: Current.account)
@export.build_later
respond_to do |format|
format.html { redirect_to @user, notice: "Export started. You'll receive an email when it's ready." }
format.json { render :show, status: :created }
end
end
private
@@ -28,6 +37,7 @@ class Users::DataExportsController < ApplicationController
end
def set_export
@export = @user.data_exports.completed.find_by(id: params[:id])
scope = request.format.json? ? @user.data_exports : @user.data_exports.completed
@export = scope.find_by(id: params[:id])
end
end
@@ -0,0 +1,6 @@
json.(@export, :id, :status)
json.created_at @export.created_at.utc
if @export.completed? && @export.file.attached?
json.download_url rails_blob_url(@export.file, disposition: "attachment")
end