mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Add DELETE /api/v1.1/accounts/avatar api endpoint
This commit is contained in:
parent
102baa517e
commit
5ea12601ce
2 changed files with 39 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use Cache;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use League\Fractal;
|
use League\Fractal;
|
||||||
|
@ -10,6 +11,7 @@ use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
use App\Status;
|
use App\Status;
|
||||||
use App\Report;
|
use App\Report;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
|
use App\Services\AccountService;
|
||||||
|
|
||||||
class ApiV1Dot1Controller extends Controller
|
class ApiV1Dot1Controller extends Controller
|
||||||
{
|
{
|
||||||
|
@ -128,4 +130,40 @@ class ApiV1Dot1Controller extends Controller
|
||||||
];
|
];
|
||||||
return $this->json($res);
|
return $this->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE /api/v1.1/accounts/avatar
|
||||||
|
*
|
||||||
|
* @return \App\Transformer\Api\AccountTransformer
|
||||||
|
*/
|
||||||
|
public function deleteAvatar(Request $request)
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
abort_if(!$user, 403);
|
||||||
|
abort_if($user->status != null, 403);
|
||||||
|
|
||||||
|
$avatar = $user->profile->avatar;
|
||||||
|
|
||||||
|
if( $avatar->media_path == 'public/avatars/default.png' ||
|
||||||
|
$avatar->media_path == 'public/avatars/default.jpg'
|
||||||
|
) {
|
||||||
|
return AccountService::get($user->profile_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_file(storage_path('app/' . $avatar->media_path))) {
|
||||||
|
@unlink(storage_path('app/' . $avatar->media_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
$avatar->media_path = 'public/avatars/default.jpg';
|
||||||
|
$avatar->change_count = $avatar->change_count + 1;
|
||||||
|
$avatar->save();
|
||||||
|
|
||||||
|
Cache::forget('avatar:' . $user->profile_id);
|
||||||
|
Cache::forget("avatar:{$user->profile_id}");
|
||||||
|
Cache::forget('user:account:id:'.$user->id);
|
||||||
|
AccountService::del($user->profile_id);
|
||||||
|
|
||||||
|
return AccountService::get($user->profile_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
|
||||||
|
|
||||||
Route::group(['prefix' => 'v1.1'], function() use($middleware) {
|
Route::group(['prefix' => 'v1.1'], function() use($middleware) {
|
||||||
Route::post('report', 'Api\ApiV1Dot1Controller@report')->middleware($middleware);
|
Route::post('report', 'Api\ApiV1Dot1Controller@report')->middleware($middleware);
|
||||||
|
Route::delete('accounts/avatar', 'Api\ApiV1Dot1Controller@deleteAvatar')->middleware($middleware);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::group(['prefix' => 'live'], function() use($middleware) {
|
Route::group(['prefix' => 'live'], function() use($middleware) {
|
||||||
|
|
Loading…
Reference in a new issue