Skip to content

Commit e7ffcdd

Browse files
committed
Paste App
slack webhook test_command_is_run_by_scheduler_at_midnight
1 parent 2d7ec78 commit e7ffcdd

23 files changed

Lines changed: 1469 additions & 118 deletions

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ LOG_CHANNEL=stack
1818
LOG_STACK=single
1919
LOG_DEPRECATIONS_CHANNEL=null
2020
LOG_LEVEL=debug
21+
LOG_SLACK_WEBHOOK_URL=
2122

2223
DB_CONNECTION=sqlite
2324
# DB_HOST=127.0.0.1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ yarn-error.log
1818
/.fleet
1919
/.idea
2020
/.vscode
21+
Envoy.blade.php

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
4+
deploy:
5+
#git push
6+
# ./vendor/bin/envoy run deploy
7+
.\vendor\bin\envoy run deploy

README.md

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,3 @@
1-
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
1+
## Paste
22

3-
<p align="center">
4-
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
5-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
6-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
7-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
8-
</p>
9-
10-
## About Laravel
11-
12-
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
13-
14-
- [Simple, fast routing engine](https://laravel.com/docs/routing).
15-
- [Powerful dependency injection container](https://laravel.com/docs/container).
16-
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
17-
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
18-
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
19-
- [Robust background job processing](https://laravel.com/docs/queues).
20-
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
21-
22-
Laravel is accessible, powerful, and provides tools required for large, robust applications.
23-
24-
## Learning Laravel
25-
26-
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
27-
28-
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
29-
30-
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
31-
32-
## Laravel Sponsors
33-
34-
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
35-
36-
### Premium Partners
37-
38-
- **[Vehikl](https://vehikl.com/)**
39-
- **[Tighten Co.](https://tighten.co)**
40-
- **[WebReinvent](https://webreinvent.com/)**
41-
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
42-
- **[64 Robots](https://64robots.com)**
43-
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
44-
- **[Cyber-Duck](https://cyber-duck.co.uk)**
45-
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
46-
- **[Jump24](https://jump24.co.uk)**
47-
- **[Redberry](https://redberry.international/laravel/)**
48-
- **[Active Logic](https://activelogic.com)**
49-
- **[byte5](https://byte5.de)**
50-
- **[OP.GG](https://op.gg)**
51-
52-
## Contributing
53-
54-
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
55-
56-
## Code of Conduct
57-
58-
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
59-
60-
## Security Vulnerabilities
61-
62-
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
63-
64-
## License
65-
66-
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
3+
A simple pastebin-like made with Laravel. Only private paste, no public listing.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\Paste;
6+
use Illuminate\Console\Command;
7+
8+
class DeleteExpiredPastes extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'delete-expired-pastes';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Command description';
23+
24+
/**
25+
* Execute the console command.
26+
*/
27+
public function handle()
28+
{
29+
$expiredPastes = Paste::where('expired_at', '<=', now())->get();
30+
31+
foreach ($expiredPastes as $paste) {
32+
$paste->delete();
33+
}
34+
35+
$this->info('Expired pastes deleted successfully.');
36+
}
37+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use App\Models\Paste; // Import the Paste model
7+
use Illuminate\Support\Str; // Import the Str class
8+
9+
class PasteController extends Controller
10+
{
11+
public function create()
12+
{
13+
return view('pastes.create');
14+
}
15+
16+
public function store(Request $request)
17+
{
18+
$validatedData = $request->validate([
19+
'content' => 'required',
20+
'expiration' => 'in:1day,1week,1month,1year,never',
21+
]);
22+
23+
$truncatedContent = Str::limit($validatedData['content'], 65000, '');
24+
25+
//unique slug
26+
$slug = Str::random(8);
27+
while (Paste::where('slug', $slug)->exists()) {
28+
$slug = Str::random(8);
29+
}
30+
31+
$expiration = $validatedData['expiration'];
32+
$expiredAt = match ($expiration) {
33+
'1day' => now()->addDay(),
34+
'1week' => now()->addWeek(),
35+
'1month' => now()->addMonth(),
36+
'1year' => now()->addYear(),
37+
'never' => null,
38+
};
39+
40+
$paste = new Paste();
41+
$paste->content = $truncatedContent;
42+
$paste->slug = $slug;
43+
$paste->expired_at = $expiredAt;
44+
$paste->save();
45+
46+
return redirect()->route('pastes.show', $paste->slug);
47+
}
48+
49+
public function show($slug)
50+
{
51+
$paste = Paste::where('slug', $slug)->firstOrFail();
52+
if ($paste->expired_at && $paste->expired_at->isPast()) {
53+
abort(404, 'Paste has expired');
54+
}
55+
return response($paste->content)
56+
->header('Content-Type', 'text/plain');
57+
}
58+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Logging;
4+
5+
use Monolog\Handler\DeduplicationHandler;
6+
use Monolog\Handler\SlackWebhookHandler;
7+
use Monolog\Logger;
8+
9+
class SlackDeduplicatedLogger
10+
{
11+
/**
12+
* Create a custom Monolog instance.
13+
*
14+
* @return \Monolog\Logger
15+
*/
16+
public function __invoke(array $config)
17+
{
18+
$logger = new Logger('slack_deduplicated');
19+
20+
$slackHandler = new SlackWebhookHandler(
21+
$config['url'],
22+
$config['channel'] ?? null,
23+
$config['username'] ?? 'Laravel',
24+
$config['attachment'] ?? true,
25+
$config['emoji'] ?? ':boom:',
26+
$config['short'] ?? false,
27+
$config['context'] ?? true,
28+
Logger::DEBUG,
29+
$config['bubble'] ?? true,
30+
$config['exclude_fields'] ?? []
31+
);
32+
33+
$logger->pushHandler(new DeduplicationHandler(
34+
$slackHandler,
35+
storage_path('logs/duplicates.log'),
36+
Logger::DEBUG,
37+
$config['time'] ?? 3600,
38+
true
39+
));
40+
41+
return $logger;
42+
}
43+
}

app/Models/Paste.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Paste extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = ['content', 'slug', 'expired_at'];
13+
14+
//cast
15+
protected $casts = [
16+
'expired_at' => 'datetime',
17+
];
18+
19+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"require-dev": {
1313
"fakerphp/faker": "^1.23",
14+
"laravel/envoy": "^2.9",
1415
"laravel/pint": "^1.13",
1516
"laravel/sail": "^1.26",
1617
"mockery/mockery": "^1.6",

0 commit comments

Comments
 (0)