switch remote file_get_contents to curl

This commit is contained in:
ghost 2023-09-15 23:43:00 +03:00
parent 034a8c540a
commit d2cad4833e

View File

@ -52,10 +52,19 @@ try
continue;
}
// Manifest
if ($manifest = @json_decode(@file_get_contents($node->manifest)))
// Get node manifest
$curl = new Curl($node->manifest, API_USER_AGENT);
if (200 != $curl->getCode())
{
// Feed channel exists
continue;
}
if (!$manifest = $curl->getResponse())
{
continue;
}
if (empty($manifest->export))
{
continue;
@ -64,7 +73,20 @@ try
// Users
if (API_IMPORT_USERS_ENABLED)
{
if (empty($manifest->export->users))
if (Valid::url($manifest->export->users))
{
continue;
}
// Call feed
$curl = new Curl($manifest->export->users, API_USER_AGENT);
if (200 != $curl->getCode())
{
continue;
}
if (!$remoteUsers = $curl->getResponse())
{
continue;
}
@ -72,7 +94,7 @@ try
// Init alias registry for this host
$aliasUserId = [];
foreach (@json_decode(@file_get_contents($manifest->export->users)) as $remoteUser)
foreach ((object) $remoteUsers as $remoteUser)
{
// Validate required fields
if (!Valid::user($remoteUser))
@ -95,9 +117,6 @@ try
continue;
}
// Remember user ID for this host
$aliasUserId[$remoteUser->userId] = $localUser->userId;
// Update time added if newer
if ($localUser->timeAdded < $remoteUser->timeAdded)
{
@ -136,12 +155,28 @@ try
);
}
}
// Register userId alias
$aliasUserId[$remoteUser->userId] = $localUser->userId;
}
// Magnets
if (API_IMPORT_MAGNETS_ENABLED)
{
if (empty($manifest->export->magnets))
if (Valid::url($manifest->export->magnets))
{
continue;
}
// Call feed
$curl = new Curl($manifest->export->magnets, API_USER_AGENT);
if (200 != $curl->getCode())
{
continue;
}
if (!$remoteMagnets = $curl->getResponse())
{
continue;
}
@ -149,7 +184,7 @@ try
// Init alias registry for this host
$aliasMagnetId = [];
foreach (@json_decode(@file_get_contents($manifest->export->magnets)) as $remoteMagnet)
foreach ((object) $remoteMagnets as $remoteMagnet)
{
// Validate required fields by protocol
if (!Valid::magnet($remoteMagnet))
@ -187,9 +222,6 @@ try
);
}
// Add magnet alias for this host
$aliasMagnetId[$remoteMagnet->magnetId] = $localMagnet->magnetId;
// Update time added if newer
if ($localMagnet->timeAdded < $remoteMagnet->timeAdded)
{
@ -334,17 +366,33 @@ try
);
}
}
// Add magnet alias for this host
$aliasMagnetId[$remoteMagnet->magnetId] = $localMagnet->magnetId;
}
// Magnet comments
if (API_IMPORT_MAGNET_COMMENTS_ENABLED)
{
if (empty($manifest->export->magnetComments))
if (Valid::url($manifest->export->magnetComments))
{
continue;
}
foreach (@json_decode(@file_get_contents($manifest->export->magnetComments)) as $remoteMagnetComment)
// Call feed
$curl = new Curl($manifest->export->magnetComments, API_USER_AGENT);
if (200 != $curl->getCode())
{
continue;
}
if (!$remoteMagnetComments = $curl->getResponse())
{
continue;
}
foreach ((object) $remoteMagnetComments as $remoteMagnetComment)
{
// Validate
if (!Valid::magnetComment($remoteMagnetComment))
@ -396,12 +444,25 @@ try
// Magnet downloads
if (API_IMPORT_MAGNET_DOWNLOADS_ENABLED)
{
if (empty($manifest->export->magnetDownloads))
if (Valid::url($manifest->export->magnetDownloads))
{
continue;
}
foreach (@json_decode(@file_get_contents($manifest->export->magnetDownloads)) as $remoteMagnetDownload)
// Call feed
$curl = new Curl($manifest->export->magnetDownloads, API_USER_AGENT);
if (200 != $curl->getCode())
{
continue;
}
if (!$remoteMagnetDownloads = $curl->getResponse())
{
continue;
}
foreach ((object) $remoteMagnetDownloads as $remoteMagnetDownload)
{
// Validate
if (!Valid::magnetDownload($remoteMagnetDownload))
@ -432,12 +493,25 @@ try
// Magnet views
if (API_IMPORT_MAGNET_VIEWS_ENABLED)
{
if (empty($manifest->export->magnetViews))
if (Valid::url($manifest->export->magnetViews))
{
continue;
}
foreach (@json_decode(@file_get_contents($manifest->export->magnetViews)) as $remoteMagnetView)
// Call feed
$curl = new Curl($manifest->export->magnetViews, API_USER_AGENT);
if (200 != $curl->getCode())
{
continue;
}
if (!$remoteMagnetViews = $curl->getResponse())
{
continue;
}
foreach ((object) $remoteMagnetViews as $remoteMagnetView)
{
// Validate
if (!Valid::magnetView($remoteMagnetView))
@ -468,12 +542,25 @@ try
// Magnet stars
if (API_IMPORT_MAGNET_STARS_ENABLED)
{
if (empty($manifest->export->magnetStars))
if (Valid::url($manifest->export->magnetStars))
{
continue;
}
foreach (@json_decode(@file_get_contents($manifest->export->magnetStars)) as $remoteMagnetStar)
// Call feed
$curl = new Curl($manifest->export->magnetStars, API_USER_AGENT);
if (200 != $curl->getCode())
{
continue;
}
if (!$remoteMagnetStars = $curl->getResponse())
{
continue;
}
foreach ((object) $remoteMagnetStars as $remoteMagnetStar)
{
// Validate
if (!Valid::magnetStar($remoteMagnetStar))
@ -504,7 +591,6 @@ try
}
}
}
}
$db->commit();