Make the logo fetching optional

This commit is contained in:
Bubka 2022-07-26 22:35:04 +02:00
parent 8e397fb5ca
commit 38d3744d39
2 changed files with 13 additions and 6 deletions

View File

@ -168,7 +168,7 @@ public function reorder(TwoFAccountReorderRequest $request)
public function preview(TwoFAccountUriRequest $request)
{
$twofaccount = new TwoFAccount;
$twofaccount->fillWithURI($request->uri, $request->custom_otp === TwoFAccount::STEAM_TOTP);
$twofaccount->fillWithURI($request->uri, $request->custom_otp === TwoFAccount::STEAM_TOTP, true);
return new TwoFAccountStoreResource($twofaccount);
}
@ -202,7 +202,7 @@ public function otp(Request $request, $id = null)
else {
$validatedData = $request->validate((new TwoFAccountUriRequest)->rules());
$twofaccount = new TwoFAccount;
$twofaccount->fillWithURI($validatedData['uri'], Arr::get($validatedData, 'custom_otp') === TwoFAccount::STEAM_TOTP);
$twofaccount->fillWithURI($validatedData['uri'], Arr::get($validatedData, 'custom_otp') === TwoFAccount::STEAM_TOTP, true);
}
}
@ -210,7 +210,7 @@ public function otp(Request $request, $id = null)
else {
$validatedData = $request->validate((new TwoFAccountStoreRequest)->rules());
$twofaccount = new TwoFAccount();
$twofaccount->fillWithOtpParameters($validatedData);
$twofaccount->fillWithOtpParameters($validatedData, true);
}
return response()->json($twofaccount->getOTP(), 200);

View File

@ -373,7 +373,7 @@ public function getOTP()
*
* @return $this
*/
public function fillWithOtpParameters(array $parameters)
public function fillWithOtpParameters(array $parameters, bool $skipIconFetching = false)
{
$this->otp_type = Arr::get($parameters, 'otp_type');
$this->account = Arr::get($parameters, 'account');
@ -391,6 +391,13 @@ public function fillWithOtpParameters(array $parameters)
$this->enforceAsSteam();
}
if (!$this->icon && $skipIconFetching) {
$this->icon = $this->getDefaultIcon();
}
if (!$this->icon && SettingService::get('getOfficialIcons') && !$skipIconFetching) {
$this->icon = $this->getDefaultIcon();
}
Log::info(sprintf('TwoFAccount filled with OTP parameters'));
return $this;
@ -402,7 +409,7 @@ public function fillWithOtpParameters(array $parameters)
*
* @return $this
*/
public function fillWithURI(string $uri, bool $isSteamTotp = false)
public function fillWithURI(string $uri, bool $isSteamTotp = false, bool $skipIconFetching = false)
{
// First we instanciate the OTP generator
try {
@ -440,7 +447,7 @@ public function fillWithURI(string $uri, bool $isSteamTotp = false)
if ($this->generator->hasParameter('image')) {
$this->icon = $this->storeImageAsIcon($this->generator->getParameter('image'));
}
if (!$this->icon) {
if (!$this->icon && SettingService::get('getOfficialIcons') && !$skipIconFetching) {
$this->icon = $this->getDefaultIcon();
}