support pg problem fix

This commit is contained in:
xiaomlove
2026-04-16 04:03:52 +07:00
parent 00fdc2d08f
commit e3376c3f1b
5 changed files with 27 additions and 8 deletions
+9
View File
@@ -200,6 +200,15 @@ class Torrent extends NexusModel
throw new \RuntimeException("Not supported database"); throw new \RuntimeException("Not supported database");
} }
/**
* 重写获取 info_hash 的方法,确保从数据库读出时是正确的格式
*/
public function getInfoHashAttribute($value): false|string
{
// PostgreSQL 返回 bytea 时可能是十六进制流或资源
return is_resource($value) ? stream_get_contents($value) : $value;
}
public function getPickInfoAttribute() public function getPickInfoAttribute()
{ {
$info = self::$pickTypes[$this->picktype] ?? null; $info = self::$pickTypes[$this->picktype] ?? null;
+3 -3
View File
@@ -1277,9 +1277,9 @@ function parse_imdb_id($url)
$url = str_pad($url, 7, '0', STR_PAD_LEFT); $url = str_pad($url, 7, '0', STR_PAD_LEFT);
} }
if ($url != "" && preg_match("/[0-9]+/i", $url, $matches)) { if ($url != "" && preg_match("/[0-9]+/i", $url, $matches)) {
return $matches[0]; return intval($matches[0]);
} }
return ''; return null;
} }
function build_imdb_url($imdb_id) function build_imdb_url($imdb_id)
@@ -6066,7 +6066,7 @@ function insert_torrent_tags($torrentId, $tagIdArr, $sync = false)
if (empty($tagIdArr)) { if (empty($tagIdArr)) {
return; return;
} }
$insertTagsSql = 'insert into torrent_tags (`torrent_id`, `tag_id`, `created_at`, `updated_at`) values '; $insertTagsSql = 'insert into torrent_tags (torrent_id, tag_id, created_at, updated_at) values ';
$values = []; $values = [];
foreach ($tagIdArr as $tagId) { foreach ($tagIdArr as $tagId) {
if (in_array($tagId, $specialTags) && !$canSetSpecialTag) { if (in_array($tagId, $specialTags) && !$canSetSpecialTag) {
+3
View File
@@ -89,6 +89,9 @@ function sqlesc($value) {
} }
function hash_pad($hash) { function hash_pad($hash) {
if (is_resource($hash)) {
$hash = stream_get_contents($hash);
}
return str_pad($hash, 20); return str_pad($hash, 20);
} }
+1 -1
View File
@@ -618,7 +618,7 @@ echo "</script>";
$no_give = ""; $no_give = "";
$add_value =""; $add_value ="";
$tempresult = sql_query ("SELECT count( DISTINCT `userid` ) as count FROM magic WHERE torrentid=".sqlesc($id)); $tempresult = sql_query ("SELECT count( DISTINCT userid ) as count FROM magic WHERE torrentid=".sqlesc($id));
$count_user = mysql_fetch_array($tempresult); $count_user = mysql_fetch_array($tempresult);
$count_user_number = $count_user['count']; $count_user_number = $count_user['count'];
+11 -4
View File
@@ -279,6 +279,13 @@ if (!is_writable($torrentSavePath)) {
*/ */
$descriptionArr = format_description($descr); $descriptionArr = format_description($descr);
$cover = get_image_from_description($descriptionArr, true, false); $cover = get_image_from_description($descriptionArr, true, false);
if (\Nexus\Database\NexusDB::isPgsql()) {
$infoHashInsert = \Nexus\Database\NexusDB::raw("decode('" . bin2hex($infohash) . "', 'hex')");
} elseif (\Nexus\Database\NexusDB::isMysql()) {
$infoHashInsert = $infohash;
} else {
throw new \RuntimeException("Not supported database");
}
$insert = [ $insert = [
'filename' => $fname, 'filename' => $fname,
'owner' => $CURUSER['id'], 'owner' => $CURUSER['id'],
@@ -305,7 +312,7 @@ $insert = [
'added' => $dateTimeStringNow, 'added' => $dateTimeStringNow,
'last_action' => $dateTimeStringNow, 'last_action' => $dateTimeStringNow,
// 'nfo' => $nfo, // 'nfo' => $nfo,
'info_hash' => $infohash, 'info_hash' => $infoHashInsert,
// 'pt_gen' => $_POST['pt_gen'] ?? '', // 'pt_gen' => $_POST['pt_gen'] ?? '',
// 'technical_info' => $_POST['technical_info'] ?? '', // 'technical_info' => $_POST['technical_info'] ?? '',
'cover' => $cover, 'cover' => $cover,
@@ -354,10 +361,10 @@ if (user_can('torrent-approval-allow-automatic')) {
$insert['approval_status'] = \App\Models\Torrent::APPROVAL_STATUS_ALLOW; $insert['approval_status'] = \App\Models\Torrent::APPROVAL_STATUS_ALLOW;
} }
if (user_can('torrent-set-price') && $paidTorrentEnabled) { if (user_can('torrent-set-price') && $paidTorrentEnabled) {
$insert['price'] = $_POST['price'] ?? 0; $insert['price'] = intval($_POST['price'] ?? 0);
} }
do_log("[INSERT_TORRENT]: " . nexus_json_encode($insert)); do_log("[INSERT_TORRENT]: " . nexus_json_encode($insert));
$id = \Nexus\Database\NexusDB::insert('torrents', $insert); $id = \App\Models\Torrent::query()->insertGetId($insert);
//$ret = sql_query("INSERT INTO torrents (filename, owner, visible, anonymous, name, size, numfiles, type, url, small_descr, descr, ori_descr, category, source, medium, codec, audiocodec, standard, processing, team, save_as, sp_state, added, last_action, nfo, info_hash, pt_gen, technical_info) VALUES (".sqlesc($fname).", ".sqlesc($CURUSER["id"]).", 'yes', ".sqlesc($anonymous).", ".sqlesc($torrent).", ".sqlesc($totallen).", ".count($filelist).", ".sqlesc($type).", ".sqlesc($url).", ".sqlesc($small_descr).", ".sqlesc($descr).", ".sqlesc($descr).", ".sqlesc($catid).", ".sqlesc($sourceid).", ".sqlesc($mediumid).", ".sqlesc($codecid).", ".sqlesc($audiocodecid).", ".sqlesc($standardid).", ".sqlesc($processingid).", ".sqlesc($teamid).", ".sqlesc($dname).", ".sqlesc($sp_state) . //$ret = sql_query("INSERT INTO torrents (filename, owner, visible, anonymous, name, size, numfiles, type, url, small_descr, descr, ori_descr, category, source, medium, codec, audiocodec, standard, processing, team, save_as, sp_state, added, last_action, nfo, info_hash, pt_gen, technical_info) VALUES (".sqlesc($fname).", ".sqlesc($CURUSER["id"]).", 'yes', ".sqlesc($anonymous).", ".sqlesc($torrent).", ".sqlesc($totallen).", ".count($filelist).", ".sqlesc($type).", ".sqlesc($url).", ".sqlesc($small_descr).", ".sqlesc($descr).", ".sqlesc($descr).", ".sqlesc($catid).", ".sqlesc($sourceid).", ".sqlesc($mediumid).", ".sqlesc($codecid).", ".sqlesc($audiocodecid).", ".sqlesc($standardid).", ".sqlesc($processingid).", ".sqlesc($teamid).", ".sqlesc($dname).", ".sqlesc($sp_state) .
//", " . sqlesc(date("Y-m-d H:i:s")) . ", " . sqlesc(date("Y-m-d H:i:s")) . ", ".sqlesc($nfo).", " . sqlesc($infohash). ", " . sqlesc($_POST['pt_gen']) . ", " . sqlesc($_POST['technical_info'] ?? '') . ")"); //", " . sqlesc(date("Y-m-d H:i:s")) . ", " . sqlesc(date("Y-m-d H:i:s")) . ", ".sqlesc($nfo).", " . sqlesc($infohash). ", " . sqlesc($_POST['pt_gen']) . ", " . sqlesc($_POST['technical_info'] ?? '') . ")");
@@ -426,7 +433,7 @@ fire_event(\App\Enums\ModelEventEnum::TORRENT_CREATED, \App\Models\Torrent::quer
//===notify people who voted on offer thanks CoLdFuSiOn :) //===notify people who voted on offer thanks CoLdFuSiOn :)
if ($is_offer) if ($is_offer)
{ {
$res = sql_query("SELECT `userid` FROM `offervotes` WHERE `userid` != " . $CURUSER["id"] . " AND `offerid` = ". sqlesc($offerid)." AND `vote` = 'yeah'") or sqlerr(__FILE__, __LINE__); $res = sql_query("SELECT userid FROM offervotes WHERE userid != " . $CURUSER["id"] . " AND offerid = ". sqlesc($offerid)." AND vote = 'yeah'") or sqlerr(__FILE__, __LINE__);
while($row = mysql_fetch_assoc($res)) while($row = mysql_fetch_assoc($res))
{ {