Skip to content

Commit 8ab9adb

Browse files
Merge pull request #219 from nextcloud/resolver
Resolver
2 parents c32b0b3 + 884cd7d commit 8ab9adb

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

Sources/NextcloudKit/TypeIdentifiers/NKFilePropertyResolver.swift

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,60 @@ public final class NKFilePropertyResolver {
5353
) -> NKFileProperty {
5454

5555
let fileProperty = NKFileProperty()
56+
let normalizedFileExtension = fileExtension.lowercased()
57+
fileProperty.ext = fileExtension
5658

5759
// MARK: - Custom MIME types
5860

5961
switch mimeType {
6062

63+
case "text/markdown", "text/x-markdown":
64+
fileProperty.classFile = .document
65+
fileProperty.iconName = .txt
66+
fileProperty.name = "text"
67+
fileProperty.ext = fileExtension.isEmpty ? "md" : fileExtension
68+
return fileProperty
69+
6170
case "application/vnd.excalidraw+json":
6271
fileProperty.classFile = .document
6372
fileProperty.iconName = .draw
6473
fileProperty.name = "whiteboard"
65-
fileProperty.ext = "whiteboard"
74+
return fileProperty
75+
76+
default:
77+
break
78+
}
79+
80+
// MARK: - Custom file extensions
81+
82+
switch normalizedFileExtension {
83+
84+
case "md", "markdown":
85+
fileProperty.classFile = .document
86+
fileProperty.iconName = .txt
87+
fileProperty.name = "text"
88+
fileProperty.ext = fileExtension.isEmpty ? "md" : fileExtension
89+
return fileProperty
90+
91+
case "txt", "text", "log", "csv", "tsv":
92+
fileProperty.classFile = .document
93+
fileProperty.iconName = .txt
94+
fileProperty.name = "text"
95+
return fileProperty
96+
97+
case "swift", "m", "mm", "h", "c", "cpp", "hpp",
98+
"java", "kt", "js", "ts", "html", "css",
99+
"xml", "json", "yaml", "yml", "php", "py",
100+
"rb", "go", "rs", "sh", "sql":
101+
fileProperty.classFile = .document
102+
fileProperty.iconName = .txt
103+
fileProperty.name = "text"
104+
return fileProperty
105+
106+
case "whiteboard":
107+
fileProperty.classFile = .document
108+
fileProperty.iconName = .draw
109+
fileProperty.name = "whiteboard"
66110
return fileProperty
67111

68112
default:

0 commit comments

Comments
 (0)