aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Daemon/File_importer.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-09-27 18:37:09 +0000
committerMario <mario@mariovavti.com>2021-09-27 18:37:09 +0000
commit3eeb2b0ee483bfb5c845dd4cc5e6a4915526a383 (patch)
tree88a6c1bbda95c46357a291a8a103807d1e3063d2 /Zotlabs/Daemon/File_importer.php
parent230a1919ddc0c5456c5beb26c89bf99badae9d30 (diff)
downloadvolse-hubzilla-3eeb2b0ee483bfb5c845dd4cc5e6a4915526a383.tar.gz
volse-hubzilla-3eeb2b0ee483bfb5c845dd4cc5e6a4915526a383.tar.bz2
volse-hubzilla-3eeb2b0ee483bfb5c845dd4cc5e6a4915526a383.zip
add importer daemons ported from zap
Diffstat (limited to 'Zotlabs/Daemon/File_importer.php')
-rw-r--r--Zotlabs/Daemon/File_importer.php50
1 files changed, 50 insertions, 0 deletions
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 @@
+<?php
+
+namespace Zotlabs\Daemon;
+
+use Zotlabs\Web\HTTPSig;
+
+require_once('include/cli_startup.php');
+require_once('include/attach.php');
+require_once('include/import.php');
+
+class File_importer {
+
+ static public function run($argc,$argv) {
+
+ cli_startup();
+
+ $attach_id = $argv[1];
+ $channel_address = $argv[2];
+ $hz_server = urldecode($argv[3]);
+
+ $m = parse_url($hz_server);
+
+ $channel = channelx_by_nick($channel_address);
+ if(! $channel) {
+ logger('filehelper: channel not found');
+ killme();
+ }
+
+ $headers = [
+ 'X-API-Token' => 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();
+ }
+}