aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/storage.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/routes/storage.php b/routes/storage.php
new file mode 100644
index 0000000..341770b
--- /dev/null
+++ b/routes/storage.php
@@ -0,0 +1,27 @@
+<?php
+
+use Digitigrade\HttpResponseStatus\NotFound;
+use Digitigrade\Model\StorageObject;
+use Digitigrade\Router;
+use Digitigrade\StorageProvider\FilesystemStorage;
+
+Router::getInstance()->mount('/storage/:oid', function (array $args) {
+ // find the storage object regardless of backend provider
+ $obj = StorageObject::findByOid($args['oid']);
+ if ($obj == null) {
+ throw new NotFound('unknown object');
+ }
+ header("Content-Disposition: inline; filename*=UTF-8''" . urlencode($obj->filename));
+ $obj->passthrough();
+});
+
+Router::getInstance()->mount('/upload/:token', function (array $args) {
+ // for direct urls for the FilesystemStorage backend, in case the server
+ // admin didn't put a special handler in their reverse proxy
+ $storage = new FilesystemStorage();
+ $token = $args['token'];
+ if (!$storage->exists($token)) {
+ throw new NotFound('unknown object');
+ }
+ $storage->passthrough($token);
+}); \ No newline at end of file