Browse Source

update manifest api

main
ghost 1 year ago
parent
commit
b4ad54513b
  1. 101
      src/crontab/export/feed.php
  2. 26
      src/crontab/import/feed.php

101
src/crontab/export/feed.php

@ -52,40 +52,63 @@ try
'settings' => (object) 'settings' => (object)
[ [
'YGGDRASIL_HOST_REGEX' => YGGDRASIL_HOST_REGEX, 'YGGDRASIL_HOST_REGEX' => (string) YGGDRASIL_HOST_REGEX,
'NODE_RULE_SUBJECT' => NODE_RULE_SUBJECT, 'NODE_RULE_SUBJECT' => (string) NODE_RULE_SUBJECT,
'NODE_RULE_LANGUAGES' => NODE_RULE_LANGUAGES, 'NODE_RULE_LANGUAGES' => (string) NODE_RULE_LANGUAGES,
'USER_DEFAULT_APPROVED' => USER_DEFAULT_APPROVED, 'USER_DEFAULT_APPROVED' => (bool) USER_DEFAULT_APPROVED,
'USER_AUTO_APPROVE_ON_MAGNET_APPROVE' => USER_AUTO_APPROVE_ON_MAGNET_APPROVE, 'USER_AUTO_APPROVE_ON_MAGNET_APPROVE' => (bool) USER_AUTO_APPROVE_ON_MAGNET_APPROVE,
'USER_AUTO_APPROVE_ON_COMMENT_APPROVE' => USER_AUTO_APPROVE_ON_COMMENT_APPROVE, 'USER_AUTO_APPROVE_ON_COMMENT_APPROVE' => (bool) USER_AUTO_APPROVE_ON_COMMENT_APPROVE,
'USER_DEFAULT_IDENTICON' => USER_DEFAULT_IDENTICON, 'USER_DEFAULT_IDENTICON' => (string) USER_DEFAULT_IDENTICON,
'USER_IDENTICON_FIELD' => USER_IDENTICON_FIELD, 'USER_IDENTICON_FIELD' => (string) USER_IDENTICON_FIELD,
'MAGNET_DEFAULT_APPROVED' => MAGNET_DEFAULT_APPROVED, 'MAGNET_DEFAULT_APPROVED' => (bool) MAGNET_DEFAULT_APPROVED,
'MAGNET_DEFAULT_PUBLIC' => MAGNET_DEFAULT_PUBLIC, 'MAGNET_DEFAULT_PUBLIC' => (bool) MAGNET_DEFAULT_PUBLIC,
'MAGNET_DEFAULT_COMMENTS' => MAGNET_DEFAULT_COMMENTS, 'MAGNET_DEFAULT_COMMENTS' => (bool) MAGNET_DEFAULT_COMMENTS,
'MAGNET_DEFAULT_SENSITIVE' => MAGNET_DEFAULT_SENSITIVE, 'MAGNET_DEFAULT_SENSITIVE' => (bool) MAGNET_DEFAULT_SENSITIVE,
'MAGNET_EDITOR_LOCK_TIMEOUT' => MAGNET_EDITOR_LOCK_TIMEOUT, 'MAGNET_EDITOR_LOCK_TIMEOUT' => (int) MAGNET_EDITOR_LOCK_TIMEOUT,
'MAGNET_TITLE_MIN_LENGTH' => MAGNET_TITLE_MIN_LENGTH, 'MAGNET_TITLE_MIN_LENGTH' => (int) MAGNET_TITLE_MIN_LENGTH,
'MAGNET_TITLE_MAX_LENGTH' => MAGNET_TITLE_MAX_LENGTH, 'MAGNET_TITLE_MAX_LENGTH' => (int) MAGNET_TITLE_MAX_LENGTH,
'MAGNET_PREVIEW_MIN_LENGTH' => MAGNET_PREVIEW_MIN_LENGTH, 'MAGNET_PREVIEW_MIN_LENGTH' => (int) MAGNET_PREVIEW_MIN_LENGTH,
'MAGNET_PREVIEW_MAX_LENGTH' => MAGNET_PREVIEW_MAX_LENGTH, 'MAGNET_PREVIEW_MAX_LENGTH' => (int) MAGNET_PREVIEW_MAX_LENGTH,
'MAGNET_DESCRIPTION_MIN_LENGTH' => MAGNET_DESCRIPTION_MIN_LENGTH, 'MAGNET_DESCRIPTION_MIN_LENGTH' => (int) MAGNET_DESCRIPTION_MIN_LENGTH,
'MAGNET_DESCRIPTION_MAX_LENGTH' => MAGNET_DESCRIPTION_MAX_LENGTH, 'MAGNET_DESCRIPTION_MAX_LENGTH' => (int) MAGNET_DESCRIPTION_MAX_LENGTH,
'MAGNET_COMMENT_DEFAULT_APPROVED' => MAGNET_COMMENT_DEFAULT_APPROVED, 'MAGNET_COMMENT_DEFAULT_APPROVED' => (bool) MAGNET_COMMENT_DEFAULT_APPROVED,
'MAGNET_COMMENT_DEFAULT_PUBLIC' => MAGNET_COMMENT_DEFAULT_PUBLIC, 'MAGNET_COMMENT_DEFAULT_PUBLIC' => (bool) MAGNET_COMMENT_DEFAULT_PUBLIC,
'MAGNET_COMMENT_DEFAULT_PUBLIC' => MAGNET_COMMENT_DEFAULT_PUBLIC, 'MAGNET_COMMENT_DEFAULT_PUBLIC' => (bool) MAGNET_COMMENT_DEFAULT_PUBLIC,
'MAGNET_COMMENT_MIN_LENGTH' => MAGNET_COMMENT_MIN_LENGTH, 'MAGNET_COMMENT_MIN_LENGTH' => (int) MAGNET_COMMENT_MIN_LENGTH,
'MAGNET_COMMENT_MAX_LENGTH' => MAGNET_COMMENT_MAX_LENGTH, 'MAGNET_COMMENT_MAX_LENGTH' => (int) MAGNET_COMMENT_MAX_LENGTH,
'MAGNET_STOP_WORDS_SIMILAR' => (object) MAGNET_STOP_WORDS_SIMILAR, 'MAGNET_STOP_WORDS_SIMILAR' => (object) MAGNET_STOP_WORDS_SIMILAR,
'API_EXPORT_ENABLED' => (bool) API_EXPORT_ENABLED,
'API_EXPORT_PUSH_ENABLED' => (bool) API_EXPORT_PUSH_ENABLED,
'API_EXPORT_USERS_ENABLED' => (bool) API_EXPORT_USERS_ENABLED,
'API_EXPORT_MAGNETS_ENABLED' => (bool) API_EXPORT_MAGNETS_ENABLED,
'API_EXPORT_MAGNET_DOWNLOADS_ENABLED' => (bool) API_EXPORT_MAGNET_DOWNLOADS_ENABLED,
'API_EXPORT_MAGNET_COMMENTS_ENABLED' => (bool) API_EXPORT_MAGNET_COMMENTS_ENABLED,
'API_EXPORT_MAGNET_STARS_ENABLED' => (bool) API_EXPORT_MAGNET_STARS_ENABLED,
'API_EXPORT_MAGNET_STARS_ENABLED' => (bool) API_EXPORT_MAGNET_STARS_ENABLED,
'API_EXPORT_MAGNET_VIEWS_ENABLED' => (bool) API_EXPORT_MAGNET_VIEWS_ENABLED,
'API_IMPORT_ENABLED' => (bool) API_IMPORT_ENABLED,
'API_IMPORT_PUSH_ENABLED' => (bool) API_IMPORT_PUSH_ENABLED,
'API_IMPORT_USERS_ENABLED' => (bool) API_IMPORT_USERS_ENABLED,
'API_IMPORT_USERS_APPROVED_ONLY' => (bool) API_IMPORT_USERS_APPROVED_ONLY,
'API_IMPORT_MAGNETS_ENABLED' => (bool) API_IMPORT_MAGNETS_ENABLED,
'API_IMPORT_MAGNETS_APPROVED_ONLY' => (bool) API_IMPORT_MAGNETS_APPROVED_ONLY,
'API_IMPORT_MAGNET_DOWNLOADS_ENABLED' => (bool) API_IMPORT_MAGNET_DOWNLOADS_ENABLED,
'API_IMPORT_MAGNET_COMMENTS_ENABLED' => (bool) API_IMPORT_MAGNET_COMMENTS_ENABLED,
'API_IMPORT_MAGNET_COMMENTS_APPROVED_ONLY' => (bool) API_IMPORT_MAGNET_COMMENTS_APPROVED_ONLY,
'API_IMPORT_MAGNET_STARS_ENABLED' => (bool) API_IMPORT_MAGNET_STARS_ENABLED,
'API_IMPORT_MAGNET_VIEWS_ENABLED' => (bool) API_IMPORT_MAGNET_VIEWS_ENABLED,
], ],
'totals' => (object) 'totals' => (object)
[ [
@ -120,7 +143,11 @@ try
'local' => $db->findMagnetViewsTotalByUsersPublic(false), 'local' => $db->findMagnetViewsTotalByUsersPublic(false),
], ],
], ],
'feeds' => (object) 'import' => (object)
[
'push' => API_IMPORT_PUSH_ENABLED ? sprintf('%s/api/push.php', WEBSITE_URL) : false,
],
'export' => (object)
[ [
'users' => API_EXPORT_USERS_ENABLED ? sprintf('%s/api/users.json', WEBSITE_URL) : false, 'users' => API_EXPORT_USERS_ENABLED ? sprintf('%s/api/users.json', WEBSITE_URL) : false,
'magnets' => API_EXPORT_MAGNETS_ENABLED ? sprintf('%s/api/magnets.json', WEBSITE_URL) : false, 'magnets' => API_EXPORT_MAGNETS_ENABLED ? sprintf('%s/api/magnets.json', WEBSITE_URL) : false,
@ -129,8 +156,8 @@ try
'magnetStars' => API_EXPORT_MAGNET_STARS_ENABLED ? sprintf('%s/api/magnetStars.json', WEBSITE_URL) : false, 'magnetStars' => API_EXPORT_MAGNET_STARS_ENABLED ? sprintf('%s/api/magnetStars.json', WEBSITE_URL) : false,
'magnetViews' => API_EXPORT_MAGNET_VIEWS_ENABLED ? sprintf('%s/api/magnetViews.json', WEBSITE_URL) : false, 'magnetViews' => API_EXPORT_MAGNET_VIEWS_ENABLED ? sprintf('%s/api/magnetViews.json', WEBSITE_URL) : false,
], ],
'trackers' => (object) json_decode(file_get_contents(__DIR__ . '/../../config/trackers.json')), 'trackers' => (object) json_decode(file_get_contents(__DIR__ . '/../../config/trackers.json')),
'nodes' => (object) json_decode(file_get_contents(__DIR__ . '/../../config/nodes.json')), 'nodes' => (object) json_decode(file_get_contents(__DIR__ . '/../../config/nodes.json')),
]; ];
/// Dump feed /// Dump feed

