Skip to content

Commit

Permalink
add new check to url conversion to avoid double conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Feb 15, 2024
1 parent 275928f commit 8d6869c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/KukaiCoreSwift/Services/MediaProxyService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public class MediaProxyService: NSObject {
return nil
}

// To simplify calling logic, check if its already been converted and return previous url
if uri.absoluteString.prefix(25) == "https://data.mantodev.com" {
return uri
}

let sanitizedURL = strippedURL.replacingOccurrences(of: "www.", with: "")
var source = Source.ipfs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class MediaProxySerivceTests: XCTestCase {

XCTAssert(url10?.absoluteString == "https://data.mantodev.com/media/mobile600/ipfs/bafybeiatpitaej7bynhsequ5hl45jbtjft2nkkho74jfocvnw4vrqlhdea", url10?.absoluteString ?? "-")
XCTAssert(url11?.absoluteString == "https://data.mantodev.com/media/mobile900/ipfs/bafybeiatpitaej7bynhsequ5hl45jbtjft2nkkho74jfocvnw4vrqlhdea", url11?.absoluteString ?? "-")

let alreadyConverted = URL(string: "https://data.mantodev.com/media/mobile64/ipfs/bafybeiatpitaej7bynhsequ5hl45jbtjft2nkkho74jfocvnw4vrqlhdea")
let testConversion = MediaProxyService.url(fromUri: alreadyConverted, ofFormat: .mobile64)
XCTAssert(testConversion?.absoluteString == "https://data.mantodev.com/media/mobile64/ipfs/bafybeiatpitaej7bynhsequ5hl45jbtjft2nkkho74jfocvnw4vrqlhdea", testConversion?.absoluteString ?? "-")
}

func testMediaTypeCheckerFromFormat() {
Expand Down

0 comments on commit 8d6869c

Please sign in to comment.