diff --git a/app/Http/Controllers/Settings/ExportSettings.php b/app/Http/Controllers/Settings/ExportSettings.php new file mode 100644 index 000000000..57349863a --- /dev/null +++ b/app/Http/Controllers/Settings/ExportSettings.php @@ -0,0 +1,84 @@ +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() { + 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 264ab3939..9365d6205 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'); 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 @@