Skip to content

Commit

Permalink
No longer base64 encode customMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
quanganhdo committed Oct 15, 2024
1 parent 39a9251 commit a28a854
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
11 changes: 11 additions & 0 deletions DuckDuckGo/Feedback/VPNMetadataCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ struct VPNMetadata: Encodable {

return String(data: encodedMetadata, encoding: .utf8)
}

func toBase64() -> String {
let encoder = JSONEncoder()

do {
let encodedMetadata = try encoder.encode(self)
return encodedMetadata.base64EncodedString()
} catch {
return "Failed to encode metadata to JSON, error message: \(error.localizedDescription)"
}
}
}

protocol VPNMetadataCollector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct DefaultFeedbackSender: UnifiedFeedbackSender {
category: Category.from(category),
subcategory: Subcategory.from(subcategory),
description: description,
metadata: metadata?.toBase64() ?? ""),
metadata: metadata?.toString() ?? ""),
frequency: .regular)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ protocol UnifiedMetadataCollector {
}

protocol UnifiedFeedbackMetadata: Encodable {
func toBase64() -> String
func toString() -> String
}

extension UnifiedFeedbackMetadata {
func toBase64() -> String {
func toString() -> String {
let encoder = JSONEncoder()

do {
let encodedMetadata = try encoder.encode(self)
return encodedMetadata.base64EncodedString()
return String(data: encodedMetadata, encoding: .utf8) ?? ""
} catch {
return "Failed to encode metadata to JSON, error message: \(error.localizedDescription)"
return "Failed to encode metadata to JSON string, error message: \(error.localizedDescription)"
}
}
}

0 comments on commit a28a854

Please sign in to comment.