diff --git a/app/Http/Controllers/Settings/ExportSettings.php b/app/Http/Controllers/Settings/ExportSettings.php index 071c800e8..57349863a 100644 --- a/app/Http/Controllers/Settings/ExportSettings.php +++ b/app/Http/Controllers/Settings/ExportSettings.php @@ -9,6 +9,10 @@ use App\UserFilter; use Auth, Cookie, DB, Cache, Purify; use Carbon\Carbon; use Illuminate\Http\Request; +use App\Transformer\ActivityPub\ProfileTransformer; +use League\Fractal; +use League\Fractal\Serializer\ArraySerializer; +use League\Fractal\Pagination\IlluminatePaginatorAdapter; trait ExportSettings { @@ -18,6 +22,21 @@ trait ExportSettings return view('settings.dataexport'); } + public function exportAccount() + { + $data = Cache::remember('account:export:profile:actor:'.Auth::user()->profile->id, now()->addMinutes(60), function() { + $profile = Auth::user()->profile; + $fractal = new Fractal\Manager(); + $fractal->setSerializer(new ArraySerializer()); + $resource = new Fractal\Resource\Item($profile, new ProfileTransformer()); + return $fractal->createData($resource)->toArray(); + }); + + return response()->streamDownload(function () use ($data) { + echo json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE); + }, 'account.json'); + } + public function exportFollowing() { $data = Cache::remember('account:export:profile:following:'.Auth::user()->profile->id, now()->addMinutes(60), function() { diff --git a/resources/views/settings/dataexport.blade.php b/resources/views/settings/dataexport.blade.php index 98c6f16fd..df26ec61f 100644 --- a/resources/views/settings/dataexport.blade.php +++ b/resources/views/settings/dataexport.blade.php @@ -6,6 +6,7 @@

Data Export


+
We generate data exports once per hour, and they may not contain the latest data if you've requested them recently.
diff --git a/routes/web.php b/routes/web.php index 167c688db..664d8cdf3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -228,6 +228,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::post('data-export/following', 'SettingsController@exportFollowing')->middleware('dangerzone'); Route::post('data-export/followers', 'SettingsController@exportFollowers')->middleware('dangerzone'); Route::post('data-export/mute-block-list', 'SettingsController@exportMuteBlockList')->middleware('dangerzone'); + Route::post('data-export/account', 'SettingsController@exportAccount')->middleware('dangerzone'); Route::get('developers', 'SettingsController@developers')->name('settings.developers')->middleware('dangerzone'); });