mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Add status exports
This commit is contained in:
parent
d92d9ddaf0
commit
2063bfc9fd
3 changed files with 64 additions and 2 deletions
|
@ -5,17 +5,26 @@ namespace App\Http\Controllers\Settings;
|
|||
use App\AccountLog;
|
||||
use App\Following;
|
||||
use App\Report;
|
||||
use App\Status;
|
||||
use App\UserFilter;
|
||||
use Auth, Cookie, DB, Cache, Purify;
|
||||
use Carbon\Carbon;
|
||||
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\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
|
||||
trait ExportSettings
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
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'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -35,7 +35,16 @@
|
|||
<span class="font-weight-bold">Statuses</span>
|
||||
</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>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
|
|
|
@ -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/mute-block-list', 'SettingsController@exportMuteBlockList')->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');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue