From d118ab71e6aa4f300ba6e42663d13a63a2323122 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 21 Dec 2020 21:37:10 +0000 Subject: files_ng: implement directory and bulk file download --- include/attach.php | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 8ebe2d243..b4f697f81 100644 --- a/include/attach.php +++ b/include/attach.php @@ -300,6 +300,44 @@ function attach_by_hash($hash, $observer_hash, $rev = 0) { } +/** + * @brief Find an attachment by id. + * + * Returns the entire attach structure including data. + * + * This could exhaust memory so most useful only when immediately sending the data. + * + * @param string $hash + * @param string $observer_hash + * @return array + */ +function attach_by_id($id, $observer_hash) { + + $ret = array('success' => false); + + // Check for existence, which will also provide us the owner uid + + $r = q("SELECT * FROM attach WHERE id = %d", + intval($id) + ); + if(! $r) { + $ret['message'] = t('Item was not found.'); + return $ret; + } + + if(! attach_can_view($r[0]['uid'], $observer_hash, $r[0]['hash'])) { + $ret['message'] = t('Permission denied.'); + return $ret; + } + + $r[0]['content'] = dbunescbin($r[0]['content']); + + $ret['success'] = true; + $ret['data'] = $r[0]; + + return $ret; +} + function attach_can_view($uid,$ob_hash,$resource) { $sql_extra = permissions_sql($uid,$ob_hash); @@ -1120,7 +1158,6 @@ function attach_mkdir($channel, $observer_hash, $arr = null) { if(! is_dir($os_basepath)) os_mkdir($os_basepath,STORAGE_DEFAULT_PERMISSIONS, true); - $os_basepath .= '/'; if(! perm_is_allowed($channel_id, $observer_hash, 'write_storage')) { -- cgit v1.2.3