Compare commits

...

2 Commits

Author SHA1 Message Date
Notoric 29740fec36 fixed profile table 2025-03-02 20:10:42 +00:00
Notoric da2422e44a minor changes 2025-03-02 19:04:31 +00:00
6 changed files with 57 additions and 25 deletions

View File

@ -14,6 +14,12 @@ class ShortlinkController extends Controller
return response()->json(['error' => 'Unauthorized'], 401);
}
if (strlen($request->url) > 5000) {
return back()->withErrors([
'error' => 'The URL provided is too long'
]);
}
try {
$request->validate([
'url' => 'required|url'
@ -41,7 +47,7 @@ class ShortlinkController extends Controller
return redirect("/l/{$shortlink->shortid}");
} catch (\Exception $e) {
return back()->withErrors([
'error' => $e->getMessage()
'error' => 'An error occurred while creating the shortlink'
]);
}
}

View File

@ -40,9 +40,9 @@ class Shortlink extends Model
$this->save();
}
function generateNewId(int $length = 6): string {
function generateNewId(int $length = 5): string {
$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 + 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 n + 1
for ($i = 0; $i < $length * 2; $i++) {
$id = '';
for ($i = 0; $i < $length; $i++) {

View File

@ -14,7 +14,7 @@ return new class extends Migration
Schema::create('shortlinks', function (Blueprint $table) {
$table->id();
$table->string('shortid')->unique();
$table->string('destination');
$table->string('destination', 5000);
$table->foreignId('user_id')->references('id')->on('users');
$table->integer('max_clicks')->default(0);
$table->boolean('deleted')->default(false);

View File

@ -383,7 +383,7 @@ button {
justify-content: space-between;
}
#graphs h2, #stats h2 {
#graphs h2, #stats h2, #table-container h2 {
margin-bottom: 20px;
}
@ -395,6 +395,7 @@ button {
table {
font-size: 1.5em;
border-collapse: collapse;
margin-bottom: 40px;
}
table td, table th {
@ -406,6 +407,14 @@ table td, table th {
table td {
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 {
@ -420,8 +429,9 @@ table th:last-child, table td:last-child {
border-right: none;
}
table {
margin-bottom: 40px;
.destination {
height: 1.2em;
overflow: hidden;
}
footer {

View File

@ -36,6 +36,8 @@
<input id="expiry-date" name="expiry-date" type="date"
@if ($shortlink->expires_at != null)
value="{{ Carbon\Carbon::parse($shortlink->expires_at)->format('Y-m-d') }}"
@else
value="{{ Carbon\Carbon::now()->format('Y-m-d') }}"
@endif
>
<label id="time-label" for="expiry-hour">Time</label>

View File

@ -5,22 +5,36 @@
@endsection
@section('content')
<h1>Profile</h1>
<p>Username: <em>{{ Auth::user()->name }}</em></p>
<p>Email: <em>{{ Auth::user()->email }}</em></p>
<p>Created at: <em>{{ Auth::user()->created_at }}</em></p>
<table>
<tr>
<th>Link</th>
<th>Destination</th>
<th>Created at</th>
</tr>
@foreach ($shortlinks as $shortlink)
<tr>
<td><a href="{{ url()->to("l/" . $shortlink->shortid) }}">{{ $shortlink['shortid'] }}</a></td>
<td>{{ $shortlink['destination'] }}</td>
<td>{{ Carbon\Carbon::parse($shortlink->created_at)->format('M jS Y') }}</td>
</tr>
@endforeach
</table>
<div id="title-container" class="container">
<h1>Profile</h1>
</div>
<div id="profile-container" class="container">
<p>Username: <em>{{ Auth::user()->name }}</em></p>
<p>Email: <em>{{ Auth::user()->email }}</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>
<tbody>
<tr>
<th>Link</th>
<th>Destination</th>
<th>Created at</th>
</tr>
@foreach ($shortlinks as $shortlink)
<tr>
<td><a href="{{ url()->to("l/" . $shortlink->shortid) }}">{{ $shortlink['shortid'] }}</a></td>
<td class="table-truncate"><div class="destination">{{ $shortlink['destination'] }}</div></td>
<td>{{ Carbon\Carbon::parse($shortlink->created_at)->format('M jS Y') }}</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<td colspan="3"><a href="/home">Shorten a new link</a></td>
</tr>
</tfoot>
</table>
</div>
@endsection