44
55namespace App \Http \Controllers ;
66
7+ use App \Services \UserAgentService ;
8+
79use Illuminate \Support \Facades \Gate ;
810use Illuminate \Http \RedirectResponse ;
911use Illuminate \Http \Request ;
1012
13+ use App \Enums \Link \Os ;
14+
1115use App \Jobs \ProcessLinkStat ;
1216
1317use App \Models \Link ;
@@ -20,7 +24,6 @@ public function __invoke($key, Request $request): RedirectResponse
2024 ->with ('workspace ' )
2125 ->firstOrFail ();
2226
23-
2427 $ reachEventLimit = Gate::inspect ('reached-event-limit ' , $ link ->workspace );
2528
2629 ProcessLinkStat::dispatchIf (
@@ -32,6 +35,24 @@ public function __invoke($key, Request $request): RedirectResponse
3235 $ request ->input ('qr ' ) ? true : false ,
3336 $ request ->header ('Referer ' )
3437 );
38+
39+ /**
40+ * If the link has an iOS or Android redirect URL, we need to check the user's OS
41+ * and redirect to the appropriate URL.
42+ */
43+ if ($ link ->ios || $ link ->android ) {
44+ $ service = new UserAgentService ();
45+ $ os = $ service ->getOS ($ request ->userAgent ());
46+
47+ if ($ os === Os::IOS ->value && $ link ->ios ) {
48+ return redirect ($ link ->ios , 302 );
49+ }
50+
51+ if ($ os === Os::ANDROID ->value && $ link ->android ) {
52+ return redirect ($ link ->android , 302 );
53+ }
54+ }
55+
3556 return redirect ($ link ->url , 302 );
3657 }
3758}
0 commit comments