Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 7e2abe7

Browse files
committed
ENH: refs #236. Add download by checksum capability
1 parent 33a81d7 commit 7e2abe7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

modules/api/controllers/components/ApiComponent.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,18 +977,40 @@ function userApikeyDefault($args)
977977
return array('apikey' => $defaultApiKey);
978978
}
979979

980+
/**
981+
* Download a bitstream either by its id or by a checksum. Either an id or checksum parameter is required.
982+
* @param token (Optional) Authentication token
983+
* @param id (Optional) The id of the bitstream
984+
* @param checksum (Optional) The checksum of the bitstream
985+
* @param name (Optional) Alternate filename to download as
986+
*/
980987
function bitstreamDownload($args)
981988
{
982-
$this->_validateParams($args, array('id'));
989+
if(!array_key_exists('id', $args) && !array_key_exists('checksum', $args))
990+
{
991+
throw new Exception('Either an id or checksum parameter is required', MIDAS_INVALID_PARAMETER);
992+
}
983993
$userDao = $this->_getUser($args);
984994
$modelLoader = new MIDAS_ModelLoader();
985995
$bitstreamModel = $modelLoader->loadModel('Bitstream');
986-
$bitstream = $bitstreamModel->load($args['id']);
996+
if(array_key_exists('id', $args))
997+
{
998+
$bitstream = $bitstreamModel->load($args['id']);
999+
}
1000+
else
1001+
{
1002+
$bitstream = $bitstreamModel->getByChecksum($args['checksum']);
1003+
}
9871004

9881005
if(!$bitstream)
9891006
{
9901007
throw new Exception('Invalid bitstream id', MIDAS_INVALID_PARAMETER);
9911008
}
1009+
1010+
if(array_key_exists('name', $args))
1011+
{
1012+
$bitstream->setName($args['name']);
1013+
}
9921014
$revisionModel = $modelLoader->loadModel('ItemRevision');
9931015
$revision = $revisionModel->load($bitstream->getItemrevisionId());
9941016

0 commit comments

Comments
 (0)