-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11686 from nanaya/proxy-media-controller
Clean up proxy media controller
- Loading branch information
Showing
4 changed files
with
38 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
class ProxyMediaController extends Controller | ||
{ | ||
private static function fromNonBrowser(): bool | ||
{ | ||
$headers = \Request::instance()->headers; | ||
|
||
return $headers->get('origin') === null | ||
&& $headers->get('referer') === null | ||
&& $headers->get('sec-fetch-site') === null; | ||
} | ||
|
||
public function __invoke() | ||
{ | ||
if (!static::fromNonBrowser() && !from_app_url()) { | ||
return response('Forbidden', 403); | ||
} | ||
|
||
$url = presence(get_string(\Request::input('url'))); | ||
|
||
if (!isset($url)) { | ||
return response('Missing url parameter', 422); | ||
} | ||
|
||
// Tell browser to cache redirect url for a while. | ||
return redirect(proxy_media($url))->header('Cache-Control', 'max-age=86400'); | ||
} | ||
} |
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