mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Merge pull request #1189 from pixelfed/frontend-ui-refactor
Add Account Export
This commit is contained in:
commit
f51403cb34
4 changed files with 93 additions and 51 deletions
84
app/Http/Controllers/Settings/ExportSettings.php
Normal file
84
app/Http/Controllers/Settings/ExportSettings.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?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;
|
||||
use App\Transformer\ActivityPub\ProfileTransformer;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
|
||||
trait ExportSettings
|
||||
{
|
||||
|
||||
public function dataExport()
|
||||
{
|
||||
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() {
|
||||
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 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');
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<h3 class="font-weight-bold">Data Export</h3>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="alert alert-info font-weight-bold">We generate data exports once per hour, and they may not contain the latest data if you've requested them recently.</div>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
|
@ -53,7 +54,10 @@
|
|||
<span class="font-weight-bold">Account</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="small text-muted">Coming Soon</span>
|
||||
<form action="/settings/data-export/account" method="post">
|
||||
@csrf
|
||||
<button type="submit" class="font-weight-bold btn btn-outline-primary btn-sm">Download</button>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue