mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 22:41:27 +00:00
Update BaseApiController, add avatar update method
This commit is contained in:
parent
85e4e9cf65
commit
522729b050
1 changed files with 41 additions and 1 deletions
|
@ -3,15 +3,22 @@
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
use App\{Like, Profile, Status};
|
use App\{
|
||||||
|
Avatar,
|
||||||
|
Like,
|
||||||
|
Profile,
|
||||||
|
Status
|
||||||
|
};
|
||||||
use League\Fractal;
|
use League\Fractal;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Controllers\AvatarController;
|
||||||
use App\Util\Webfinger\Webfinger;
|
use App\Util\Webfinger\Webfinger;
|
||||||
use App\Transformer\Api\{
|
use App\Transformer\Api\{
|
||||||
AccountTransformer,
|
AccountTransformer,
|
||||||
StatusTransformer
|
StatusTransformer
|
||||||
};
|
};
|
||||||
|
use App\Jobs\AvatarPipeline\AvatarOptimize;
|
||||||
use League\Fractal\Serializer\ArraySerializer;
|
use League\Fractal\Serializer\ArraySerializer;
|
||||||
|
|
||||||
class BaseApiController extends Controller
|
class BaseApiController extends Controller
|
||||||
|
@ -68,4 +75,37 @@ class BaseApiController extends Controller
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
$res = $this->fractal->createData($resource)->toArray();
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function avatarUpdate(Request $request)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'upload' => 'required|mimes:jpeg,png,gif|max:2000',
|
||||||
|
]);
|
||||||
|
try {
|
||||||
|
$user = Auth::user();
|
||||||
|
$file = $request->file('upload');
|
||||||
|
$path = (new AvatarController())->getPath($user, $file);
|
||||||
|
$dir = $path['root'];
|
||||||
|
$name = $path['name'];
|
||||||
|
$public = $path['storage'];
|
||||||
|
$currentAvatar = storage_path('app/'.$user->profile->avatar->media_path);
|
||||||
|
$loc = $request->file('upload')->storeAs($public, $name);
|
||||||
|
|
||||||
|
$avatar = Avatar::whereProfileId($user->profile->id)->firstOrFail();
|
||||||
|
$opath = $avatar->media_path;
|
||||||
|
$avatar->media_path = "$public/$name";
|
||||||
|
$avatar->thumb_path = null;
|
||||||
|
$avatar->change_count = ++$avatar->change_count;
|
||||||
|
$avatar->last_processed_at = null;
|
||||||
|
$avatar->save();
|
||||||
|
|
||||||
|
AvatarOptimize::dispatch($user->profile, $currentAvatar);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'code' => 200,
|
||||||
|
'msg' => 'Avatar successfully updated'
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue