Compare commits
No commits in common. "29740fec367e33544b20e13a55bc4cc9996e9edc" and "df147d90143c57f9eaeee0b3e7c30dc6eaeb2057" have entirely different histories.
29740fec36
...
df147d9014
|
@ -14,12 +14,6 @@ class ShortlinkController extends Controller
|
||||||
return response()->json(['error' => 'Unauthorized'], 401);
|
return response()->json(['error' => 'Unauthorized'], 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($request->url) > 5000) {
|
|
||||||
return back()->withErrors([
|
|
||||||
'error' => 'The URL provided is too long'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'url' => 'required|url'
|
'url' => 'required|url'
|
||||||
|
@ -47,7 +41,7 @@ class ShortlinkController extends Controller
|
||||||
return redirect("/l/{$shortlink->shortid}");
|
return redirect("/l/{$shortlink->shortid}");
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return back()->withErrors([
|
return back()->withErrors([
|
||||||
'error' => 'An error occurred while creating the shortlink'
|
'error' => $e->getMessage()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ class Shortlink extends Model
|
||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateNewId(int $length = 5): string {
|
function generateNewId(int $length = 6): string {
|
||||||
$characters = 'qwrtypsdfghjklzxcvbnmQWRTYPSDFGHJKLZXCVBNM256789_';
|
$characters = 'qwrtypsdfghjklzxcvbnmQWRTYPSDFGHJKLZXCVBNM256789_';
|
||||||
// try n x 2 times to generate a new id, if it finds an id, return it, otherwise, try to look for an id of length n + 1
|
// try n x 2 times to generate a new id, if it finds an id, return it, otherwise, try to look for an id of length + 1
|
||||||
for ($i = 0; $i < $length * 2; $i++) {
|
for ($i = 0; $i < $length * 2; $i++) {
|
||||||
$id = '';
|
$id = '';
|
||||||
for ($i = 0; $i < $length; $i++) {
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ return new class extends Migration
|
||||||
Schema::create('shortlinks', function (Blueprint $table) {
|
Schema::create('shortlinks', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('shortid')->unique();
|
$table->string('shortid')->unique();
|
||||||
$table->string('destination', 5000);
|
$table->string('destination');
|
||||||
$table->foreignId('user_id')->references('id')->on('users');
|
$table->foreignId('user_id')->references('id')->on('users');
|
||||||
$table->integer('max_clicks')->default(0);
|
$table->integer('max_clicks')->default(0);
|
||||||
$table->boolean('deleted')->default(false);
|
$table->boolean('deleted')->default(false);
|
||||||
|
|
|
@ -383,7 +383,7 @@ button {
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
#graphs h2, #stats h2, #table-container h2 {
|
#graphs h2, #stats h2 {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +395,6 @@ button {
|
||||||
table {
|
table {
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
margin-bottom: 40px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table td, table th {
|
table td, table th {
|
||||||
|
@ -407,14 +406,6 @@ table td, table th {
|
||||||
|
|
||||||
table td {
|
table td {
|
||||||
border-top: 1px solid #888;
|
border-top: 1px solid #888;
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
table td.table-truncate {
|
|
||||||
white-space: normal;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
word-break: break-all;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table th, table td {
|
table th, table td {
|
||||||
|
@ -429,9 +420,8 @@ table th:last-child, table td:last-child {
|
||||||
border-right: none;
|
border-right: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.destination {
|
table {
|
||||||
height: 1.2em;
|
margin-bottom: 40px;
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
|
|
|
@ -36,8 +36,6 @@
|
||||||
<input id="expiry-date" name="expiry-date" type="date"
|
<input id="expiry-date" name="expiry-date" type="date"
|
||||||
@if ($shortlink->expires_at != null)
|
@if ($shortlink->expires_at != null)
|
||||||
value="{{ Carbon\Carbon::parse($shortlink->expires_at)->format('Y-m-d') }}"
|
value="{{ Carbon\Carbon::parse($shortlink->expires_at)->format('Y-m-d') }}"
|
||||||
@else
|
|
||||||
value="{{ Carbon\Carbon::now()->format('Y-m-d') }}"
|
|
||||||
@endif
|
@endif
|
||||||
>
|
>
|
||||||
<label id="time-label" for="expiry-hour">Time</label>
|
<label id="time-label" for="expiry-hour">Time</label>
|
||||||
|
|
|
@ -5,18 +5,11 @@
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div id="title-container" class="container">
|
|
||||||
<h1>Profile</h1>
|
<h1>Profile</h1>
|
||||||
</div>
|
|
||||||
<div id="profile-container" class="container">
|
|
||||||
<p>Username: <em>{{ Auth::user()->name }}</em></p>
|
<p>Username: <em>{{ Auth::user()->name }}</em></p>
|
||||||
<p>Email: <em>{{ Auth::user()->email }}</em></p>
|
<p>Email: <em>{{ Auth::user()->email }}</em></p>
|
||||||
<p>Created at: <em>{{ Auth::user()->created_at }}</em></p>
|
<p>Created at: <em>{{ Auth::user()->created_at }}</em></p>
|
||||||
</div>
|
|
||||||
<div id="table-container" class="container">
|
|
||||||
<h2>My Short URLs</h2>
|
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>Link</th>
|
<th>Link</th>
|
||||||
<th>Destination</th>
|
<th>Destination</th>
|
||||||
|
@ -25,16 +18,9 @@
|
||||||
@foreach ($shortlinks as $shortlink)
|
@foreach ($shortlinks as $shortlink)
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ url()->to("l/" . $shortlink->shortid) }}">{{ $shortlink['shortid'] }}</a></td>
|
<td><a href="{{ url()->to("l/" . $shortlink->shortid) }}">{{ $shortlink['shortid'] }}</a></td>
|
||||||
<td class="table-truncate"><div class="destination">{{ $shortlink['destination'] }}</div></td>
|
<td>{{ $shortlink['destination'] }}</td>
|
||||||
<td>{{ Carbon\Carbon::parse($shortlink->created_at)->format('M jS Y') }}</td>
|
<td>{{ Carbon\Carbon::parse($shortlink->created_at)->format('M jS Y') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
|
||||||
<tfoot>
|
|
||||||
<tr>
|
|
||||||
<td colspan="3"><a href="/home">Shorten a new link</a></td>
|
|
||||||
</tr>
|
|
||||||
</tfoot>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
|
||||||
@endsection
|
@endsection
|
Loading…
Reference in New Issue