From 6236869ebed317aa06078f606156edcec9f9b55b Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 30 Sep 2021 17:34:30 +0200 Subject: implement file totals and add mod import_progress --- Zotlabs/Daemon/File_importer.php | 12 +++++-- Zotlabs/Module/Import_progress.php | 66 ++++++++++++++++++++++++++++++++++++++ include/api_zot.php | 17 +++++++--- 3 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 Zotlabs/Module/Import_progress.php diff --git a/Zotlabs/Daemon/File_importer.php b/Zotlabs/Daemon/File_importer.php index bb12cdf70..28fb172a7 100644 --- a/Zotlabs/Daemon/File_importer.php +++ b/Zotlabs/Daemon/File_importer.php @@ -48,12 +48,18 @@ class File_importer { $j = json_decode($x['body'],true); - if(! is_array($j[0]['attach']) || ! count($j[0]['attach'])) { - PConfig::Set($channel['channel_id'], 'import', 'files', 1); + if(! is_array($j['results'][0]['attach']) || ! count($j['results'][0]['attach'])) { return; } - $r = sync_files($channel,$j); + $r = sync_files($channel, $j['results']); + + PConfig::Set($channel['channel_id'], 'import', 'files_progress', [ + 'files_total' => $j['total'], + 'files_page' => 1, // export page atm returns just one file + 'last_page' => $page, + 'next_cmd' => ['File_importer',sprintf('%d',$page + 1), $channel['channel_address'], urlencode($hz_server)] + ]); $page++; diff --git a/Zotlabs/Module/Import_progress.php b/Zotlabs/Module/Import_progress.php new file mode 100644 index 000000000..3bae94bbb --- /dev/null +++ b/Zotlabs/Module/Import_progress.php @@ -0,0 +1,66 @@ +' . $co . ''; + if (is_array($c)) + $o .= '
' . htmlspecialchars(print_array($c)) . '
'; + + $o .= '

' . $fo . '

'; + if (is_array($f)) + $o .= '
' . htmlspecialchars(print_array($f)) . '
'; + + $o .= '

Refresh page for updates!

'; + + return $o; + } + +} diff --git a/include/api_zot.php b/include/api_zot.php index 93b99c0c8..dda726787 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -305,24 +305,33 @@ if(api_user() === false) return false; - $ret = []; $codebase = ((isset($_REQUEST['zap_compat']) && $_REQUEST['zap_compat']) ? true : false); $channel = channelx_by_n(api_user()); $page = ((array_key_exists('page',$_REQUEST)) ? intval($_REQUEST['page']) : 0); + $ret['success'] = false; + $ret['total'] = attach_count_files($channel['channel_id'], get_observer_hash()); + $ret['results'] = []; + + if (!$ret['total']) { + json_return_and_die($ret); + } + $files = attach_list_files($channel['channel_id'], get_observer_hash(), '', '', '', 'created asc' ,$page, 1); if (!$files['success']) { - return false; + json_return_and_die($ret); } foreach($files['results'] as $file) { - $ret[] = attach_export_data($channel, $file['hash'], false, $codebase); + $ret['results'] = attach_export_data($channel, $file['hash'], false, $codebase); } - if($ret) { + if($ret['results']) { + $ret['success'] = true; json_return_and_die($ret); } + killme(); } -- cgit v1.2.3