Skip to content

feat(media): add a WebDAV share as a media source - #430

Open
obelix58143 wants to merge 5 commits into
trypostit:mainfrom
obelix58143:feat/webdav-media-source-v2
Open

obelix58143 wants to merge 5 commits into
trypostit:mainfrom
obelix58143:feat/webdav-media-source-v2

Conversation

@obelix58143

@obelix58143 obelix58143 commented Oct 15, 2026 •

Copy link
Copy Markdown

Replaces #355, which was written against the pre-2.0 gallery and is closed. This one plugs into the 2.0 MediaSource menu and import pipeline instead of building its own.

What it does

Adds WebDAV (Nextcloud, ownCloud, any WebDAV server) as a picker source next to GIPHY, Google Drive, Google Photos, Canva and Unsplash. Self-hosted teams often already keep their photos in a Nextcloud folder; this lets them pick from it in the composer without downloading and re-uploading.

  • Browse: a small file-browser dialog lists one folder at a time — sub-folders first, then images and videos; hidden files and other types are left out. Backed by GET media/webdav/browse, which runs a PROPFIND Depth: 1 server-side. The browser only ever sees paths below the configured root.
  • Import: a new arm in StoreMediaImportRequest turns a picked path into a RemoteFile for the existing ImportRemoteMedia job, limited to images and videos (types). Several selected files become one import each, like the other sources.
  • No thumbnails: files sit behind credentials, so rather than proxy previews the dialog shows type, size and date.

Security

  • Credentials never reach the browser. They travel to the job as a header through MediaImportHeaders, so — like the Google Drive token — they stay out of the queued job, the database and the cache (covered by a test that greps all three).
  • Paths with empty, . or .. segments, backslashes or control characters are rejected before any request is made, so nothing can climb out of the root.
  • Downloads are limited to the configured share host and still go through SafeHttpFetcher. A share on a private network needs TRYPOST_ALLOW_PRIVATE_NETWORK, documented in .env.example.
  • Listing doesn't follow redirects, and an answer that isn't a DAV multistatus (a login page, say) is an error rather than an empty folder.

Configuration

Off by default:

WEBDAV_ENABLED=true
WEBDAV_URL=https://cloud.example.com/remote.php/dav/files/<user>
WEBDAV_USERNAME=
WEBDAV_PASSWORD=          # e.g. a Nextcloud app password for a read-only account
WEBDAV_ROOT=Shared Media  # optional: limit to one folder
WEBDAV_LABEL=Nextcloud    # name shown in the menu

Plus a per-user rate limit for listings (WEBDAV_REQUESTS_PER_MINUTE, default 60).

Checks

  • 31 new tests (tests/Feature/Media/WebdavMediaSourceTest.php): menu and label, disabled/incomplete config, listing order and filtering, request method/auth/encoding, path traversal, upstream failures (500, 401, redirect, non-XML), entries outside the root, the import download, a document refused by type, and credential hygiene.
  • Media, composer, jobs, unit and localization-parity suites green; strings added for all 17 locales.
  • Pint, vue-tsc, ESLint clean; Prettier clean on the new component (the existing menu file was left as is).
  • Field-tested against a real Nextcloud: browsing a folder of ~60 photos and importing through the guarded fetcher.

Docs: trypostit/trypost-docs#33.

🤖 Generated with Claude Code

obelix58143 and others added 5 commits October 15, 2026 23:17
Adds WebDAV (Nextcloud, ownCloud, any WebDAV server) as a picker source
in the 2.0 media source menu, next to Google Drive, Google Photos, Canva
and Unsplash.

- Browsing: a file browser dialog lists one folder at a time (sub-folders
  first, then images and videos; hidden and other files are left out) via
  GET media/webdav/browse. The listing is fetched server-side with PROPFIND
  Depth: 1; the browser only ever sees paths below the configured root.
- Importing: a new arm in StoreMediaImportRequest turns a picked path into
  a RemoteFile for the existing ImportRemoteMedia job. The share
  credentials travel as a header through MediaImportHeaders, so they stay
  out of the queued job, the database and the cache - same as the Google
  Drive token.
- Safety: paths with empty, "." or ".." segments, backslashes or control
  characters are rejected before any request; downloads are limited to the
  configured share host and still go through SafeHttpFetcher (a share on a
  private network needs TRYPOST_ALLOW_PRIVATE_NETWORK); redirects are not
  followed when listing; a non-multistatus answer (e.g. a login page) is an
  error, not an empty folder.
- Configuration: WEBDAV_ENABLED (off by default), WEBDAV_URL,
  WEBDAV_USERNAME, WEBDAV_PASSWORD, WEBDAV_ROOT, WEBDAV_LABEL, plus a
  per-user rate limit for listings.
- No thumbnails: files are behind credentials, so the dialog shows a list
  with type, size and date instead of proxying previews.

Translations for all 16 locales. Tests cover the menu, disabled and
incomplete configuration, listing order and filtering, request shape and
encoding, path traversal, upstream failures, entries outside the root, the
import download and that the password never reaches response, job,
tables or cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rce-v2

# Conflicts:
#	app/Enums/Media/Source.php
#	app/Providers/AppServiceProvider.php
#	resources/js/components/posts/composer/MediaSourceMenu.vue
#	resources/js/types/index.d.ts
#	resources/js/types/media.ts
#	routes/app.php
#	tests/Unit/Enums/Media/SourceTest.php
Indonesian arrived with trypostit#501 after this branch last synced; it now carries
the same six WebDAV strings as every other locale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since trypostit#514 every import arm names the media types its pick may be, and the
WebDAV arm had none, so importing from the share failed with a 500. The
browser only lists images and videos, so those are the two types: a document
on the share is refused even when its path is posted by hand (new test).

Also puts the blank line back between the WebDAV block and the host
overrides in both env examples.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@obelix58143

Copy link
Copy Markdown
Author

Updated for 2.1.0 — merged current main (v2.1.0 + #523–#525), no force-push.

What changed:

Checks on this head:

  • Full Pest suite: 11,616 passed, 1 failed — BillingControllerTest › an amount discount is formatted…, which fails the same way on plain main in this environment; unrelated.
  • Pint clean on every PHP file the PR touches, vue-tsc --noEmit clean, vite build OK, Prettier and ESLint clean on the new component.
  • Field-tested again on a self-hosted 2.1.0 instance against a real Nextcloud: listing and an authenticated download, with the download pinned to the share's host.

Docs are up as trypostit/trypost-docs#33 (replaces the closed #25).

This branch has not been deployed

No deployments
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