implement manifest API

This commit is contained in:
ghost 2023-04-25 19:35:52 +03:00
parent 5875dd58c9
commit a2fc14c8cf
4 changed files with 129 additions and 33 deletions

View File

@ -51,7 +51,7 @@ Could be enabled or disabled by `API_ENABLED` option
/api.php /api.php
``` ```
##### Search API ##### Search
Returns search results. Returns search results.
@ -65,7 +65,7 @@ GET query={string} - optional, search request, empty if not provided
GET page={int} - optional, search results page, 1 if not provided GET page={int} - optional, search results page, 1 if not provided
``` ```
##### Hosts distribution API ##### Hosts distribution
Returns node hosts collected with fields provided in `API_HOSTS_FIELDS` option. Returns node hosts collected with fields provided in `API_HOSTS_FIELDS` option.
@ -77,6 +77,18 @@ Could be enabled or disabled by `API_HOSTS_ENABLED` option
GET action=hosts - required GET action=hosts - required
``` ```
##### Application manifest
Returns node information.
Could be enabled or disabled by `API_MANIFEST_ENABLED` option
###### Request attributes
```
GET action=manifest - required
```
#### Roadmap / ideas #### Roadmap / ideas
* [x] Web pages full text ranking search * [x] Web pages full text ranking search

View File

@ -5,6 +5,16 @@ ini_set('display_errors', '1');
ini_set('display_startup_errors', '1'); ini_set('display_startup_errors', '1');
error_reporting(E_ALL); error_reporting(E_ALL);
// Application
/*
* Unique project name
*
* using to ident the app in the YGGo ecosystem
*
*/
define('APPLICATION_NAME', 'My YGGo host');
// Website // Website
/* /*
@ -200,3 +210,13 @@ define('API_HOSTS_FIELDS',
`host`.`timeAdded`, `host`.`timeAdded`,
`host`.`timeUpdated`, `host`.`timeUpdated`,
(SELECT COUNT(*) FROM `hostPage` WHERE `hostPage`.`hostId` = `host`.`hostId`) AS `hostPagesTotal`'); // string: *|field names comma separated (SELECT COUNT(*) FROM `hostPage` WHERE `hostPage`.`hostId` = `host`.`hostId`) AS `hostPagesTotal`'); // string: *|field names comma separated
/*
* Manifest API
*
* Application meta sharing between YGGo remote nodes
*
* When true - make this node public for distributed index sharing
*
*/
define('API_MANIFEST_ENABLED', true);

View File

@ -1,5 +1,8 @@
<?php <?php
// Current version
define('API_VERSION', 0.1);
// Load system dependencies // Load system dependencies
require_once('../config/app.php'); require_once('../config/app.php');
require_once('../library/curl.php'); require_once('../library/curl.php');
@ -17,6 +20,8 @@ if (API_ENABLED) {
// Search API // Search API
case 'search'; case 'search';
if (API_SEARCH_ENABLED) {
// Connect database // Connect database
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
@ -52,11 +57,21 @@ if (API_ENABLED) {
'result' => $dbResults, 'result' => $dbResults,
]; ];
} else {
$response = [
'status' => false,
'result' => [],
];
}
break; break;
// Host API // Host API
case 'hosts'; case 'hosts';
if (API_HOSTS_ENABLED) {
// Connect database // Connect database
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
@ -66,6 +81,52 @@ if (API_ENABLED) {
'result' => $db->getAPIHosts(API_HOSTS_FIELDS), 'result' => $db->getAPIHosts(API_HOSTS_FIELDS),
]; ];
} else {
$response = [
'status' => false,
'result' => [],
];
}
break;
// Manifest API
case 'manifest';
if (API_MANIFEST_ENABLED) {
$response = [
'status' => true,
'result' => [
'APPLICATION_NAME' => APPLICATION_NAME,
'WEBSITE_DOMAIN' => WEBSITE_DOMAIN,
'CRAWL_URL_REGEXP' => CRAWL_URL_REGEXP,
'CRAWL_HOST_DEFAULT_PAGES_LIMIT' => CRAWL_HOST_DEFAULT_PAGES_LIMIT,
'CRAWL_HOST_DEFAULT_STATUS' => CRAWL_HOST_DEFAULT_STATUS,
'CRAWL_HOST_DEFAULT_META_ONLY' => CRAWL_HOST_DEFAULT_META_ONLY,
'CRAWL_ROBOTS_DEFAULT_RULES' => CRAWL_ROBOTS_DEFAULT_RULES,
'CRAWL_ROBOTS_POSTFIX_RULES' => CRAWL_ROBOTS_POSTFIX_RULES,
'CLEAN_HOST_SECONDS_OFFSET' => CLEAN_HOST_SECONDS_OFFSET,
'API_VERSION' => API_VERSION,
'API_ENABLED' => API_ENABLED,
'API_SEARCH_ENABLED' => API_SEARCH_ENABLED,
'API_HOSTS_ENABLED' => API_HOSTS_ENABLED,
],
];
} else {
$response = [
'status' => false,
'result' => [],
];
}
break; break;
default: default:

View File

@ -21,6 +21,9 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the
<head> <head>
<title><?php echo _('YGGo! Web Search Engine') ?></title> <title><?php echo _('YGGo! Web Search Engine') ?></title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<?php if (API_MANIFEST_ENABLED) { ?>
<meta name="yggo" content="<?php echo sprintf('%s/api.php?action=manifest', WEBSITE_DOMAIN) ?>" />
<?php } ?>
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="<?php echo _('Javascript-less Open Source Web Search Engine') ?>" /> <meta name="description" content="<?php echo _('Javascript-less Open Source Web Search Engine') ?>" />
<meta name="keywords" content="<?php echo _('web, search, engine, crawler, php, pdo, mysql, sphinx, yggdrasil, js-less, open source') ?>" /> <meta name="keywords" content="<?php echo _('web, search, engine, crawler, php, pdo, mysql, sphinx, yggdrasil, js-less, open source') ?>" />