Skip to content

Commit

Permalink
feat: prepupload extension (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
JNdhlovu authored Aug 28, 2024
1 parent 2edcfe9 commit 86ad3e6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release Notes

## 10.2.8

### Changed
* Smartselfie captures now return relative file urls as the rest of the products

### Added
* Zip files from prepupload request

## 10.2.7

### Changed
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PODS:
- Sentry (8.32.0):
- Sentry/Core (= 8.32.0)
- Sentry/Core (8.32.0)
- SmileID (10.2.7):
- SmileID (10.2.8):
- lottie-ios (~> 4.4.2)
- ZIPFoundation (~> 0.9)
- SwiftLint (0.55.1)
Expand Down Expand Up @@ -43,7 +43,7 @@ SPEC CHECKSUMS:
lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418
netfox: 9d5cc727fe7576c4c7688a2504618a156b7d44b7
Sentry: 96ae1dcdf01a644bc3a3b1dc279cecaf48a833fb
SmileID: 500429946fbb916221450c9f792fa94ee1060955
SmileID: 8d3a64e845a5fb82239516def978391d4d814c9e
SwiftLint: 3fe909719babe5537c552ee8181c0031392be933
ZIPFoundation: b8c29ea7ae353b309bc810586181fd073cb3312c

Expand Down
2 changes: 1 addition & 1 deletion SmileID.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SmileID'
s.version = '10.2.7'
s.version = '10.2.8'
s.summary = 'The Official Smile Identity iOS SDK.'
s.homepage = 'https://docs.usesmileid.com/integration-options/mobile/ios-v10-beta'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
49 changes: 48 additions & 1 deletion Sources/SmileID/Classes/Helpers/LocalStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public class LocalStorage {
let data = try Data(contentsOf: authenticationrequest!)
return try jsonDecoder.decode(AuthenticationRequest.self, from: data)
}

static func saveOfflineJob(
jobId: String,
userId: String,
Expand Down Expand Up @@ -292,6 +292,46 @@ public class LocalStorage {
}
}

public static func toZip(uploadRequest: UploadRequest) throws -> Data {
var destinationFolder: String?
// Extract directory paths from all images and check for consistency
for imageInfo in uploadRequest.images {
let folder = extractDirectoryPath(from: imageInfo.fileName)
if let existingDestinationFolder = destinationFolder {
if folder != existingDestinationFolder {
throw SmileIDError.fileNotFound("Job not found")
}
} else {
destinationFolder = folder
}
}

// Ensure a destination folder was found
guard let finalDestinationFolder = destinationFolder else {
throw SmileIDError.fileNotFound("Job not found")
}

// Get the URL for the JSON file
let jsonUrl = try LocalStorage.getInfoJsonFile(jobId: finalDestinationFolder)

// Create full URLs for all images
let imageUrls = uploadRequest.images.map { imageInfo in
URL(fileURLWithPath: finalDestinationFolder).appendingPathComponent(imageInfo.fileName)
}

var allUrls = imageUrls

do {
let jsonUrl = try LocalStorage.getInfoJsonFile(jobId: finalDestinationFolder)
allUrls.append(jsonUrl)
} catch {
debugPrint("Warning: info.json file not found. Continuing without it.")
}

// Zip all files
return try zipFiles(at: allUrls)
}

public static func zipFiles(at urls: [URL]) throws -> Data {
let archive = try Archive(accessMode: .create)
for url in urls {
Expand All @@ -300,6 +340,13 @@ public class LocalStorage {
return archive.data!
}

private static func extractDirectoryPath(from path: String) -> String? {
let url = URL(fileURLWithPath: path)
// Remove the last component and add a trailing slash
let directoryPath = url.deletingLastPathComponent().path + "/"
return directoryPath
}

private static func delete(at url: URL) throws {
if fileManager.fileExists(atPath: url.relativePath) {
try fileManager.removeItem(atPath: url.relativePath)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmileID/Classes/SmileID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI
import UIKit

public class SmileID {
public static let version = "10.2.7"
public static let version = "10.2.8"
@Injected var injectedApi: SmileIDServiceable
public static var configuration: Config { config }

Expand Down

0 comments on commit 86ad3e6

Please sign in to comment.