-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
217 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Drupal\islandora_riprap\Controller; | ||
|
||
use Drupal\Core\Controller\ControllerBase; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
/** | ||
* Controller. | ||
*/ | ||
class IslandoraRiprapGetHashController extends ControllerBase { | ||
|
||
/** | ||
* Gets the hash of the file identified by the UUID. | ||
* | ||
* @param string $file_uuid | ||
* The UUID of the file. | ||
* @param string $algorith | ||
* One of 'md5', 'sha1', or 'sha256'. | ||
* | ||
* @return JsonResponse | ||
* A JSON response. | ||
*/ | ||
public function main($file_uuid, $algorithm) { | ||
$file = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uuid' => $file_uuid]); | ||
$file = reset($file); | ||
$checksum = hash_file($algorithm, $file->getFileUri()); | ||
$response[] = [ | ||
'checksume' => $checksum, | ||
'file_uuid' => $file_uuid, | ||
'algorithm' => $algorithm, | ||
]; | ||
|
||
return new JsonResponse($response); | ||
} | ||
|
||
} |