Skip to content

Commit

Permalink
add API version check #13, #14
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost committed Sep 21, 2023
1 parent 3507abc commit fe2a7a5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 0 additions & 2 deletions example/environment/env.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@
define('NODE_RULE_LANGUAGES', 'All');

// API
define('API_VERSION', '1.0.0');

define('API_USER_AGENT', WEBSITE_NAME);

/// Export
Expand Down
4 changes: 4 additions & 0 deletions src/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// PHP
declare(strict_types=1);

// Application
define('APP_VERSION', '2.0.0');
define('API_VERSION', APP_VERSION);

// Init environment
if (!file_exists(__DIR__ . '/.env'))
{
Expand Down
4 changes: 2 additions & 2 deletions src/crontab/export/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
// Manifest
$manifest =
[
'updated' => time(),
'updated' => time(),
'version' => (string) API_VERSION,

'settings' => (object)
[
Expand Down Expand Up @@ -119,7 +120,6 @@

'MAGNET_STOP_WORDS_SIMILAR' => (object) MAGNET_STOP_WORDS_SIMILAR,

'API_VERSION' => (string) API_VERSION,
'API_USER_AGENT' => (string) API_USER_AGENT,

'API_EXPORT_ENABLED' => (bool) API_EXPORT_ENABLED,
Expand Down
13 changes: 13 additions & 0 deletions src/crontab/import/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@
continue;
}

if (empty($manifest->version) || $manifest->version !== API_VERSION)
{
array_push(
$debug['dump'],
sprintf(
_('Manifest API not compatible with local version "%s"'),
API_VERSION
)
);

continue;
}

if (empty($manifest->export))
{
array_push(
Expand Down

0 comments on commit fe2a7a5

Please sign in to comment.