mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-04-02 20:06:16 +02:00
Use Storage::disk() where possible
This commit is contained in:
parent
bf32b37176
commit
e540e2bb26
@ -22,6 +22,7 @@ public function upload(Request $request)
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$path = $request->file('icon')->store('public/icons');
|
$path = $request->file('icon')->store('public/icons');
|
||||||
|
$path = $request->file('icon')->store('', 'icons');
|
||||||
$response['filename'] = pathinfo($path)['basename'];
|
$response['filename'] = pathinfo($path)['basename'];
|
||||||
|
|
||||||
return response()->json($response, 201);
|
return response()->json($response, 201);
|
||||||
@ -36,7 +37,7 @@ public function upload(Request $request)
|
|||||||
*/
|
*/
|
||||||
public function delete($icon)
|
public function delete($icon)
|
||||||
{
|
{
|
||||||
Storage::delete('public/icons/' . $icon);
|
Storage::disk('icons')->delete($icon);
|
||||||
|
|
||||||
return response()->json(null, 204);
|
return response()->json(null, 204);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -26,7 +26,7 @@ public function __construct()
|
|||||||
*/
|
*/
|
||||||
public function handle(TwoFAccountDeleted $event)
|
public function handle(TwoFAccountDeleted $event)
|
||||||
{
|
{
|
||||||
Storage::delete('public/icons/' . $event->twofaccount->icon);
|
Storage::disk('icons')->delete($event->twofaccount->icon);
|
||||||
Log::info(sprintf('Icon cleaned for deleted TwoFAccount #%d', $event->twofaccount->id));
|
Log::info(sprintf('Icon cleaned for deleted TwoFAccount #%d', $event->twofaccount->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -28,6 +28,7 @@
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use ParagonIE\ConstantTime\Base32;
|
use ParagonIE\ConstantTime\Base32;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class TwoFAccount extends Model implements Sortable
|
class TwoFAccount extends Model implements Sortable
|
||||||
{
|
{
|
||||||
@ -535,25 +536,34 @@ private function initGenerator()
|
|||||||
private function storeImageAsIcon(string $url)
|
private function storeImageAsIcon(string $url)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$remoteImageURL = $url;
|
$path_parts = pathinfo($url);
|
||||||
$path_parts = pathinfo($remoteImageURL);
|
$newFilename = Str::random(40).'.'.$path_parts['extension'];
|
||||||
$newFilename = Str::random(40) . '.' . $path_parts['extension'];
|
|
||||||
$imageFile = self::IMAGELINK_STORAGE_PATH . $newFilename;
|
$imageFile = self::IMAGELINK_STORAGE_PATH . $newFilename;
|
||||||
$iconFile = self::ICON_STORAGE_PATH . $newFilename;
|
|
||||||
|
|
||||||
Storage::disk('local')->put($imageFile, file_get_contents($remoteImageURL));
|
try {
|
||||||
|
$response = Http::retry(3, 100)->get($url);
|
||||||
|
|
||||||
|
if ($response->successful()) {
|
||||||
|
Storage::disk('imagesLink')->put($newFilename, $response->body());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\Exception $exception) {
|
||||||
|
Log::error(sprintf('Cannot fetch imageLink at "%s"', $url));
|
||||||
|
}
|
||||||
|
|
||||||
if ( in_array(Storage::mimeType($imageFile), ['image/png', 'image/jpeg', 'image/webp', 'image/bmp'])
|
if ( in_array(Storage::mimeType($imageFile), ['image/png', 'image/jpeg', 'image/webp', 'image/bmp'])
|
||||||
&& getimagesize(storage_path() . '/app/' . $imageFile) )
|
&& getimagesize(storage_path() . '/app/' . $imageFile) )
|
||||||
{
|
{
|
||||||
// Should be a valid image
|
// Should be a valid image, we move it to the icons disk
|
||||||
Storage::move($imageFile, $iconFile);
|
if (Storage::disk('icons')->put($newFilename, Storage::disk('imagesLink')->get($newFilename))) {
|
||||||
|
Storage::disk('imagesLink')->delete($newFilename);
|
||||||
|
}
|
||||||
|
|
||||||
Log::info(sprintf('Icon file %s stored', $newFilename));
|
Log::info(sprintf('Icon file %s stored', $newFilename));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
Storage::delete($imageFile);
|
Storage::disk('imagesLink')->delete($newFilename);
|
||||||
throw new \Exception('Unsupported mimeType or missing image on storage');
|
throw new \Exception('Unsupported mimeType or missing image on storage');
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
@ -561,7 +571,7 @@ private function storeImageAsIcon(string $url)
|
|||||||
return $newFilename;
|
return $newFilename;
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
catch (\Assert\AssertionFailedException|\Assert\InvalidArgumentException|\Exception|\Throwable $ex) {
|
catch (\Exception|\Throwable $ex) {
|
||||||
Log::error(sprintf('Icon storage failed: %s', $ex->getMessage()));
|
Log::error(sprintf('Icon storage failed: %s', $ex->getMessage()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user