issue #389 partial back-end implementation of multiple formats web upload

This commit is contained in:
plegall
2022-05-31 12:05:27 +02:00
parent 63414deadd
commit 3a63eccb0e
4 changed files with 243 additions and 9 deletions
+101
View File
@@ -1317,6 +1317,28 @@ function ws_images_upload($params, $service)
return new PwgError(403, 'Invalid security token');
}
if (isset($params['format_of']))
{
$format_ext = null;
// are formats enabled?
if (!$conf['enable_formats'])
{
return new PwgError(401, 'formats are disabled');
}
// We must check if the extension is in the authorized list.
if (preg_match('/\.('.implode('|', $conf['format_ext']).')$/', $params['name'], $matches))
{
$format_ext = $matches[1];
}
if (empty($format_ext))
{
return new PwgError(401, 'unexpected format extension of file "'.$params['name'].'" (authorized extensions: '.implode(', ', $conf['format_ext']).')');
}
}
// usleep(100000);
// if (!isset($_FILES['image']))
@@ -1405,6 +1427,36 @@ function ws_images_upload($params, $service)
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
if (isset($params['format_of']))
{
$query='
SELECT *
FROM '.IMAGES_TABLE.'
WHERE id = '. $params['format_of'] .'
;';
$images = query2array($query);
if (count($images) == 0)
{
return new PwgError(404, __FUNCTION__.' : image_id not found');
}
$image = $images[0];
add_format($filePath, $format_ext, $image['id']);
return array(
'image_id' => $image['id'],
'src' => DerivativeImage::thumb_url($image),
'square_src' => DerivativeImage::url(ImageStdParams::get_by_type(IMG_SQUARE), $image),
'name' => $image['name'],
'category' => array(
'id' => $params['category'][0], // not relevant
'nb_photos' => 42, // not relevant, once again
'label' => 'test', // not relevant
)
);
}
$image_id = add_uploaded_file(
$filePath,
stripslashes($params['name']), // function add_uploaded_file will secure before insert
@@ -1806,6 +1858,55 @@ SELECT id, file
return $result;
}
/**
* API method
* Check if an image exists by it's name or md5 sum
*
* @since 13
* @param mixed[] $params
* @option string category_id (optional)
* @option string filename_list
*/
function ws_images_formats_searchImage($params, $service)
{
global $conf, $logger;
$logger->debug(__FUNCTION__, 'WS', $params);
$result = array();
$candidates = json_decode(stripslashes($params['filename_list']), true);
// let's fake it for now: return an id without really testing the match
/*
$unique_filenames_db = array();
$query = '
SELECT
id,
file
FROM '.IMAGES_TABLE.'
;';
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
{
$filename_wo_ext = get_filename_wo_extension($row['file']);
@$unique_filenames_db[ $filename_wo_ext ][] = $row['id'];
}
*/
foreach ($candidates as $format_external_id => $format_filename)
{
$result[$format_external_id] = array(
'status' => 'found', // could be 'not found' or 'multiple'
'image_id' => 84,
);
}
return $result;
}
/**
* API method
* Check is file has been update