From de8d472527e805c02c1ed96c879b20163cea843d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 24 Apr 2019 13:32:23 -0600 Subject: [PATCH 1/2] Move data export to its own controller --- .../Controllers/Settings/ExportSettings.php | 65 +++++++++++++++++++ app/Http/Controllers/SettingsController.php | 53 +-------------- 2 files changed, 68 insertions(+), 50 deletions(-) create mode 100644 app/Http/Controllers/Settings/ExportSettings.php diff --git a/app/Http/Controllers/Settings/ExportSettings.php b/app/Http/Controllers/Settings/ExportSettings.php new file mode 100644 index 00000000..071c800e --- /dev/null +++ b/app/Http/Controllers/Settings/ExportSettings.php @@ -0,0 +1,65 @@ +profile->id, now()->addMinutes(60), function() { + return Auth::user()->profile->following()->get()->map(function($i) { + return $i->url(); + }); + }); + return response()->streamDownload(function () use($data) { + echo $data; + }, 'following.json'); + } + + public function exportFollowers() + { + $data = Cache::remember('account:export:profile:followers:'.Auth::user()->profile->id, now()->addMinutes(60), function() { + return Auth::user()->profile->followers()->get()->map(function($i) { + return $i->url(); + }); + }); + return response()->streamDownload(function () use($data) { + echo $data; + }, 'followers.json'); + } + + public function exportMuteBlockList() + { + $profile = Auth::user()->profile; + $exists = UserFilter::select('id') + ->whereUserId($profile->id) + ->exists(); + if(!$exists) { + return redirect()->back(); + } + $data = Cache::remember('account:export:profile:muteblocklist:'.Auth::user()->profile->id, now()->addMinutes(60), function() use($profile) { + return json_encode([ + 'muted' => $profile->mutedProfileUrls(), + 'blocked' => $profile->blockedProfileUrls() + ], JSON_PRETTY_PRINT); + }); + return response()->streamDownload(function () use($data) { + echo $data; + }, 'muted-and-blocked-accounts.json'); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 264ab393..9365d620 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -10,6 +10,7 @@ use Auth, Cookie, DB, Cache, Purify; use Carbon\Carbon; use Illuminate\Http\Request; use App\Http\Controllers\Settings\{ + ExportSettings, HomeSettings, PrivacySettings, SecuritySettings @@ -18,7 +19,8 @@ use App\Jobs\DeletePipeline\DeleteAccountPipeline; class SettingsController extends Controller { - use HomeSettings, + use ExportSettings, + HomeSettings, PrivacySettings, SecuritySettings; @@ -67,55 +69,6 @@ class SettingsController extends Controller return view('settings.applications'); } - public function dataExport() - { - return view('settings.dataexport'); - } - - public function exportFollowing() - { - $data = Cache::remember('account:export:profile:following:'.Auth::user()->profile->id, now()->addMinutes(60), function() { - return Auth::user()->profile->following()->get()->map(function($i) { - return $i->url(); - }); - }); - return response()->streamDownload(function () use($data) { - echo $data; - }, 'following.json'); - } - - public function exportFollowers() - { - $data = Cache::remember('account:export:profile:followers:'.Auth::user()->profile->id, now()->addMinutes(60), function() { - return Auth::user()->profile->followers()->get()->map(function($i) { - return $i->url(); - }); - }); - return response()->streamDownload(function () use($data) { - echo $data; - }, 'followers.json'); - } - - public function exportMuteBlockList() - { - $profile = Auth::user()->profile; - $exists = UserFilter::select('id') - ->whereUserId($profile->id) - ->exists(); - if(!$exists) { - return redirect()->back(); - } - $data = Cache::remember('account:export:profile:muteblocklist:'.Auth::user()->profile->id, now()->addMinutes(60), function() use($profile) { - return json_encode([ - 'muted' => $profile->mutedProfileUrls(), - 'blocked' => $profile->blockedProfileUrls() - ], JSON_PRETTY_PRINT); - }); - return response()->streamDownload(function () use($data) { - echo $data; - }, 'muted-and-blocked-accounts.json'); - } - public function dataImport() { return view('settings.import.home'); From 4122bb83cbab2c1d6db124bf32b8be7bdf43c10f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 24 Apr 2019 13:50:47 -0600 Subject: [PATCH 2/2] Add account export --- .../Controllers/Settings/ExportSettings.php | 19 +++++++++++++++++++ resources/views/settings/dataexport.blade.php | 6 +++++- routes/web.php | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Settings/ExportSettings.php b/app/Http/Controllers/Settings/ExportSettings.php index 071c800e..57349863 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 98c6f16f..df26ec61 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 167c688d..664d8cdf 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'); });