fix(premiere-uxp): preserve remote cloud storage presigned URLs in asset resolution (#408)

- Stop rewriting absolute URLs in resolveAssetUrl to prevent overwriting cloud storage hosts (e.g. Cloudflare R2, S3) with the plugin endpoint
- Prepend endpoint to relative paths only (e.g. /files/..., /api/...)
- Resolve download URLs through resolveAssetUrl before fetch in importAssetIntoPremiere
- Update unit tests to ensure absolute URLs remain intact and relative download paths resolve correctly
- Rebuild and package shumai-premiere.ccx
This commit is contained in:
Yiling-J
2026-09-17 16:37:11 +08:00
committed by GitHub
parent 1796de8eda
commit 12f99797d2
5 changed files with 82 additions and 36 deletions
+12 -10
View File
@@ -22,22 +22,24 @@ describe('resolveAssetUrl', () => {
)
})
it('rewrites host when server presigned with localhost but client connected via 127.0.0.1', () => {
const raw = 'http://localhost:3000/files/shumai/files/cat.webp'
it('preserves absolute URLs intact even when hosts differ', () => {
const localRaw = 'http://localhost:3000/files/shumai/files/cat.webp'
const endpoint = 'http://127.0.0.1:3000'
expect(resolveAssetUrl(raw, endpoint)).toBe('http://127.0.0.1:3000/files/shumai/files/cat.webp')
})
expect(resolveAssetUrl(localRaw, endpoint)).toBe(localRaw)
it('rewrites host and protocol when client connected via remote HTTPS server', () => {
const raw = 'http://localhost:3000/files/shumai/files/cat.webp'
const endpoint = 'https://shumai.example.com'
expect(resolveAssetUrl(raw, endpoint)).toBe(
'https://shumai.example.com/files/shumai/files/cat.webp',
)
const remoteEndpoint = 'https://shumai.example.com'
expect(resolveAssetUrl(localRaw, remoteEndpoint)).toBe(localRaw)
})
it('keeps matching absolute URLs intact', () => {
const raw = 'http://localhost:3000/files/shumai/cat.png'
expect(resolveAssetUrl(raw, 'http://localhost:3000')).toBe(raw)
})
it('preserves remote cloud storage presigned URLs without rewriting host', () => {
const r2Url =
'https://04e37a3c563610bccea6a3ce6f8618ca.r2.cloudflarestorage.com/shumai/files/01KYKNT8NEJ3Q1G6A6K08M2XHC/Float%2002-480p.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Signature=8112ab30'
const endpoint = 'https://staging.shumai.one'
expect(resolveAssetUrl(r2Url, endpoint)).toBe(r2Url)
})
})
+6 -25
View File
@@ -7,9 +7,8 @@
* the user-configured Shumai endpoint.
*
* Handles:
* 1. Relative paths (/files/..., /api/...)
* 2. Host/Port mismatch when the backend defaulted S3 URL to localhost:3000
* while the client connected via 127.0.0.1 or a remote IP/domain.
* - Relative paths (/files/..., /api/...) by prepending the endpoint.
* - Absolute URLs (http://, https://) are preserved as-is.
*/
export function resolveAssetUrl(url?: string | null, endpoint?: string): string | undefined {
if (!url) return undefined
@@ -17,28 +16,10 @@ export function resolveAssetUrl(url?: string | null, endpoint?: string): string
const cleanEndpoint = endpoint.replace(/\/+$/, '')
let resolved = url
// Handle relative URLs
if (url.startsWith('/')) {
resolved = `${cleanEndpoint}${url}`
} else {
// Handle absolute URLs with host mismatch
try {
const parsedUrl = new URL(url)
const parsedEndpoint = new URL(cleanEndpoint)
// If host differs (e.g. localhost vs 127.0.0.1 or remote server address)
if (parsedUrl.host !== parsedEndpoint.host) {
parsedUrl.protocol = parsedEndpoint.protocol
parsedUrl.hostname = parsedEndpoint.hostname
parsedUrl.port = parsedEndpoint.port
resolved = parsedUrl.toString()
}
} catch {
// If URL parsing fails, fallback to raw url
}
// Handle relative URLs (e.g. /files/..., /api/...)
if (url.startsWith('/') && !url.startsWith('//')) {
return `${cleanEndpoint}${url}`
}
return resolved
return url
}