Skip to content

Commit 4db2875

Browse files
committed
add: store torrent deletion reason
To be later used on the unregistered info hash page, in the tracker's torrent deletion message for bittorrent clients and perhaps a work edit log.
1 parent 3449be7 commit 4db2875

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

app/Http/Controllers/TorrentController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public function destroy(Request $request, int $id): \Illuminate\Http\RedirectRes
284284
'message' => [
285285
'required',
286286
'min:1',
287+
'max:255',
287288
],
288289
]);
289290

@@ -327,6 +328,9 @@ public function destroy(Request $request, int $id): \Illuminate\Http\RedirectRes
327328

328329
Unit3dAnnounce::removeTorrent($torrent);
329330

331+
$torrent->update([
332+
'deletion_message' => $request->message,
333+
]);
330334
$torrent->delete();
331335

332336
return to_route('torrents.index')

app/Http/Livewire/SimilarTorrent.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use App\Traits\CastLivewireProperties;
3636
use App\Traits\LivewireSort;
3737
use Illuminate\Support\Facades\Notification;
38+
use Illuminate\Support\Facades\Validator;
3839
use Livewire\Attributes\Computed;
3940
use Livewire\Attributes\Url;
4041
use Livewire\Component;
@@ -472,6 +473,22 @@ final public function deleteRecords(): void
472473
return;
473474
}
474475

476+
$validator = Validator::make([
477+
'reason' => $this->reason,
478+
], [
479+
'reason' => [
480+
'required',
481+
'min:1',
482+
'max:255',
483+
],
484+
]);
485+
486+
if ($validator->fails()) {
487+
$this->dispatch('error', type: 'error', message: $validator->messages()->get('reason'));
488+
489+
return;
490+
}
491+
475492
$torrents = Torrent::whereKey($this->checked)->get();
476493
$users = [];
477494
$title = match (true) {
@@ -518,6 +535,9 @@ final public function deleteRecords(): void
518535

519536
Unit3dAnnounce::removeTorrent($torrent);
520537

538+
$torrent->update([
539+
'deletion_message' => $this->reason,
540+
]);
521541
$torrent->delete();
522542
}
523543

app/Models/Torrent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* @property \Illuminate\Support\Carbon|null $updated_at
7171
* @property \Illuminate\Support\Carbon|null $bumped_at
7272
* @property \Illuminate\Support\Carbon|null $deleted_at
73+
* @property string|null $deletion_reason
7374
* @property \Illuminate\Support\Carbon|null $fl_until
7475
* @property \Illuminate\Support\Carbon|null $du_until
7576
* @property int $type_id
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* NOTICE OF LICENSE.
4+
*
5+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
6+
* The details is bundled with this project in the file LICENSE.txt.
7+
*
8+
* @project UNIT3D Community Edition
9+
*
10+
* @author Roardom <roardom@protonmail.com>
11+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
12+
*/
13+
14+
use Illuminate\Database\Migrations\Migration;
15+
use Illuminate\Database\Schema\Blueprint;
16+
use Illuminate\Support\Facades\Schema;
17+
18+
return new class () extends Migration {
19+
/**
20+
* Run the migrations.
21+
*/
22+
public function up(): void
23+
{
24+
Schema::table('torrents', function (Blueprint $table): void {
25+
$table->string('deletion_reason')->nullable()->after('deleted_at');
26+
});
27+
}
28+
};

database/schema/mysql-schema.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,7 @@ CREATE TABLE `torrents` (
21302130
`updated_at` timestamp NULL DEFAULT NULL,
21312131
`bumped_at` datetime DEFAULT NULL,
21322132
`deleted_at` timestamp NULL DEFAULT NULL,
2133+
`deletion_reason` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
21332134
`fl_until` datetime DEFAULT NULL,
21342135
`du_until` datetime DEFAULT NULL,
21352136
`type_id` smallint unsigned DEFAULT NULL,
@@ -3005,3 +3006,4 @@ INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (354,'2025_06_18_00
30053006
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (355,'2025_06_18_040627_alter_requests_drop_claimed',1);
30063007
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (356,'2025_06_21_234021_alter_requests_drop_votes',1);
30073008
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (357,'2025_07_15_061844_add_block_order_to_user_settings',1);
3009+
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (358,'2025_08_04_070714_add_deletion_reason_to_torrents_table',1);

0 commit comments

Comments
 (0)