-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pipe out image files stored in folder `.\lot\image` with a proxy. This allows other developers to create a feature to limit the image access with certain criteria.
- Loading branch information
1 parent
46b814e
commit 863e356
Showing
6 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
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
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,25 @@ | ||
<?php namespace x\image; | ||
|
||
function route($content, $path) { | ||
$age = 60 * 60 * 24 * 30; // Cache output for 30 day(s) | ||
\status(200, [ | ||
'cache-control' => 'max-age=' . $age . ', private', | ||
'expires' => \gmdate('D, d M Y H:i:s', $age + $_SERVER['REQUEST_TIME']) . ' GMT', | ||
'pragma' => 'private' | ||
]); | ||
\type(\mime_content_type($file = \LOT . \D . 'image' . \D . \trim($path ?? "", '/'))); | ||
echo \file_get_contents($file); | ||
exit; | ||
} | ||
|
||
$path = \trim($url->path ?? "", '/'); | ||
$route = \trim($state->x->image->route ?? 'image', '/'); | ||
if (0 === \strpos($path, $route . '/') && \is_file($file = \LOT . \D . 'image' . \D . \substr($path, \strlen($route) + 1))) { | ||
\Hook::set('route.image', __NAMESPACE__ . "\\route", 100); | ||
\Hook::set('route', function ($content, $path, $query, $hash) use ($file, $route) { | ||
if (false !== \strpos(',apng,avif,bmp,gif,jpeg,jpg,png,webp,xbm,xpm,', ',' . \pathinfo($file, \PATHINFO_EXTENSION) . ',')) { | ||
return \Hook::fire('route.image', [$content, \substr($path, \strlen($route) + 1), $query, $hash]); | ||
} | ||
return $content; | ||
}, 0); | ||
} |
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,3 @@ | ||
<?php | ||
|
||
return ['route' => '/image']; |