Getting html report

This commit is contained in:
Selim Mustafaev 2025-08-15 18:09:01 +03:00
parent c02b93dd44
commit e6f29e9a4e
6 changed files with 64 additions and 0 deletions

View File

@ -46,6 +46,7 @@
7A45FB382C27073700618694 /* StorageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A45FB372C27073700618694 /* StorageService.swift */; };
7A4927D52CCE438600851C01 /* OptionalBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A4927D42CCE438600851C01 /* OptionalBinding.swift */; };
7A4955822D58CCF900912E66 /* HistoryFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A4955812D58CCF900912E66 /* HistoryFilter.swift */; };
7A4BB8622E4F5EDC00AB22C9 /* AvtocodResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A4BB8612E4F5EDC00AB22C9 /* AvtocodResponse.swift */; };
7A54BFD32D43B95E00176D6D /* DbUpdatePolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A54BFD22D43B95E00176D6D /* DbUpdatePolicy.swift */; };
7A589E0F2D6B6E8E00EF3FBE /* NumberEditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A589E0E2D6B6E8E00EF3FBE /* NumberEditView.swift */; };
7A5911EE2D63226F00EC51BA /* SearchScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A5911ED2D63226F00EC51BA /* SearchScreen.swift */; };
@ -303,6 +304,7 @@
7A45FB372C27073700618694 /* StorageService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageService.swift; sourceTree = "<group>"; };
7A4927D42CCE438600851C01 /* OptionalBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalBinding.swift; sourceTree = "<group>"; };
7A4955812D58CCF900912E66 /* HistoryFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryFilter.swift; sourceTree = "<group>"; };
7A4BB8612E4F5EDC00AB22C9 /* AvtocodResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvtocodResponse.swift; sourceTree = "<group>"; };
7A52AB292580112E002CD910 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
7A530B7F2401803A00CBFE6E /* Vehicle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Vehicle.swift; sourceTree = "<group>"; };
7A54BFD22D43B95E00176D6D /* DbUpdatePolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DbUpdatePolicy.swift; sourceTree = "<group>"; };
@ -975,6 +977,7 @@
7A599C352C18AC7F00D47C18 /* ApiError.swift */,
7A11474823FF2B2D00B424AF /* Response.swift */,
7AEAA2A02DAD9C00009954F0 /* TokenResponse.swift */,
7A4BB8612E4F5EDC00AB22C9 /* AvtocodResponse.swift */,
);
path = ApiService;
sourceTree = "<group>";
@ -1492,6 +1495,7 @@
7A6F096026DBF588003A965D /* VehicleNote.swift in Sources */,
7AD8572D2DF95F72009E4B72 /* SwiftDataStorageService.swift in Sources */,
7AF6D21E2677C1680086EA64 /* PlateNumber.swift in Sources */,
7A4BB8622E4F5EDC00AB22C9 /* AvtocodResponse.swift in Sources */,
7A5D84C62C1AE72E00C2209B /* VehicleName.swift in Sources */,
7AD8572A2DF87928009E4B72 /* SDAudioRecord.swift in Sources */,
7A64A2122C19E2A100284124 /* VehicleModelDto.swift in Sources */,

View File

@ -252,6 +252,7 @@ public actor ApiService: ApiServiceProtocol {
numberType: VehicleNumberType,
notes: [VehicleNoteDto],
events: [VehicleEventDto],
avtocodReport: String?,
force: Bool = false
) async throws -> VehicleDto {
@ -356,4 +357,37 @@ public actor ApiService: ApiServiceProtocol {
return try await makeBodyRequest(api: "vehicles/checkGbTg", body: body)
}
public func getAvtocodHtml(by number: String, numberType: VehicleNumberType) async throws -> String? {
guard var urlComponents = URLComponents(string: Constants.avtocodBaseURL + "auto/generate") else {
return nil
}
urlComponents.queryItems = [
URLQueryItem(name: "number", value: number.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)),
URLQueryItem(name: "type", value: numberType.value),
URLQueryItem(name: "device_token", value: UUID().uuidString)
]
guard let url = urlComponents.url else {
return nil
}
var request = URLRequest(url: url)
request.addValue(Constants.avtocodUserAgent, forHTTPHeaderField: "User-Agent")
let (data, _) = try await session.data(for: request)
let json = try JSONDecoder().decode(AvtocodResponse.self, from: data)
guard let reportUrl = json.report_uri.flatMap(URL.init(string:)) else {
return nil
}
request = URLRequest(url: reportUrl)
request.addValue(Constants.avtocodUserAgent, forHTTPHeaderField: "User-Agent")
let (reportData, _) = try await session.data(for: request)
let reportBase64 = reportData.base64EncodedString()
return reportBase64
}
}

View File

@ -34,6 +34,7 @@ public protocol ApiServiceProtocol: Sendable {
numberType: VehicleNumberType,
notes: [VehicleNoteDto],
events: [VehicleEventDto],
avtocodReport: String?,
force: Bool
) async throws -> VehicleDto
func checkVehicleGb(by number: String) async throws -> VehicleDto
@ -42,4 +43,5 @@ public protocol ApiServiceProtocol: Sendable {
func fbVerifyAssertion(provider: String, idToken: String, accessToken: String?) async
func getToken(code: String, codeVerifier: String) async throws -> TokenResponse
func getReport(for number: String) async throws -> VehicleDto
func getAvtocodHtml(by number: String, numberType: VehicleNumberType) async throws -> String?
}

View File

@ -0,0 +1,14 @@
//
// AvtocodResponse.swift
// AutoCatCore
//
// Created by Selim Mustafaev on 15.08.2025.
// Copyright © 2025 Selim Mustafaev. All rights reserved.
//
import Foundation
struct AvtocodResponse: Decodable {
let report_uri: String?
}

View File

@ -65,11 +65,18 @@ extension VehicleService: VehicleServiceProtocol {
}
async let locationTask = trackLocation ? locationService.getRecentLocation() : nil
let avtocodReport = try? await apiService.getAvtocodHtml(
by: number,
numberType: numberType
)
async let vehicleTask = apiService.checkVehicle(
by: number,
numberType: numberType,
notes: notes,
events: events,
avtocodReport: avtocodReport,
force: forceUpdate
)

View File

@ -55,4 +55,7 @@ public enum Constants {
public static let audioRecordsFolder = "recordings"
public static let userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 18_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Mobile/15E148 Safari/604.1"
public static let avtocodBaseURL = "https://avtocod.ru/api/v4/"
public static let avtocodUserAgent = "avtocod/3 CFNetwork/3826.600.41 Darwin/24.6.0"
}