Skip to content

feat(files_sharing): configure public share link base URL#62146

Open
camr0 wants to merge 8 commits into
nextcloud:masterfrom
camr0:public-share-base-url
Open

feat(files_sharing): configure public share link base URL#62146
camr0 wants to merge 8 commits into
nextcloud:masterfrom
camr0:public-share-base-url

Conversation

@camr0

@camr0 camr0 commented Jul 15, 2026

Copy link
Copy Markdown

Summary

Adds an optional 'shareapi_public_link_base_url' config flag to set a custom base URL just for share links. When unset, Nextcloud behaves exactly the same.

The new "PublicShareUrlGenerator" reads the config value and validates that it's a valid HTTP(S) URL. If it's unset or if the URL is invalid, we fall back to Nextcloud's existing URL generator. Existing references to the current URL generator are replaced with this new one for the OCS Share API URL field, public shares, and public link reminder emails.

At the same time, all URLs unrelated to sharing remain unchanged and still use the standard UrlGenerator.

The web UI is also updated to use the OCS response's URL field, instead of reconstructing the share link from the current base URL. Again, if the flag is unset, we fall back to the existing local construction.

TYPE_EMAIL shares now expose a URL field in the OCS response. Also, ShareByMailProvider now takes PublicShareUrlGenerator, both email paths use it (sendEmail() and sendNote()).

This is my first contribution to this project, so I'd appreciate any feedback or guidance on how to approach the documentation and other details.

Assisted-by: Codex:GPT-5.6

Before: Screenshot 2026-07-15 at 12 32 32 AM

After: Screenshot 2026-07-15 at 12 39 53 AM

Updated Documentation PR

TODO

  • Manual live testing

    • when flag unset, link remains with default base URL
    • when valid flag set, link works correctly with custom base URL
    • when invalid flag set, link still remains with default base url (fallback)
  • Screenshots

  • Update documentation (occ config:app:set core shareapi_public_link_base_url --value='https://example.com/')

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@camr0
camr0 force-pushed the public-share-base-url branch from 838a43c to 9df6210 Compare July 22, 2026 05:53
camr0 added a commit to camr0/documentation that referenced this pull request Jul 22, 2026
Documentation for nextcloud/server#62146

Signed-off-by: Ali Aslam <ali.aslam@zohomail.com> 

Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
@camr0

camr0 commented Jul 22, 2026

Copy link
Copy Markdown
Author

Documentation added in nextcloud/documentation#15361
nextcloud/documentation#15361

@camr0
camr0 marked this pull request as ready for review July 22, 2026 07:15
@camr0
camr0 requested review from a team as code owners July 22, 2026 07:15
@camr0
camr0 requested review from come-nc, kristian-zendato, leftybournes, nfebe and sorbaugh and removed request for a team July 22, 2026 07:15

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9df62106ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

private LoggerInterface $logger,
private IMailer $mailer,
private IURLGenerator $urlGenerator,
private PublicShareUrlGenerator $publicShareUrlGenerator,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid requiring files_sharing from sharebymail

When sharebymail is enabled without files_sharing (its appinfo/info.xml does not declare a files_sharing dependency), autowiring this provider now has to resolve OCA\Files_Sharing\PublicShareUrlGenerator from an app whose autoloader is not registered for that request. That can make ProviderFactory::getShareByMailProvider() fail while enumerating or resolving mail-share providers, before the app can handle the missing sharing UI/routes gracefully; either keep the URL helper in a dependency that sharebymail owns/core owns, or declare/load the files_sharing dependency explicitly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a try/catch to cover that edge case, pls review again

camr0 added 8 commits July 22, 2026 02:51
Assisted-by: Codex:GPT-5
Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Assisted-by: Codex:GPT-5
Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Assisted-by: Codex:GPT-5
Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Assisted-by: Codex:GPT-5
Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Build the share link path through the router instead of hardcoding
'/s/{token}' so instances without pretty URLs keep their '/index.php'
front controller prefix when a custom base URL is configured. The
instance webroot is still replaced by the configured base URL.

Also trim surrounding whitespace from the configured value and log a
warning (once per process) when a non-empty value is rejected, instead
of falling back silently.

Assisted-by: ClaudeCode:kimi-k3[1m]
Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
The share notification and note emails still built the share link with
the instance URL generator, so recipients received links pointing at
the internal host even when shareapi_public_link_base_url was set.
Generate them through PublicShareUrlGenerator like the other public
share links.

Assisted-by: ClaudeCode:kimi-k3[1m]
Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Assisted-by: ClaudeCode:kimi-k3[1m]
Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Wrap Server::get(ShareByMailProvider::class) in a try/catch so that if
the provider's dependencies cannot be resolved (e.g. PublicShareUrlGenerator
from files_sharing is not autoloaded when the app is disabled), the
provider factory falls back to null instead of throwing, matching the
pattern already used for registered share providers.

Assisted-by: ClaudeCode:kimi-k3[1m]
Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
@camr0
camr0 force-pushed the public-share-base-url branch from 9df6210 to eded848 Compare July 22, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant