Merge pull request #1193 from pixelfed/frontend-ui-refactor

Add status exports
This commit is contained in:
daniel 2019-04-24 21:09:07 -06:00 committed by GitHub
commit 14affe9267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 2 deletions

View File

@ -5,17 +5,26 @@ namespace App\Http\Controllers\Settings;
use App\AccountLog; use App\AccountLog;
use App\Following; use App\Following;
use App\Report; use App\Report;
use App\Status;
use App\UserFilter; use App\UserFilter;
use Auth, Cookie, DB, Cache, Purify; use Auth, Cookie, DB, Cache, Purify;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Transformer\ActivityPub\ProfileTransformer; use App\Transformer\ActivityPub\{
ProfileTransformer,
StatusTransformer
};
use App\Transformer\Api\StatusTransformer as StatusApiTransformer;
use League\Fractal; use League\Fractal;
use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Pagination\IlluminatePaginatorAdapter;
trait ExportSettings trait ExportSettings
{ {
public function __construct()
{
$this->middleware('auth');
}
public function dataExport() public function dataExport()
{ {
@ -89,4 +98,47 @@ trait ExportSettings
]); ]);
} }
public function exportStatuses(Request $request)
{
$this->validate($request, [
'type' => 'required|string|in:ap,api'
]);
$limit = 300;
$profile = Auth::user()->profile;
$type = $request->input('type') == 'ap' ? 'ap' : 'api';
$count = Status::select('id')->whereProfileId($profile->id)->count();
if($count > $limit) {
// fire background job
return redirect('/settings/data-export')->with(['status' => 'You have more than '.$limit.' statuses, we do not support full account export yet.']);
}
$filename = 'outbox.json';
if($type == 'ap') {
$data = Cache::remember('account:export:profile:statuses:ap:'.Auth::user()->profile->id, now()->addDays(7), function() {
$profile = Auth::user()->profile->statuses;
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Collection($profile, new StatusTransformer());
return $fractal->createData($resource)->toArray();
});
} else {
$filename = 'api-statuses.json';
$data = Cache::remember('account:export:profile:statuses:api:'.Auth::user()->profile->id, now()->addDays(7), function() {
$profile = Auth::user()->profile->statuses;
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Collection($profile, new StatusApiTransformer());
return $fractal->createData($resource)->toArray();
});
}
return response()->streamDownload(function () use ($data, $filename) {
echo json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
}, $filename, [
'Content-Type' => 'application/json'
]);
}
} }

View File

@ -35,7 +35,16 @@
<span class="font-weight-bold">Statuses</span> <span class="font-weight-bold">Statuses</span>
</div> </div>
<div> <div>
<span class="small text-muted">Coming Soon</span> <form action="/settings/data-export/statuses" method="post" class="d-inline">
@csrf
<input type="hidden" name="type" value="ap">
<button type="submit" class="font-weight-bold btn btn-outline-primary btn-sm">Download</button>
</form>
{{-- <form action="/settings/data-export/statuses" method="post" class="d-inline">
@csrf
<input type="hidden" name="type" value="api">
<button type="submit" class="font-weight-bold btn btn-outline-primary btn-sm">api.json</button>
</form> --}}
</div> </div>
</li> </li>
<li class="list-group-item d-flex justify-content-between align-items-center"> <li class="list-group-item d-flex justify-content-between align-items-center">

View File

@ -229,6 +229,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::post('data-export/followers', 'SettingsController@exportFollowers')->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/mute-block-list', 'SettingsController@exportMuteBlockList')->middleware('dangerzone');
Route::post('data-export/account', 'SettingsController@exportAccount')->middleware('dangerzone'); Route::post('data-export/account', 'SettingsController@exportAccount')->middleware('dangerzone');
Route::post('data-export/statuses', 'SettingsController@exportStatuses')->middleware('dangerzone');
Route::get('developers', 'SettingsController@developers')->name('settings.developers')->middleware('dangerzone'); Route::get('developers', 'SettingsController@developers')->name('settings.developers')->middleware('dangerzone');
}); });