ExportSettings.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Http\Controllers\Settings;
  3. use App\AccountLog;
  4. use App\Following;
  5. use App\Report;
  6. use App\UserFilter;
  7. use Auth, Cookie, DB, Cache, Purify;
  8. use Carbon\Carbon;
  9. use Illuminate\Http\Request;
  10. use App\Transformer\ActivityPub\ProfileTransformer;
  11. use League\Fractal;
  12. use League\Fractal\Serializer\ArraySerializer;
  13. use League\Fractal\Pagination\IlluminatePaginatorAdapter;
  14. trait ExportSettings
  15. {
  16. public function dataExport()
  17. {
  18. return view('settings.dataexport');
  19. }
  20. public function exportAccount()
  21. {
  22. $data = Cache::remember('account:export:profile:actor:'.Auth::user()->profile->id, now()->addMinutes(60), function() {
  23. $profile = Auth::user()->profile;
  24. $fractal = new Fractal\Manager();
  25. $fractal->setSerializer(new ArraySerializer());
  26. $resource = new Fractal\Resource\Item($profile, new ProfileTransformer());
  27. return $fractal->createData($resource)->toArray();
  28. });
  29. return response()->streamDownload(function () use ($data) {
  30. echo json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
  31. }, 'account.json', [
  32. 'Content-Type' => 'application/json'
  33. ]);
  34. }
  35. public function exportFollowing()
  36. {
  37. $data = Cache::remember('account:export:profile:following:'.Auth::user()->profile->id, now()->addMinutes(60), function() {
  38. return Auth::user()->profile->following()->get()->map(function($i) {
  39. return $i->url();
  40. });
  41. });
  42. return response()->streamDownload(function () use($data) {
  43. echo $data;
  44. }, 'following.json', [
  45. 'Content-Type' => 'application/json'
  46. ]);
  47. }
  48. public function exportFollowers()
  49. {
  50. $data = Cache::remember('account:export:profile:followers:'.Auth::user()->profile->id, now()->addMinutes(60), function() {
  51. return Auth::user()->profile->followers()->get()->map(function($i) {
  52. return $i->url();
  53. });
  54. });
  55. return response()->streamDownload(function () use($data) {
  56. echo $data;
  57. }, 'followers.json', [
  58. 'Content-Type' => 'application/json'
  59. ]);
  60. }
  61. public function exportMuteBlockList()
  62. {
  63. $profile = Auth::user()->profile;
  64. $exists = UserFilter::select('id')
  65. ->whereUserId($profile->id)
  66. ->exists();
  67. if(!$exists) {
  68. return redirect()->back();
  69. }
  70. $data = Cache::remember('account:export:profile:muteblocklist:'.Auth::user()->profile->id, now()->addMinutes(60), function() use($profile) {
  71. return json_encode([
  72. 'muted' => $profile->mutedProfileUrls(),
  73. 'blocked' => $profile->blockedProfileUrls()
  74. ], JSON_PRETTY_PRINT);
  75. });
  76. return response()->streamDownload(function () use($data) {
  77. echo $data;
  78. }, 'muted-and-blocked-accounts.json', [
  79. 'Content-Type' => 'application/json'
  80. ]);
  81. }
  82. }