From 3eeb2b0ee483bfb5c845dd4cc5e6a4915526a383 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 27 Sep 2021 18:37:09 +0000 Subject: add importer daemons ported from zap --- Zotlabs/Daemon/Content_importer.php | 59 +++++++++++++++++++++++++++++++++++++ Zotlabs/Daemon/File_importer.php | 50 +++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 Zotlabs/Daemon/Content_importer.php create mode 100644 Zotlabs/Daemon/File_importer.php (limited to 'Zotlabs/Daemon') diff --git a/Zotlabs/Daemon/Content_importer.php b/Zotlabs/Daemon/Content_importer.php new file mode 100644 index 000000000..adc180a2c --- /dev/null +++ b/Zotlabs/Daemon/Content_importer.php @@ -0,0 +1,59 @@ + random_string(), + 'X-API-Request' => $hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page , + 'Host' => $m['host'], + '(request-target)' => 'get /api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page , + ]; + + $headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'], channel_url($channel),true,'sha512'); + + $x = z_fetch_url($hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page,false,$redirects,[ 'headers' => $headers ]); + + if(! $x['success']) { + logger('no API response',LOGGER_DEBUG); + killme(); + } + + $j = json_decode($x['body'],true); + + if (! $j) { + killme(); + } + + if(! ($j['item'] || count($j['item']))) + killme(); + + import_items($channel,$j['item'],false,((array_key_exists('relocate',$j)) ? $j['relocate'] : null)); + + killme(); + } +} diff --git a/Zotlabs/Daemon/File_importer.php b/Zotlabs/Daemon/File_importer.php new file mode 100644 index 000000000..f3fe785bb --- /dev/null +++ b/Zotlabs/Daemon/File_importer.php @@ -0,0 +1,50 @@ + random_string(), + 'X-API-Request' => $hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id, + 'Host' => $m['host'], + '(request-target)' => 'get /api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id, + ]; + + $headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),true,'sha512'); + $x = z_fetch_url($hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,false,$redirects,[ 'headers' => $headers ]); + + if(! $x['success']) { + logger('no API response',LOGGER_DEBUG); + return; + } + + $j = json_decode($x['body'],true); + + $r = sync_files($channel,[$j]); + + killme(); + } +} -- cgit v1.2.3