2024-09-23 13:02:26 +00:00
|
|
|
//
|
2024-10-04 07:58:42 +00:00
|
|
|
// Issue+Metadata.swift
|
2024-09-23 13:02:26 +00:00
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 9/18/24.
|
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CommonLibrary
|
|
|
|
import Foundation
|
|
|
|
import PassepartoutKit
|
|
|
|
|
|
|
|
extension Issue {
|
2024-10-04 07:58:42 +00:00
|
|
|
struct Metadata {
|
2024-10-23 15:32:49 +00:00
|
|
|
let profile: Profile?
|
|
|
|
|
2024-10-25 09:38:27 +00:00
|
|
|
let provider: (ProviderID, Date?)?
|
|
|
|
|
2024-10-04 07:58:42 +00:00
|
|
|
let configuration: PassepartoutConfiguration
|
2024-10-01 13:45:25 +00:00
|
|
|
|
2024-10-04 07:58:42 +00:00
|
|
|
let versionString: String
|
|
|
|
|
|
|
|
let purchasedProducts: Set<AppProduct>
|
|
|
|
|
2024-11-01 08:47:50 +00:00
|
|
|
let tunnel: ExtendedTunnel
|
2024-10-04 07:58:42 +00:00
|
|
|
|
|
|
|
let urlForTunnelLog: URL
|
|
|
|
|
|
|
|
let parameters: Constants.Log
|
|
|
|
}
|
|
|
|
|
|
|
|
static func withMetadata(_ metadata: Metadata) async -> Issue {
|
|
|
|
let appLog = metadata.configuration.currentLog(parameters: metadata.parameters)
|
2024-09-23 13:02:26 +00:00
|
|
|
.joined(separator: "\n")
|
|
|
|
.data(using: .utf8)
|
|
|
|
|
|
|
|
let tunnelLog: Data?
|
|
|
|
|
|
|
|
// live tunnel log
|
2024-10-04 07:58:42 +00:00
|
|
|
if await metadata.tunnel.status != .inactive {
|
|
|
|
tunnelLog = await metadata.tunnel.currentLog(parameters: metadata.parameters)
|
2024-09-23 13:02:26 +00:00
|
|
|
.joined(separator: "\n")
|
|
|
|
.data(using: .utf8)
|
|
|
|
}
|
|
|
|
// latest persisted tunnel log
|
2024-10-04 07:58:42 +00:00
|
|
|
else if let latestTunnelEntry = metadata.configuration.availableLogs(at: metadata.urlForTunnelLog)
|
2024-09-23 13:02:26 +00:00
|
|
|
.max(by: { $0.key < $1.key }) {
|
|
|
|
|
|
|
|
tunnelLog = try? Data(contentsOf: latestTunnelEntry.value)
|
|
|
|
}
|
|
|
|
// nothing
|
|
|
|
else {
|
|
|
|
tunnelLog = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return Issue(
|
2024-10-04 07:58:42 +00:00
|
|
|
appLine: "\(Strings.Unlocalized.appName) \(metadata.versionString)",
|
|
|
|
purchasedProducts: metadata.purchasedProducts,
|
2024-09-23 13:02:26 +00:00
|
|
|
appLog: appLog,
|
2024-10-23 15:32:49 +00:00
|
|
|
tunnelLog: tunnelLog,
|
2024-10-25 09:38:27 +00:00
|
|
|
provider: metadata.provider
|
2024-09-23 13:02:26 +00:00
|
|
|
)
|
|
|
|
}
|
2024-10-04 07:58:42 +00:00
|
|
|
}
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-10-04 07:58:42 +00:00
|
|
|
extension Issue {
|
2024-09-23 13:02:26 +00:00
|
|
|
var to: String {
|
|
|
|
Constants.shared.emails.issues
|
|
|
|
}
|
|
|
|
|
|
|
|
var subject: String {
|
|
|
|
Strings.Unlocalized.Issues.subject
|
|
|
|
}
|
|
|
|
}
|