Browse Source

add push events support

main
ghost 1 year ago
parent
commit
64693f7774
  1. 14
      example/environment/env.example.php
  2. 33
      src/library/database.php
  3. 80
      src/public/action.php
  4. 27
      src/public/download.php
  5. 21
      src/public/edit.php

14
example/environment/env.example.php

@ -130,16 +130,20 @@ define('API_VERSION', 1);
/// Export /// Export
define('API_EXPORT_ENABLED', true); define('API_EXPORT_ENABLED', true);
define('API_EXPORT_PUSH_ENABLED', true); // depends of API_EXPORT_ENABLED
define('API_EXPORT_USERS_ENABLED', true); // depends of API_EXPORT_ENABLED define('API_EXPORT_USERS_ENABLED', true); // depends of API_EXPORT_ENABLED
define('API_EXPORT_MAGNETS_ENABLED', true); // depends of API_EXPORT_ENABLED define('API_EXPORT_MAGNETS_ENABLED', true); // depends of API_EXPORT_ENABLED, API_EXPORT_USERS_ENABLED
define('API_EXPORT_MAGNET_DOWNLOADS_ENABLED', true); // depends of API_EXPORT_ENABLED define('API_EXPORT_MAGNET_DOWNLOADS_ENABLED', true); // depends of API_EXPORT_ENABLED, API_EXPORT_USERS_ENABLED, API_EXPORT_MAGNETS_ENABLED
define('API_EXPORT_MAGNET_COMMENTS_ENABLED', true); // depends of API_EXPORT_ENABLED define('API_EXPORT_MAGNET_COMMENTS_ENABLED', true); // depends of API_EXPORT_ENABLED, API_EXPORT_USERS_ENABLED, API_EXPORT_MAGNETS_ENABLED
define('API_EXPORT_MAGNET_STARS_ENABLED', true); // depends of API_EXPORT_ENABLED define('API_EXPORT_MAGNET_STARS_ENABLED', true); // depends of API_EXPORT_ENABLED, API_EXPORT_USERS_ENABLED, API_EXPORT_MAGNETS_ENABLED
define('API_EXPORT_MAGNET_VIEWS_ENABLED', true); // depends of API_EXPORT_ENABLED define('API_EXPORT_MAGNET_VIEWS_ENABLED', true); // depends of API_EXPORT_ENABLED, API_EXPORT_USERS_ENABLED, API_EXPORT_MAGNETS_ENABLED
/// Import /// Import
define('API_IMPORT_ENABLED', true); define('API_IMPORT_ENABLED', true);
define('API_IMPORT_PUSH_ENABLED', true); // depends of API_IMPORT_ENABLED
define('API_IMPORT_USERS_ENABLED', true); // depends of API_IMPORT_ENABLED define('API_IMPORT_USERS_ENABLED', true); // depends of API_IMPORT_ENABLED
define('API_IMPORT_USERS_APPROVED_ONLY', false); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED define('API_IMPORT_USERS_APPROVED_ONLY', false); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED
define('API_IMPORT_MAGNETS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED define('API_IMPORT_MAGNETS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED

33
src/library/database.php

@ -1444,6 +1444,17 @@ class Database {
return $this->_db->lastInsertId(); return $this->_db->lastInsertId();
} }
public function getMagnetStar(int $magnetStarId) {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `magnetStar` WHERE `magnetStarId` = ?');
$query->execute([$magnetStarId]);
return $query->fetch();
}
public function getMagnetStars() { public function getMagnetStars() {
$this->_debug->query->select->total++; $this->_debug->query->select->total++;
@ -1533,6 +1544,17 @@ class Database {
return $this->_db->lastInsertId(); return $this->_db->lastInsertId();
} }
public function getMagnetDownload(int $magnetDownloadId) {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `magnetDownload` WHERE `magnetDownloadId` = ?');
$query->execute([$magnetDownloadId]);
return $query->fetch();
}
public function getMagnetDownloads() { public function getMagnetDownloads() {
$this->_debug->query->select->total++; $this->_debug->query->select->total++;
@ -1629,6 +1651,17 @@ class Database {
return $query->fetchAll(); return $query->fetchAll();
} }
public function getMagnetView(int $magnetViewId) {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `magnetView` WHERE `magnetViewId` = ?');
$query->execute([$magnetViewId]);
return $query->fetch();
}
public function getMagnetViewsTotal() : int { public function getMagnetViewsTotal() : int {
$this->_debug->query->select->total++; $this->_debug->query->select->total++;

80
src/public/action.php

@ -237,13 +237,37 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
else else
{ {
if ($magnetCommentId = $db->addMagnetComment($magnet->magnetId, if ($magnetCommentId = $db->addMagnetComment($magnet->magnetId,
$user->userId, $user->userId,
null, // @TODO implement threads null, // @TODO implement threads
trim($_POST['comment']), trim($_POST['comment']),
$user->approved || in_array($user->address, MODERATOR_IP_LIST) ? true : MAGNET_COMMENT_DEFAULT_APPROVED, $user->approved || in_array($user->address, MODERATOR_IP_LIST) ? true : MAGNET_COMMENT_DEFAULT_APPROVED,
MAGNET_COMMENT_DEFAULT_PUBLIC, MAGNET_COMMENT_DEFAULT_PUBLIC,
time())) 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 // Redirect to referrer page
header( header(
sprintf('Location: %s#comment-%s', $callback, $magnetCommentId) sprintf('Location: %s#comment-%s', $callback, $magnetCommentId)
@ -328,18 +352,40 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
// Request valid // Request valid
else else
{ {
// Save value // Save star
$db->addMagnetStar( if ($magnetStarId = $db->addMagnetStar( $magnet->magnetId,
$magnet->magnetId, $user->userId,
$userId, !$db->findLastMagnetStarValue($magnet->magnetId, $user->userId),
!$db->findLastMagnetStarValue($magnet->magnetId, $userId), time()))
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 $memoryApiExportPush[] = (object)
header( [
sprintf('Location: %s', $callback) '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; break;

27
src/public/download.php

@ -62,8 +62,31 @@ else if (is_null($user->public))
// Request valid // Request valid
else else
{ {
// Update download stats // Register magnet download
$db->addMagnetDownload($magnet->magnetId, $userId, time()); $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 // Build magnet link
$link = (object) $link = (object)

21
src/public/edit.php

@ -188,6 +188,27 @@ else {
// Update form // Update form
if (!empty($_POST)) { 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 // Approve by moderation request
if (in_array($user->address, MODERATOR_IP_LIST)) if (in_array($user->address, MODERATOR_IP_LIST))
{ {

Loading…
Cancel
Save