Browse Source

Make the logo fetching optional

Bubka 3 years ago
parent
commit
38d3744d39
2 changed files with 13 additions and 6 deletions
  1. 3 3
      app/Api/v1/Controllers/TwoFAccountController.php
  2. 10 3
      app/Models/TwoFAccount.php

+ 3 - 3
app/Api/v1/Controllers/TwoFAccountController.php

@@ -168,7 +168,7 @@ class TwoFAccountController extends Controller
     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 @@ class TwoFAccountController extends Controller
             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 @@ class TwoFAccountController extends Controller
         else {
             $validatedData = $request->validate((new TwoFAccountStoreRequest)->rules());
             $twofaccount = new TwoFAccount();
-            $twofaccount->fillWithOtpParameters($validatedData);
+            $twofaccount->fillWithOtpParameters($validatedData, true);
         }
 
         return response()->json($twofaccount->getOTP(), 200);

+ 10 - 3
app/Models/TwoFAccount.php

@@ -373,7 +373,7 @@ class TwoFAccount extends Model implements Sortable
      * 
      * @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 @@ class TwoFAccount extends Model implements Sortable
             $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 @@ class TwoFAccount extends Model implements Sortable
      * 
      * @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 @@ class TwoFAccount extends Model implements Sortable
         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();
         }