field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

TeraRemoteQualificationMediaPicker.swift (1971B)


      1 import Foundation
      2 import RadrootsKit
      3 
      4 #if DEBUG
      5   actor TeraRemoteQualificationMediaPicker: RadrootsMediaPicker {
      6     private let roots: RadrootsAppleFileRoots
      7     private let file: RadrootsFileReference
      8 
      9     init(roots: RadrootsAppleFileRoots, file: RadrootsFileReference) {
     10       self.roots = roots
     11       self.file = file
     12     }
     13 
     14     func currentSupport() async throws -> RadrootsMediaPickerSupport {
     15       try RadrootsMediaPickerSupport(
     16         importAvailable: true,
     17         cameraCaptureAvailable: false,
     18         supportedImportKinds: [.image],
     19         supportedCaptureKinds: [],
     20         multipleSelectionSupported: false
     21       )
     22     }
     23 
     24     func importMedia(
     25       _ request: RadrootsMediaImportRequest
     26     ) async throws -> RadrootsMediaImportResult {
     27       guard request.allowedMediaKinds == [.image], request.selectionLimit >= 1 else {
     28         throw RadrootsCaptureIntakeError.invalidRequest
     29       }
     30       try RadrootsAppleFileAccess(roots: roots).write(
     31         .inline(TeraRemoteQualificationEnvironment.mediaFixtureData()),
     32         to: file
     33       )
     34       let url = try roots.resolvedURL(for: file)
     35       let values = try url.resourceValues(
     36         forKeys: [.fileSizeKey, .isRegularFileKey, .isSymbolicLinkKey]
     37       )
     38       guard values.isRegularFile == true,
     39         values.isSymbolicLink != true,
     40         let size = values.fileSize,
     41         (1 ... 40 * 1024 * 1024).contains(size)
     42       else {
     43         throw RadrootsCaptureIntakeError.unavailable
     44       }
     45       let asset = try RadrootsMediaAsset(
     46         source: .libraryImport,
     47         kind: .image,
     48         file: file,
     49         mediaType: "image/png",
     50         suggestedFilename: "input.png",
     51         sizeBytes: UInt64(size),
     52         capturedAt: Date()
     53       )
     54       return try RadrootsMediaImportResult(items: [asset])
     55     }
     56 
     57     func captureMedia(
     58       _: RadrootsMediaCaptureRequest
     59     ) async throws -> RadrootsMediaCaptureResult {
     60       throw RadrootsCaptureIntakeError.unavailable
     61     }
     62   }
     63 #endif