File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import std.string : stripRight, startsWith;
5
5
import std.conv : to;
6
6
import std.typecons : rebindable, Rebindable;
7
7
8
+ import std.regex ;
9
+
8
10
import desktopfile.paths;
9
11
import mimeapps;
10
12
import mime.database;
@@ -25,20 +27,20 @@ void main(string[] args)
25
27
auto mimeAppsLists = mimeAppsListFiles();
26
28
auto mimeInfoCaches = mimeInfoCacheFiles();
27
29
30
+ auto urlRegex = regex(` ([a-z]+)://.*` );
31
+
28
32
foreach (filePath; files) {
29
33
Rebindable! (const (MimeType)) mimeType;
30
34
string mimeTypeName;
31
- if (filePath.startsWith(" http://" )) {
32
- mimeTypeName = " x-scheme-handler/http" ;
33
- } else if (filePath.startsWith(" https://" )) {
34
- mimeTypeName = " x-scheme-handler/https" ;
35
+ auto matchResult = matchFirst(filePath, urlRegex);
36
+ if (! matchResult.empty) {
37
+ mimeTypeName = " x-scheme-handler/" ~ matchResult[1 ];
35
38
} else {
36
39
mimeType = mimeDatabase.mimeTypeForFile(filePath, match);
37
40
if (mimeType) {
38
41
mimeTypeName = mimeType.name;
39
42
}
40
43
}
41
-
42
44
if (mimeTypeName.empty) {
43
45
stderr.writefln(" Could not detect MIME type for %s" , filePath);
44
46
continue ;
You can’t perform that action at this time.
0 commit comments