26
src/crontab/import/feed.php

@ -39,7 +39,7 @@ try
if ($manifest = @json_decode(@file_get_contents($node->manifest))) if ($manifest = @json_decode(@file_get_contents($node->manifest)))
{ {
// Feed channel exists // Feed channel exists
if (empty($manifest->feeds)) if (empty($manifest->export))
{ {
continue; continue;
} }
@ -47,7 +47,7 @@ try
// Users // Users
if (API_IMPORT_USERS_ENABLED) if (API_IMPORT_USERS_ENABLED)
{ {
if (empty($manifest->feeds->users)) if (empty($manifest->export->users))
{ {
continue; continue;
} }
@ -55,7 +55,7 @@ try
// Init alias registry for this host // Init alias registry for this host
$aliasUserId = []; $aliasUserId = [];
foreach (@json_decode(@file_get_contents($manifest->feeds->users)) as $remoteUser) foreach (@json_decode(@file_get_contents($manifest->export->users)) as $remoteUser)
{ {
// Validate required fields // Validate required fields
if (!isset($remoteUser->address) || !preg_match(YGGDRASIL_HOST_REGEX, $remoteUser->address) || if (!isset($remoteUser->address) || !preg_match(YGGDRASIL_HOST_REGEX, $remoteUser->address) ||
@ -133,7 +133,7 @@ try
// Magnets // Magnets
if (API_IMPORT_MAGNETS_ENABLED) if (API_IMPORT_MAGNETS_ENABLED)
{ {
if (empty($manifest->feeds->magnets)) if (empty($manifest->export->magnets))
{ {
continue; continue;
} }
@ -141,7 +141,7 @@ try
// Init alias registry for this host // Init alias registry for this host
$aliasMagnetId = []; $aliasMagnetId = [];
foreach (@json_decode(@file_get_contents($manifest->feeds->magnets)) as $remoteMagnet) foreach (@json_decode(@file_get_contents($manifest->export->magnets)) as $remoteMagnet)
{ {
// Validate required fields by protocol // Validate required fields by protocol
if (!isset($remoteMagnet->userId) || !is_int($remoteMagnet->userId) || if (!isset($remoteMagnet->userId) || !is_int($remoteMagnet->userId) ||
@ -383,12 +383,12 @@ try
// Magnet comments // Magnet comments
if (API_IMPORT_MAGNET_COMMENTS_ENABLED) if (API_IMPORT_MAGNET_COMMENTS_ENABLED)
{ {
if (empty($manifest->feeds->magnetComments)) if (empty($manifest->export->magnetComments))
{ {
continue; continue;
} }
foreach (@json_decode(@file_get_contents($manifest->feeds->magnetComments)) as $remoteMagnetComment) foreach (@json_decode(@file_get_contents($manifest->export->magnetComments)) as $remoteMagnetComment)
{ {
// Validate // Validate
if ( if (
@ -442,12 +442,12 @@ try
// Magnet downloads // Magnet downloads
if (API_IMPORT_MAGNET_DOWNLOADS_ENABLED) if (API_IMPORT_MAGNET_DOWNLOADS_ENABLED)
{ {
if (empty($manifest->feeds->magnetDownloads)) if (empty($manifest->export->magnetDownloads))
{ {
continue; continue;
} }
foreach (@json_decode(@file_get_contents($manifest->feeds->magnetDownloads)) as $remoteMagnetDownload) foreach (@json_decode(@file_get_contents($manifest->export->magnetDownloads)) as $remoteMagnetDownload)
{ {
// Validate // Validate
if ( if (
@ -476,12 +476,12 @@ try
// Magnet views // Magnet views
if (API_IMPORT_MAGNET_VIEWS_ENABLED) if (API_IMPORT_MAGNET_VIEWS_ENABLED)
{ {
if (empty($manifest->feeds->magnetViews)) if (empty($manifest->export->magnetViews))
{ {
continue; continue;
} }
foreach (@json_decode(@file_get_contents($manifest->feeds->magnetViews)) as $remoteMagnetView) foreach (@json_decode(@file_get_contents($manifest->export->magnetViews)) as $remoteMagnetView)
{ {
// Validate // Validate
if ( if (
@ -510,12 +510,12 @@ try
// Magnet stars // Magnet stars
if (API_IMPORT_MAGNET_STARS_ENABLED) if (API_IMPORT_MAGNET_STARS_ENABLED)
{ {
if (empty($manifest->feeds->magnetStars)) if (empty($manifest->export->magnetStars))
{ {
continue; continue;
} }
foreach (@json_decode(@file_get_contents($manifest->feeds->magnetStars)) as $remoteMagnetStar) foreach (@json_decode(@file_get_contents($manifest->export->magnetStars)) as $remoteMagnetStar)
{ {
// Validate // Validate
if ( if (

Loading…
Cancel
Save