Skip to content

Make file download requests go through Omeka, allowing other modules to do access control, analytics, ...

License

Notifications You must be signed in to change notification settings

biblibre/omeka-s-module-FileGate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Gate

File Gate is an Omeka S module that make file download requests go through the application, allowing other modules to do things like access control, analytics, ...

How it works

File Gate rewrites the URLs of original files. For instance it will rewrite

https://omeka.example.com/files/original/8e595076a83fb5c1e867e468f1558808b2b8d2fb.jpg

to

https://omeka.example.com/s/some-site/filegate/b3JpZ2luYWwvOGU1OTUwNzZhODNmYjVjMWU4NjdlNDY4ZjE1NTg4MDhiMmI4ZDJmYi5qcGc

When a request is made to that URL, it will trigger an event, which other modules can attach listeners to.

Listeners may return a Laminas\Http\Response object. In that case, this response will be sent immediately and the remaining listeners will not be executed. If no listeners return a response, the default response is sent, which is a 302 redirect to the real file URI.

For instance:

<?php

    public function attachListeners(SharedEventManagerInterface $sharedEventManager)
    {
        $sharedEventManager->attach('*', 'filegate', [$this, 'onFileAccess']);
    }

    public function onFileAccess ($event)
    {
        $controller = $event->getTarget();
        $storagePath = $event->getParam('storagePath');

        // Get real URI
        $fileStore = $this->getServiceLocator()->get('Omeka\File\Store');
        $uri = $fileStore->getUri($storagePath);

        // Get HTTP request
        $request = $controller->getRequest();

        // Optionally return a Response
        $response = new \Laminas\Http\Response;
        $response->setStatusCode(403);
        return $response;
    }

Requirements

  • Omeka S 4.0.0 or greater

Additional notes

  • File URL rewrite happens only while browsing sites. On the admin interface there is no URL rewrite.
  • File URL rewrite happens only for original files. Thumbnails, assets, and other files URLs are not rewritten.
  • It is compatible with the following file stores:
    • The Local file store (the default)
    • All AnyCloud file stores

License

This module is distributed under the GNU General Public License, version 3 (GPLv3). The full text of this license is given in the LICENSE file.

About

Make file download requests go through Omeka, allowing other modules to do access control, analytics, ...

Resources

License

Stars

Watchers

Forks

Packages

No packages published