mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
API: torrents upload/list
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.0');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-04-05');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-04-17');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
+24
-10
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\SearchBox;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@@ -722,10 +723,12 @@ function get_slr_color($ratio)
|
||||
|
||||
function write_log($text, $security = "normal")
|
||||
{
|
||||
$text = sqlesc($text);
|
||||
$added = sqlesc(date("Y-m-d H:i:s"));
|
||||
$security = sqlesc($security);
|
||||
sql_query("INSERT INTO sitelog (added, txt, security_level) VALUES($added, $text, $security)") or sqlerr(__FILE__, __LINE__);
|
||||
\App\Models\SiteLog::query()->insert([
|
||||
'added' => now(),
|
||||
'txt' => $text,
|
||||
'security_level' => $security,
|
||||
'uid' => get_user_id(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -2219,9 +2222,8 @@ function validlang($langid) {
|
||||
|
||||
function get_if_restricted_is_open()
|
||||
{
|
||||
global $sptime;
|
||||
// it's sunday
|
||||
if($sptime == 'yes' && (date("w",time()) == '0' || (date("w",time()) == 6) && (date("G",time()) >=12 && date("G",time()) <=23)))
|
||||
if(\App\Models\Setting::getIsUploadOpenAtWeekend() && (date("w",time()) == '0' || (date("w",time()) == 6) && (date("G",time()) >=12 && date("G",time()) <=23)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -2992,7 +2994,6 @@ function set_langfolder_cookie($folder, $expires = 0x7fffffff)
|
||||
|
||||
function get_protocol_prefix()
|
||||
{
|
||||
global $securelogin;
|
||||
if (isHttps()) {
|
||||
return "https://";
|
||||
}
|
||||
@@ -4277,7 +4278,18 @@ function permissiondenied($allowMinimumClass = null){
|
||||
}
|
||||
|
||||
function gettime($time, $withago = true, $twoline = false, $forceago = false, $oneunit = false, $isfuturetime = false){
|
||||
global $lang_functions, $CURUSER;
|
||||
if (!IN_NEXUS) {
|
||||
if (empty($time)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return \Carbon\Carbon::parse($time)->diffForHumans();
|
||||
} catch (\Exception $e) {
|
||||
do_log($e->getMessage() . $e->getTraceAsString(), 'error');
|
||||
return $time;
|
||||
}
|
||||
}
|
||||
global $lang_functions, $CURUSER;
|
||||
if (isset($CURUSER) && $CURUSER['timetype'] != 'timealive' && !$forceago){
|
||||
$newtime = $time;
|
||||
if ($twoline){
|
||||
@@ -5910,7 +5922,8 @@ function insert_torrent_tags($torrentId, $tagIdArr, $sync = false)
|
||||
$canSetSpecialTag = user_can('torrent-set-special-tag');
|
||||
$dateTimeStringNow = date('Y-m-d H:i:s');
|
||||
if ($sync) {
|
||||
sql_query("delete from torrent_tags where torrent_id = $torrentId");
|
||||
\App\Models\TorrentTag::query()->where("torrent_id", $torrentId)->delete();
|
||||
// sql_query("delete from torrent_tags where torrent_id = $torrentId");
|
||||
}
|
||||
if (empty($tagIdArr)) {
|
||||
return;
|
||||
@@ -5926,7 +5939,8 @@ function insert_torrent_tags($torrentId, $tagIdArr, $sync = false)
|
||||
}
|
||||
$insertTagsSql .= implode(', ', $values);
|
||||
do_log("[INSERT_TAGS], torrent: $torrentId with tags: " . nexus_json_encode($tagIdArr));
|
||||
sql_query($insertTagsSql);
|
||||
\Nexus\Database\NexusDB::statement($insertTagsSql);
|
||||
// sql_query($insertTagsSql);
|
||||
}
|
||||
|
||||
function get_smile($num)
|
||||
|
||||
+35
-20
@@ -242,6 +242,9 @@ function getLogFile($append = '')
|
||||
return $logFiles[$append];
|
||||
}
|
||||
$config = nexus_config('nexus');
|
||||
if (!empty($config['log_file']) && in_array($config['log_files'], ["/dev/stdout", "/dev/stderr"])) {
|
||||
return $logFiles[$append] = $config['log_files'];
|
||||
}
|
||||
$path = getenv('NEXUS_LOG_DIR', true);
|
||||
$fromEnv = true;
|
||||
if ($path === false) {
|
||||
@@ -500,12 +503,14 @@ function getSchemeAndHttpHost(bool $fromConfig = false)
|
||||
function getBaseUrl()
|
||||
{
|
||||
$url = getSchemeAndHttpHost();
|
||||
$requestUri = $_SERVER['REQUEST_URI'];
|
||||
$pos = strpos($requestUri, '?');
|
||||
if ($pos !== false) {
|
||||
$url .= substr($requestUri, 0, $pos);
|
||||
} else {
|
||||
$url .= $requestUri;
|
||||
if (!isRunningInConsole()) {
|
||||
$requestUri = $_SERVER['REQUEST_URI'];
|
||||
$pos = strpos($requestUri, '?');
|
||||
if ($pos !== false) {
|
||||
$url .= substr($requestUri, 0, $pos);
|
||||
} else {
|
||||
$url .= $requestUri;
|
||||
}
|
||||
}
|
||||
return trim($url, '/');
|
||||
}
|
||||
@@ -528,13 +533,10 @@ function api(...$args)
|
||||
$msg = $args[1];
|
||||
$data = $args[2];
|
||||
}
|
||||
if ($data instanceof \Illuminate\Http\Resources\Json\ResourceCollection || $data instanceof \Illuminate\Http\Resources\Json\JsonResource) {
|
||||
if ($data instanceof \Illuminate\Http\Resources\Json\JsonResource) {
|
||||
$data = $data->response()->getData(true);
|
||||
if (isset($data['data']) && count($data) == 1) {
|
||||
//单纯的集合,无分页等其数据
|
||||
$data = $data['data'];
|
||||
}
|
||||
}
|
||||
// dd($data);
|
||||
$time = (float)number_format(microtime(true) - nexus()->getStartTimestamp(), 3);
|
||||
$count = null;
|
||||
$resultKey = 'ret';
|
||||
@@ -630,7 +632,7 @@ function last_query($all = false)
|
||||
function format_datetime($datetime, $format = 'Y-m-d H:i')
|
||||
{
|
||||
if (empty($datetime)) {
|
||||
return '';
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$carbonTime = \Carbon\Carbon::parse($datetime);
|
||||
@@ -1320,15 +1322,28 @@ function get_snatch_info($torrentId, $userId)
|
||||
*/
|
||||
function fire_event(string $name, \Illuminate\Database\Eloquent\Model $model, \Illuminate\Database\Eloquent\Model $oldModel = null): void
|
||||
{
|
||||
$prefix = "fire_event:";
|
||||
$idKey = $prefix . \Illuminate\Support\Str::random();
|
||||
$idKeyOld = "";
|
||||
\Nexus\Database\NexusDB::cache_put($idKey, serialize($model), 3600*24*30);
|
||||
if ($oldModel) {
|
||||
$idKeyOld = $prefix . \Illuminate\Support\Str::random();
|
||||
\Nexus\Database\NexusDB::cache_put($idKeyOld, serialize($oldModel), 3600*24*30);
|
||||
if (!isset(\App\Enums\ModelEventEnum::$eventMaps[$name])) {
|
||||
throw new \InvalidArgumentException("Event $name is not a valid event enumeration");
|
||||
}
|
||||
if (IN_NEXUS) {
|
||||
$prefix = "fire_event:";
|
||||
$idKey = $prefix . \Illuminate\Support\Str::random();
|
||||
$idKeyOld = "";
|
||||
\Nexus\Database\NexusDB::cache_put($idKey, serialize($model), 3600*24*30);
|
||||
if ($oldModel) {
|
||||
$idKeyOld = $prefix . \Illuminate\Support\Str::random();
|
||||
\Nexus\Database\NexusDB::cache_put($idKeyOld, serialize($oldModel), 3600*24*30);
|
||||
}
|
||||
executeCommand("event:fire --name=$name --idKey=$idKey --idKeyOld=$idKeyOld", "string", true, false);
|
||||
} else {
|
||||
$eventClass = \App\Enums\ModelEventEnum::$eventMaps[$name]['event'];
|
||||
$params = [$model];
|
||||
if ($oldModel) {
|
||||
$params[] = $oldModel;
|
||||
}
|
||||
call_user_func_array([$eventClass, "dispatch"], $params);
|
||||
publish_model_event($name, $model->id);
|
||||
}
|
||||
executeCommand("event:fire --name=$name --idKey=$idKey --idKeyOld=$idKeyOld", "string", true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user