forked from mirror/pixelfed
Move data export to its own controller
This commit is contained in:
parent
f53d129101
commit
de8d472527
2 changed files with 68 additions and 50 deletions
65
app/Http/Controllers/Settings/ExportSettings.php
Normal file
65
app/Http/Controllers/Settings/ExportSettings.php
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Settings;
|
||||||
|
|
||||||
|
use App\AccountLog;
|
||||||
|
use App\Following;
|
||||||
|
use App\Report;
|
||||||
|
use App\UserFilter;
|
||||||
|
use Auth, Cookie, DB, Cache, Purify;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
trait ExportSettings
|
||||||
|
{
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ use Auth, Cookie, DB, Cache, Purify;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Settings\{
|
use App\Http\Controllers\Settings\{
|
||||||
|
ExportSettings,
|
||||||
HomeSettings,
|
HomeSettings,
|
||||||
PrivacySettings,
|
PrivacySettings,
|
||||||
SecuritySettings
|
SecuritySettings
|
||||||
|
@ -18,7 +19,8 @@ use App\Jobs\DeletePipeline\DeleteAccountPipeline;
|
||||||
|
|
||||||
class SettingsController extends Controller
|
class SettingsController extends Controller
|
||||||
{
|
{
|
||||||
use HomeSettings,
|
use ExportSettings,
|
||||||
|
HomeSettings,
|
||||||
PrivacySettings,
|
PrivacySettings,
|
||||||
SecuritySettings;
|
SecuritySettings;
|
||||||
|
|
||||||
|
@ -67,55 +69,6 @@ class SettingsController extends Controller
|
||||||
return view('settings.applications');
|
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()
|
public function dataImport()
|
||||||
{
|
{
|
||||||
return view('settings.import.home');
|
return view('settings.import.home');
|
||||||
|
|
Loading…
Reference in a new issue