Skip to content

Commit

Permalink
delete snatched check user and torrent
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Dec 17, 2024
1 parent ca21b0b commit edadbf0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
11 changes: 10 additions & 1 deletion app/Filament/Resources/Torrent/TorrentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Repositories\TorrentRepository;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Pages\Actions\Action;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
Expand Down Expand Up @@ -113,7 +114,8 @@ public static function table(Table $table): Table
->defaultSort('id', 'desc')
->filters(self::getFilters())
->actions(self::getActions())
->bulkActions(self::getBulkActions());
->bulkActions(self::getBulkActions())
;

}

Expand Down Expand Up @@ -339,6 +341,13 @@ private static function getActions(): array
$actions[] = Tables\Actions\DeleteAction::make('delete')->using(function ($record) {
deletetorrent($record->id);
});
// $actions[] = Tables\Actions\Action::make('view')
// ->action(function (Torrent $record) {
// return [
// 'modelContent' => new HtmlString("ssss")
// ];
// })
// ;
}
return $actions;
}
Expand Down
10 changes: 7 additions & 3 deletions app/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\LoginLog;
use App\Models\Message;
use App\Models\Setting;
use App\Models\Snatch;
use App\Models\User;
use App\Models\UserBanLog;
use App\Models\UserMeta;
Expand Down Expand Up @@ -636,9 +637,10 @@ public function destroy(Collection|int $id, $reasonKey = 'user.destroy_by_admin'
} else {
$uidArr = $id->pluck('id')->toArray();
}
$uidStr = implode(',', $uidArr);
$users = User::query()->with('language')->whereIn('id', $uidArr)->get();
if (empty($uidArr)) {
return;
if ($users->isEmpty()) {
return true;
}
$tables = [
'users' => 'id',
Expand All @@ -655,7 +657,7 @@ public function destroy(Collection|int $id, $reasonKey = 'user.destroy_by_admin'
'oauth_auth_codes' => 'user_id',
];
foreach ($tables as $table => $key) {
\Nexus\Database\NexusDB::table($table)->whereIn($key, $uidArr)->delete();
NexusDB::statement(sprintf("delete from `%s` where `%s` in (%s)", $table, $key, $uidStr));
}
do_log("[DESTROY_USER]: " . json_encode($uidArr), 'error');
$userBanLogs = [];
Expand All @@ -667,6 +669,8 @@ public function destroy(Collection|int $id, $reasonKey = 'user.destroy_by_admin'
];
}
UserBanLog::query()->insert($userBanLogs);
//delete by user, make sure torrent is deleted
NexusDB::statement(sprintf('DELETE FROM snatched WHERE userid IN (%s) and not exists (select 1 from torrents where id = snatched.torrentid)', $uidStr));
if (is_int($id)) {
do_action("user_delete", $id);
fire_event("user_destroyed", $users->first());
Expand Down
3 changes: 2 additions & 1 deletion include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3126,7 +3126,8 @@ function deletetorrent($id, $notify = false) {
$idStr = implode(', ', $idArr ?: [0]);
$torrent_dir = get_setting('main.torrent_dir');
\Nexus\Database\NexusDB::statement("DELETE FROM torrents WHERE id in ($idStr)");
\Nexus\Database\NexusDB::statement("DELETE FROM snatched WHERE torrentid in ($idStr)");
//delete by torrent, make sure user is deleted
\Nexus\Database\NexusDB::statement("DELETE FROM snatched WHERE torrentid in ($idStr) and not exists (select 1 from users where id = snatched.userid)");
foreach(array("peers", "files", "comments") as $x) {
\Nexus\Database\NexusDB::statement("DELETE FROM $x WHERE torrent in ($idStr)");
}
Expand Down
4 changes: 2 additions & 2 deletions public/announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,8 @@
if ($snatchInfo['downloaded'] >= $requiredDownloaded) {
$nowStr = date('Y-m-d H:i:s');
$sql = sprintf(
"insert into hit_and_runs (uid, torrent_id, snatched_id, created_at, updated_at) values (%d, %d, %d, '%s', '%s') on duplicate key update created_at = '%s', updated_at = '%s'",
$userid, $torrentid, $snatchInfo['id'], $nowStr, $nowStr, $nowStr, $nowStr
"insert into hit_and_runs (uid, torrent_id, snatched_id, created_at, updated_at) values (%d, %d, %d, '%s', '%s') on duplicate key update updated_at = '%s'",
$userid, $torrentid, $snatchInfo['id'], $nowStr, $nowStr, $nowStr
);
$affectedRows = sql_query($sql);
do_log("$hrLog, total downloaded: {$snatchInfo['downloaded']} >= required: $requiredDownloaded, [INSERT_H&R], sql: $sql, affectedRows: $affectedRows");
Expand Down

0 comments on commit edadbf0

Please sign in to comment.