Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the UrlGenerator instead of $_SERVER to determine address #82

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Lock\LockedException;
use OCP\Share\IManager;
Expand All @@ -37,7 +38,8 @@ public function __construct(
private readonly IUserSession $userSession,
private readonly LoggerInterface $logger,
private readonly IRootFolder $rootFolder,
private readonly IManager $shareManager
private readonly IManager $shareManager,
private readonly IURLGenerator $urlGenerator,
) {}

/**
Expand Down Expand Up @@ -86,15 +88,7 @@ public function getShareLink(IShare $share): string
*/
private function getCurrentDomain(): string
{
// Check if the request is over HTTPS
$isHttps = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
$protocol = $isHttps ? 'https://' : 'http://';

// Get the host (domain)
$host = $_SERVER['HTTP_HOST'];

// Construct the full URL
return $protocol . $host;
return $this->urlGenerator->getBaseUrl();
}

/**
Expand Down
Loading