add push events support

This commit is contained in:
ghost 2023-09-15 01:43:20 +03:00
parent 7c054557f3
commit 64693f7774
5 changed files with 151 additions and 24 deletions

View file

@ -237,13 +237,37 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
else
{
if ($magnetCommentId = $db->addMagnetComment($magnet->magnetId,
$user->userId,
null, // @TODO implement threads
trim($_POST['comment']),
$user->approved || in_array($user->address, MODERATOR_IP_LIST) ? true : MAGNET_COMMENT_DEFAULT_APPROVED,
MAGNET_COMMENT_DEFAULT_PUBLIC,
time()))
$user->userId,
null, // @TODO implement threads
trim($_POST['comment']),
$user->approved || in_array($user->address, MODERATOR_IP_LIST) ? true : MAGNET_COMMENT_DEFAULT_APPROVED,
MAGNET_COMMENT_DEFAULT_PUBLIC,
time()))
{
// Push event to other nodes
if (API_EXPORT_ENABLED &&
API_EXPORT_PUSH_ENABLED &&
API_EXPORT_USERS_ENABLED &&
API_EXPORT_MAGNETS_ENABLED &&
API_EXPORT_MAGNET_COMMENTS_ENABLED)
{
if (!$memoryApiExportPush = $memory->get('api.export.push'))
{
$memoryApiExportPush = [];
}
$memoryApiExportPush[] = (object)
[
'time' => time(),
'userId' => $user->userId,
'magnetId' => $magnet->magnetId,
'magnetCommentId' => $magnetCommentId
];
$memory->set('api.export.push', $memoryApiExportPush, 3600);
}
// Redirect to referrer page
header(
sprintf('Location: %s#comment-%s', $callback, $magnetCommentId)
@ -328,18 +352,40 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
// Request valid
else
{
// Save value
$db->addMagnetStar(
$magnet->magnetId,
$userId,
!$db->findLastMagnetStarValue($magnet->magnetId, $userId),
time()
);
// Save star
if ($magnetStarId = $db->addMagnetStar( $magnet->magnetId,
$user->userId,
!$db->findLastMagnetStarValue($magnet->magnetId, $user->userId),
time()))
{
// Push event to other nodes
if (API_EXPORT_ENABLED &&
API_EXPORT_PUSH_ENABLED &&
API_EXPORT_USERS_ENABLED &&
API_EXPORT_MAGNETS_ENABLED &&
API_EXPORT_MAGNET_STARS_ENABLED)
{
if (!$memoryApiExportPush = $memory->get('api.export.push'))
{
$memoryApiExportPush = [];
}
// Redirect to edit page
header(
sprintf('Location: %s', $callback)
);
$memoryApiExportPush[] = (object)
[
'time' => time(),
'userId' => $user->userId,
'magnetId' => $magnet->magnetId,
'magnetStarId' => $magnetStarId
];
$memory->set('api.export.push', $memoryApiExportPush, 3600);
}
// Redirect to edit page
header(
sprintf('Location: %s', $callback)
);
}
}
break;

View file

@ -62,8 +62,31 @@ else if (is_null($user->public))
// Request valid
else
{
// Update download stats
$db->addMagnetDownload($magnet->magnetId, $userId, time());
// Register magnet download
$magnetDownloadId = $db->addMagnetDownload($magnet->magnetId, $user->userId, time());
// Push event to other nodes
if (API_EXPORT_ENABLED &&
API_EXPORT_PUSH_ENABLED &&
API_EXPORT_USERS_ENABLED &&
API_EXPORT_MAGNETS_ENABLED &&
API_EXPORT_MAGNET_DOWNLOADS_ENABLED)
{
if (!$memoryApiExportPush = $memory->get('api.export.push'))
{
$memoryApiExportPush = [];
}
$memoryApiExportPush[] = (object)
[
'time' => time(),
'userId' => $user->userId,
'magnetId' => $magnet->magnetId,
'magnetDownloadId' => $magnetDownloadId
];
$memory->set('api.export.push', $memoryApiExportPush, 3600);
}
// Build magnet link
$link = (object)

View file

@ -188,6 +188,27 @@ else {
// Update form
if (!empty($_POST)) {
// Push event to other nodes
if (API_EXPORT_ENABLED &&
API_EXPORT_PUSH_ENABLED &&
API_EXPORT_USERS_ENABLED &&
API_EXPORT_MAGNETS_ENABLED)
{
if (!$memoryApiExportPush = $memory->get('api.export.push'))
{
$memoryApiExportPush = [];
}
$memoryApiExportPush[] = (object)
[
'time' => time(),
'userId' => $user->userId,
'magnetId' => $magnet->magnetId,
];
$memory->set('api.export.push', $memoryApiExportPush, 3600);
}
// Approve by moderation request
if (in_array($user->address, MODERATOR_IP_LIST))
{