Skip to content

Commit b89a0b7

Browse files
committed
refactor: Move format bytes to utils
1 parent f0b848c commit b89a0b7

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

FileBrowserClient/FileBrowserClient/FileListView.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,6 @@ struct FileListView: View {
467467
fileCacheSize = FileCache.shared.diskCacheSize()
468468
}
469469

470-
func formatBytes(_ bytes: Int64) -> String {
471-
let formatter = ByteCountFormatter()
472-
formatter.allowedUnits = [.useTB, .useGB, .useMB, .useKB]
473-
formatter.countStyle = .file
474-
return formatter.string(fromByteCount: bytes)
475-
}
476-
477470
func fetchUsageInfo() {
478471
guard let serverURL = auth.serverURL, let token = auth.token,
479472
let url = URL(string: "\(serverURL)/api/usage/") else {
@@ -869,10 +862,6 @@ struct FileListView: View {
869862
}
870863
}
871864

872-
func encodedPath(_ path: String, allowed: CharacterSet = .urlPathAllowed) -> String? {
873-
return path.addingPercentEncoding(withAllowedCharacters: allowed)
874-
}
875-
876865
func renameSelectedItem() {
877866
guard let item = selectedItems.first else { return }
878867
let fromPath = item.path
@@ -936,7 +925,7 @@ struct FileListView: View {
936925
)
937926
let fullPath = self.fullPath(for: fileItem)
938927

939-
guard let encodedPath = encodedPath(fullPath) else {
928+
guard let encodedPath = fullPath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
940929
Log.error("❌ Failed to encode path")
941930
viewModel.errorMessage = "Failed to encode path"
942931
return

FileBrowserClient/FileBrowserClient/Utils.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ func sizeConverter(_ byteSize: Int?) -> String {
2828
return String(format: "%.2f %@", size, sizeNames[index])
2929
}
3030

31+
func formatBytes(_ bytes: Int64) -> String {
32+
let formatter = ByteCountFormatter()
33+
formatter.allowedUnits = [.useTB, .useGB, .useMB, .useKB]
34+
formatter.countStyle = .file
35+
return formatter.string(fromByteCount: bytes)
36+
}
37+
3138
func timeAgoString(from diff: [String: Double]) -> String {
3239
let seconds = Int(diff["seconds"] ?? 0)
3340
let minutes = Int(diff["minutes"] ?? 0)

0 commit comments

Comments
 (0)