Skip to content

Fall back to room-less file URL format when parsing open group download URLs#94

Open
mpretty-cyro wants to merge 1 commit into
session-foundation:devfrom
mpretty-cyro:fix/community-filr-url-parsing
Open

Fall back to room-less file URL format when parsing open group download URLs#94
mpretty-cyro wants to merge 1 commit into
session-foundation:devfrom
mpretty-cyro:fix/community-filr-url-parsing

Conversation

@mpretty-cyro

Copy link
Copy Markdown
Collaborator

No description provided.

@mpretty-cyro mpretty-cyro self-assigned this Jul 21, 2026
@mpretty-cyro
mpretty-cyro requested a review from jagerman July 21, 2026 07:07

@jagerman jagerman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code seems fine, but I'm a little bit confused how this can actually work: do clients have to throw away most of the URL but keep the ID and then reconstruct the URL to actually download a file? As far as I know, sogs always requires the /room/NAME/file/N URL to get a room attachment.

@mpretty-cyro

Copy link
Copy Markdown
Collaborator Author

Yep pretty much, below are the Android and Desktop versions - they grab the last part of the url to get the fileId and then reconstruct the SOGS endpoint with that id so it doesn't actually matter what the downloadUrl is.

In the last major iOS release before we shut down I updated iOS to use open_group_server::parse_download_url which deconstructed the url into a structured object, but required it to be in the correct structure which, combined with the incorrect structure Android was generating (Fix), resulted in iOS failing to download community attachments sent from Android.

This change is to add support for the incorrect URL (so a future universal client is able to download images sent by the broken Android versions), and an update to iOS which has a similar fallback to extract the last part of the url if libSession fails to parse it.

Android:

val url = attachment.url.toHttpUrlOrNull()!!
val fileID = url.pathSegments.last()

communityApiExecutor.execute(
    CommunityApiRequest(
        serverBaseUrl = threadRecipient.address.serverUrl,
        api = communityFileDownloadApiFactory.create(
            room = threadRecipient.address.room,
            fileId = fileID,
            requiresSigning = true,
        )
    )
).toByteArraySlice()

Desktop:

export function attachmentIdAsStrFromUrl(fullUrl: string) {
  const url = new URL(fullUrl);
  const lastSegment = extractLastPathSegment(url);
  if (!lastSegment) {
    throw new Error('attachmentIdAsStrFromUrl last segment is not valid');
  }
  return lastSegment;
}

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