Skip to content

Commit

Permalink
Address #33.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Aug 19, 2020
1 parent dd6b825 commit f713b25
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 217 deletions.
217 changes: 0 additions & 217 deletions config/optional/views.view.file_checksum_from_uuid.yml

This file was deleted.

12 changes: 12 additions & 0 deletions islandora_riprap.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ islandora_riprap.events_report:
_title: 'Failed Fixity Check Events'
requirements:
_permission: 'administer site configuration'

islandora.riprap.hash:
path: '/islandora_riprap/checksum/{file_uuid}/{algorithm}'
defaults:
_controller: '\Drupal\islandora_riprap\Controller\IslandoraRiprapGetHashController::main'
methods: [GET]
requirements:
# Defined by the Islandora module.
_permission: 'view checksums'
options:
_auth: ['basic_auth', 'cookie', 'jwt_auth']

37 changes: 37 additions & 0 deletions src/Controller/IslandoraRiprapGetHashController.php
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);
}

}

0 comments on commit f713b25

Please sign in to comment.