API: torrents upload/list

This commit is contained in:
xiaomlove
2025-04-17 01:39:40 +07:00
parent 0d3a46231d
commit 2b029eba10
72 changed files with 2332 additions and 507 deletions
+2
View File
@@ -45,6 +45,7 @@ class BonusLogs extends NexusModel
const BUSINESS_TYPE_TORRENT_BE_DOWNLOADED = 1001;
const BUSINESS_TYPE_RECEIVE_REWARD = 1002;
const BUSINESS_TYPE_RECEIVE_GIFT = 1003;
const BUSINESS_TYPE_UPLOAD_TORRENT = 1004;
public static array $businessTypes = [
self::BUSINESS_TYPE_CANCEL_HIT_AND_RUN => ['text' => 'Cancel H&R'],
@@ -73,6 +74,7 @@ class BonusLogs extends NexusModel
self::BUSINESS_TYPE_TORRENT_BE_DOWNLOADED => ['text' => 'Torrent be downloaded'],
self::BUSINESS_TYPE_RECEIVE_REWARD => ['text' => 'Receive reward'],
self::BUSINESS_TYPE_RECEIVE_GIFT => ['text' => 'Receive gift'],
self::BUSINESS_TYPE_UPLOAD_TORRENT => ['text' => 'Upload torrent'],
];
public function getBusinessTypeTextAttribute()
-11
View File
@@ -1,11 +0,0 @@
<?php
namespace App\Models;
class PersonalAccessTokenPlain extends NexusModel
{
protected $fillable = ['access_token_id', 'plain_text_token'];
public $timestamps = true;
}
+11 -4
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use App\Auth\Permission;
use App\Http\Middleware\Locale;
use App\Repositories\TagRepository;
use Illuminate\Database\Eloquent\Casts\Attribute;
@@ -106,7 +107,9 @@ class SearchBox extends NexusModel
$lang = get_langfolder_cookie();
foreach ($this->extra[self::EXTRA_TAXONOMY_LABELS] ?? [] as $item) {
if ($item['torrent_field'] == $torrentField) {
return $item['display_text'][$lang] ?? 'Unknown';
if (!empty($item['display_text'][$lang])) {
return $item['display_text'][$lang];
}
}
}
return nexus_trans("searchbox.sub_category_{$torrentField}_label") ?: ucfirst($torrentField);
@@ -214,7 +217,7 @@ class SearchBox extends NexusModel
public static function isSpecialEnabled(): bool
{
return Setting::get('main.spsct') == 'yes';
return Setting::getIsSpecialSectionEnabled();
}
public static function getBrowseMode()
@@ -303,7 +306,12 @@ class SearchBox extends NexusModel
public function loadTags(): void
{
$this->setRelation("tags", TagRepository::listAll($this->getKey()));
$allTags = TagRepository::listAll($this->getKey());
if (!Permission::canSetTorrentSpecialTag()) {
$specialTagIdList = Tag::listSpecial();
$allTags = $allTags->filter(fn ($item) => !in_array($item->id, $specialTagIdList));
}
$this->setRelation("tags", $allTags);
}
public static function getDefaultSearchMode()
@@ -349,5 +357,4 @@ class SearchBox extends NexusModel
return $results;
}
}
+109 -1
View File
@@ -100,7 +100,7 @@ class Setting extends NexusModel
return $value;
}
public static function getDefaultLang()
public static function getDefaultLang(): string
{
return self::get("main.defaultlang");
}
@@ -110,4 +110,112 @@ class Setting extends NexusModel
return self::get("security.use_challenge_response_authentication") == "yes";
}
public static function getUploadTorrentMaxSize(): int
{
return intval(self::get("main.max_torrent_size"));
}
public static function getUploadTorrentMaxPrice(): int
{
return intval(self::get("torrent.max_price"));
}
public static function getIsPaidTorrentEnabled(): bool
{
return self::get("torrent.paid_torrent_enabled") == "yes";
}
public static function getUploadDenyApprovalDenyCount(): int
{
return intval(self::get("main.upload_deny_approval_deny_count"));
}
public static function getOfferSkipApprovedCount(): int
{
return intval(self::get("main.offer_skip_approved_count"));
}
public static function getLargeTorrentSize(): int
{
return intval(self::get("torrent.largesize"));
}
public static function getLargeTorrentSpState(): int
{
return intval(self::get("torrent.largepro"));
}
public static function getUploadTorrentHalfDownProbability(): int
{
return intval(self::get("torrent.randomhalfleech"));
}
public static function getUploadTorrentFreeProbability(): int
{
return intval(self::get("torrent.randomfree"));
}
public static function getUploadTorrentTwoTimesUpProbability(): int
{
return intval(self::get("torrent.randomtwoup"));
}
public static function getUploadTorrentFreeTwoTimesUpProbability(): int
{
return intval(self::get("torrent.randomtwoupfree"));
}
public static function getUploadTorrentHalfDownTwoTimesUpProbability(): int
{
return intval(self::get("torrent.randomtwouphalfdown"));
}
public static function getUploadTorrentOneThirdDownProbability(): int
{
return intval(self::get("torrent.randomthirtypercentdown"));
}
public static function getUploadTorrentRewardBonus(): int
{
return intval(self::get("bonus.uploadtorrent"));
}
public static function getIsUploadOpenAtWeekend(): bool
{
return self::get("main.sptime") == "yes";
}
public static function getIsSpecialSectionEnabled(): bool
{
return self::get('main.spsct') == 'yes';
}
public static function getIsAllowUserReceiveEmailNotification(): bool
{
return self::get('smtp.emailnotify') == 'yes';
}
public static function getBaseUrl(): string
{
$result = self::get('basic.BASEURL', $_SERVER['HTTP_HOST'] ?? '');
return rtrim($result, '/');
}
public static function getSiteName(): string
{
return self::get("basic.SITENAME");
}
public static function getTorrentSaveDir(): string
{
return self::get("main.torrent_dir");
}
public static function getSmtpType(): string
{
return self::get("smtp.smtptype");
}
}
+12
View File
@@ -0,0 +1,12 @@
<?php
namespace App\Models;
class SiteLog extends NexusModel
{
protected $table = 'sitelog';
protected $fillable = ['added', 'txt', 'security_level', 'uid'];
}
+20 -12
View File
@@ -13,8 +13,9 @@ class Torrent extends NexusModel
'category', 'source', 'medium', 'codec', 'standard', 'processing', 'team', 'audiocodec',
'size', 'added', 'type', 'numfiles', 'owner', 'nfo', 'sp_state', 'promotion_time_type',
'promotion_until', 'anonymous', 'url', 'pos_state', 'cache_stamp', 'picktype', 'picktime',
'last_reseed', 'leechers', 'seeders', 'cover', 'last_action',
'last_reseed', 'leechers', 'seeders', 'cover', 'last_action', 'info_hash', 'pieces_hash',
'times_completed', 'approval_status', 'banned', 'visible', 'pos_state_until', 'price',
'hr',
];
const VISIBLE_YES = 'yes';
@@ -27,6 +28,7 @@ class Torrent extends NexusModel
'added' => 'datetime',
'promotion_until' => 'datetime',
'pos_state_until' => 'datetime',
'last_action' => 'datetime',
];
public static $commentFields = [
@@ -334,15 +336,6 @@ class Torrent extends NexusModel
return implode('', $html);
}
public static function getBasicInfo(): array
{
$result = [];
foreach (self::$basicRelations as $relation) {
$result[$relation] = nexus_trans("torrent.show.$relation");
}
return $result;
}
public static function listPosStates($onlyKeyValue = false, $valueField = 'text'): array
{
$result = self::$posStates;
@@ -382,6 +375,11 @@ class Torrent extends NexusModel
return true;
}
public function getSubCategoryLabel($field): string
{
return $this->basic_category->search_box->getTaxonomyLabel($field);
}
public function bookmarks(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Bookmark::class, 'torrentid');
@@ -452,7 +450,7 @@ class Torrent extends NexusModel
return $this->belongsTo(Source::class, 'source');
}
public function basic_media()
public function basic_medium()
{
return $this->belongsTo(Media::class, 'medium');
}
@@ -477,11 +475,21 @@ class Torrent extends NexusModel
return $this->belongsTo(Team::class, 'team');
}
public function basic_audio_codec()
public function basic_audiocodec()
{
return $this->belongsTo(AudioCodec::class, 'audiocodec');
}
public function claim_users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(User::class, 'claims', 'torrent_id');
}
public function claims()
{
return $this->hasMany(Claim::class, 'torrent_id');
}
public function scopeVisible($query, $visible = self::VISIBLE_YES)
{
$query->where('visible', $visible);
+10 -1
View File
@@ -3,16 +3,25 @@
namespace App\Models;
use Nexus\Database\NexusDB;
use Nexus\Torrent\TechnicalInformation;
class TorrentExtra extends NexusModel
{
public $timestamps = true;
protected $fillable = ['torrent_id', 'descr', 'ori_descr', 'media_info'];
protected $fillable = ['torrent_id', 'descr', 'ori_descr', 'media_info', 'nfo'];
public function torrent()
{
return $this->belongsTo(Torrent::class, 'torrent_id');
}
protected $appends = ['media_info_summary'];
public function getMediaInfoSummaryAttribute(): array
{
$technicalInfo = new TechnicalInformation($this->media_info ?? '');
return $technicalInfo->getSummaryInfo();
}
}
+5
View File
@@ -540,6 +540,11 @@ class User extends Authenticatable implements FilamentUser, HasName
return $this->hasMany(UserModifyLog::class, "user_id");
}
public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Claim::class, 'uid');
}
public function getAvatarAttribute($value)
{
if ($value) {