Skip to content

Conversation

@bpollman
Copy link
Contributor

@bpollman bpollman commented Oct 11, 2024

🔗 Issue Link

Jira or Github issue link, if applicable.

🎯 Goal

To use our own CDN, we need the equivalent of ImageCDN to intercept a given URL and provide a signed URL when dealing with File attachments.

🛠 Implementation

Example of how we are using it to make an async call for a signed URL.

public final class CustomFileCDN: FileCDN {

    static var customCDNURL = "mycustomCDN.com"

    let attachmentService: ChatAttachmentService

    init(attachmentService: ChatAttachmentService) {
        self.attachmentService = attachmentService
    }

    public func adjustedURL(for url: URL, completion: @escaping ((Result<URL, any Error>) -> Void)) {
        Task {
            do {
                let signedUrl = try await signedUrl(for: url)
                completion(.success(signedUrl))

            } catch {
                completion(.failure(error))
            }
        }
    }

    func signedUrl(for url: URL) async throws -> URL {
        guard
            let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
            let host = components.host,
            host.contains(Self.customCDNURL)
        else {
            return url
        }
        return try await self.attachmentService.signedDownloadUrl(url)
    }
}

🧪 Testing

Describe the steps how this change can be tested (or why it can't be tested).

🎨 Changes

Add relevant screenshots or videos showcasing the changes.

☑️ Checklist

  • I have signed the Stream CLA (required)
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Affected documentation updated (docusaurus, tutorial, CMS (task created)

@bpollman bpollman requested a review from a team as a code owner October 11, 2024 02:27
Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

@martinmitrevski martinmitrevski merged commit 9a9e8a1 into GetStream:develop Oct 11, 2024
5 of 9 checks passed
@bpollman bpollman deleted the fileCDN branch October 13, 2024 22:53
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.

2 participants