Skip to content

Commit

Permalink
Merge 1d9a18b into bb85b34
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Jan 9, 2023
2 parents bb85b34 + 1d9a18b commit 97b743a
Show file tree
Hide file tree
Showing 43 changed files with 929 additions and 969 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

UH_ANONYMIZE_IP_ADDR=true
UH_PUBLIC_SITE=true
UH_REGISTRATION=true
UH_HASH_LENGTH=6
Expand Down
1 change: 0 additions & 1 deletion .env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ APP_KEY=base64:SsuVzwH9xQnlEqSgTdTbBKyJ0rYrgt5Wr71vv02jDV8=
APP_DEBUG=true
APP_URL=http://localhost

UH_ANONYMIZE_IP_ADDR=true
UH_PUBLIC_SITE=true
UH_REGISTRATION=true
UH_HASH_LENGTH=6
Expand Down
65 changes: 0 additions & 65 deletions app/Actions/UrlRedirectAction.php

This file was deleted.

16 changes: 0 additions & 16 deletions app/Helpers/Global/NumHelper.php

This file was deleted.

15 changes: 0 additions & 15 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,9 @@
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;
use Spatie\Url\Url as SpatieUrl;
use Symfony\Component\HttpFoundation\IpUtils;

class Helper
{
/**
* Anonymize an IPv4 or IPv6 address.
*
* @param string|null $address
*/
public static function anonymizeIp($address): string
{
if (config('urlhub.anonymize_ip_addr') === false) {
return $address;
}

return IPUtils::anonymize($address);
}

/**
* Display the link according to what You need.
*
Expand Down
63 changes: 0 additions & 63 deletions app/Helpers/NumHelper.php

This file was deleted.

43 changes: 0 additions & 43 deletions app/Http/Controllers/API/UrlController.php

This file was deleted.

24 changes: 11 additions & 13 deletions app/Http/Controllers/Dashboard/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
use App\Http\Controllers\Controller;
use App\Models\Url;
use App\Models\User;
use App\Models\Visit;
use App\Services\DuplicateUrl;
use App\Services\KeyGeneratorService;
use App\Services\UpdateShortenedUrl;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
public function __construct(
public Url $url,
public User $user,
public Visit $visit
) {
}

Expand All @@ -27,39 +28,36 @@ public function view()
return view('backend.dashboard', [
'url' => $this->url,
'user' => $this->user,
'visit' => $this->visit,
'keyGeneratorService' => app(KeyGeneratorService::class),
]);
}

/**
* Show shortened url details page
*
* @param mixed $key
* @return \Illuminate\Contracts\View\View
*/
public function edit($key)
public function edit(string $urlKey)
{
$url = Url::whereKeyword($key)->firstOrFail();
$url = Url::whereKeyword($urlKey)->first();

$this->authorize('updateUrl', $url);

return view('backend.edit', compact('url'));
return view('backend.edit', ['url' => $url]);
}

/**
* Update the destination URL
*
* @param Request $request \Illuminate\Http\Request
* @param mixed $url
* @param Url $url \App\Models\Url
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function update(Request $request, $url)
public function update(Request $request, Url $url)
{
$url->destination = $request->long_url;
$url->title = $request->title;
$url->save();
app(UpdateShortenedUrl::class)->execute($request, $url);

return to_route('dashboard')
->withFlashSuccess(__('Link changed successfully !'));
Expand Down Expand Up @@ -89,7 +87,7 @@ public function delete($url)
*/
public function duplicate($key)
{
$this->url->duplicate($key, auth()->id());
app(DuplicateUrl::class)->execute($key, auth()->id());

return redirect()->back()
->withFlashSuccess(__('The link has successfully duplicated.'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function view(User $user)
{
$this->authorize('view', $user);

return view('backend.user.changepassword', compact('user'));
return view('backend.user.changepassword', ['user' => $user]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Dashboard/User/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function edit(User $user)
{
$this->authorize('view', $user);

return view('backend.user.profile', compact('user'));
return view('backend.user.profile', ['user' => $user]);
}

/**
Expand Down
22 changes: 12 additions & 10 deletions app/Http/Controllers/UrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

namespace App\Http\Controllers;

use App\Actions\QrCodeAction;
use App\Http\Requests\StoreUrl;
use App\Models\Url;
use App\Services\CreateShortenedUrl;
use App\Services\DuplicateUrl;
use App\Services\KeyGeneratorService;
use App\Services\QrCodeService;

class UrlController extends Controller
{
/**
* UrlController constructor.
*/
public function __construct(
public Url $url
public Url $url,
) {
$this->middleware('urlhublinkchecker')->only('create');
}
Expand All @@ -25,7 +28,7 @@ public function __construct(
*/
public function create(StoreUrl $request)
{
$url = $this->url->shortenUrl($request, auth()->id());
$url = app(CreateShortenedUrl::class)->execute($request);

return to_route('su_detail', $url->keyword);
}
Expand All @@ -35,18 +38,17 @@ public function create(StoreUrl $request)
*
* @codeCoverageIgnore
*
* @param string $key
* @return \Illuminate\Contracts\View\View
*/
public function showDetail($key)
public function showDetail(string $urlKey)
{
$url = Url::with('visit')->whereKeyword($key)->firstOrFail();
$url = Url::with('visit')->whereKeyword($urlKey)->firstOrFail();
$data = ['url' => $url, 'visit' => new \App\Models\Visit];

if (config('urlhub.qrcode')) {
$qrCode = (new QrCodeAction)->process($url->short_url);
$qrCode = app(QrCodeService::class)->execute($url->short_url);

$data = array_merge($data, compact(['qrCode']));
$data = array_merge($data, ['qrCode' => $qrCode]);
}

return view('frontend.short', $data);
Expand Down Expand Up @@ -78,8 +80,8 @@ public function delete($url)
*/
public function duplicate(string $key)
{
$randomKey = $this->url->randomString();
$this->url->duplicate($key, auth()->id(), $randomKey);
$randomKey = app(KeyGeneratorService::class)->generateRandomString();
app(DuplicateUrl::class)->execute($key, auth()->id(), $randomKey);

return to_route('su_detail', $randomKey)
->withFlashSuccess(__('The link has successfully duplicated.'));
Expand Down

0 comments on commit 97b743a

Please sign in to comment.