aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/storage.php
diff options
context:
space:
mode:
authorwinter2025-01-18 00:22:36 +0000
committerwinter2025-01-18 00:22:36 +0000
commitba61c6435b668375a411716f3a35447aa38b03a4 (patch)
treec305f2a994888a773d2b4a781176b8dffbe90576 /routes/storage.php
parent141f11ba980fe019c12f0a8fa456f520ec48e522 (diff)
implement object storage
Diffstat (limited to 'routes/storage.php')
-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