Repository: static-web-server/static-web-server (language: rust)

Issue:
JSON directory listing indicates type=directory for empty file entries
**Describe the bug**

JSON listing entry indicates `"type": "directory"` for empty files

**To Reproduce**

```
$ mkdir sws-base-dir && cd $_
$ mkdir -p public/dir1
$ touch public/file1
$ echo "hola" > public/file2
$ static-web-server --directory-listing=true --directory-listing-format=json
```

In other terminal, request `http://localhost/`, for example, via curlie, one gets:

```json
[
    {
        "name": "file2",
        "type": "file",
        "mtime": "2023-10-11T20:07:05Z",
        "size": 5
    },
    {
        "name": "file1",
        "type": "directory",
        "mtime": "2023-10-11T20:06:50Z"
    },
    {
        "name": "dir1",
        "type": "directory",
        "mtime": "2023-10-11T20:06:38Z"
    }
]
```

**Expected behavior**

The entry indicates `"type": "file"` for empty file, eg the "file1" above.

**Environment and Specs**
 - static-web-server: v2.22.1


(btw, SWS is awesome!)
JSON directory listing indicates type=directory for empty file entries
**Describe the bug**

JSON listing entry indicates `"type": "directory"` for empty files

**To Reproduce**

```
$ mkdir sws-base-dir && cd $_
$ mkdir -p public/dir1
$ touch public/file1
$ echo "hola" > public/file2
$ static-web-server --directory-listing=true --directory-listing-format=json
```

In other terminal, request `http://localhost/`, for example, via curlie, one gets:

```json
[
    {
        "name": "file2",
        "type": "file",
        "mtime": "2023-10-11T20:07:05Z",
        "size": 5
    },
    {
        "name": "file1",
        "type": "directory",
        "mtime": "2023-10-11T20:06:50Z"
    },
    {
        "name": "dir1",
        "type": "directory",
        "mtime": "2023-10-11T20:06:38Z"
    }
]
```

**Expected behavior**

The entry indicates `"type": "file"` for empty file, eg the "file1" above.

**Environment and Specs**
 - static-web-server: v2.22.1


(btw, SWS is awesome!)


Discussion / hints:

Fix patch:
diff --git a/src/directory_listing.rs b/src/directory_listing.rs
index d6b81bf6..9d0a235a 100644
--- a/src/directory_listing.rs
+++ b/src/directory_listing.rs
@@ -131,6 +131,7 @@ struct FileEntry {
     name_encoded: String,
     modified: Option<DateTime<Local>>,
     filesize: u64,
+    is_dir: bool,
     uri: Option<String>,
 }
 
@@ -286,11 +287,14 @@ async fn read_dir_entries(
                 None
             }
         };
+        let is_dir = meta.is_dir();
+
         file_entries.push(FileEntry {
             name,
             name_encoded,
             modified,
             filesize,
+            is_dir,
             uri,
         });
     }
@@ -364,8 +368,7 @@ fn json_auto_index(entries: &mut [FileEntry], order_code: u8) -> Result<String>
     for entry in entries {
         let file_size = &entry.filesize;
         let file_name = &entry.name;
-        let is_empty = *file_size == 0_u64;
-        let file_type = if is_empty { "directory" } else { "file" };
+        let file_type = if entry.is_dir { "directory" } else { "file" };
         let file_modified = &entry.modified;
 
         json.push('{');
@@ -380,7 +383,7 @@ fn json_auto_index(entries: &mut [FileEntry], order_code: u8) -> Result<String>
         });
         json.push_str(format!("\"mtime\":\"{file_modified_str}\"").as_str());
 
-        if !is_empty {
+        if !entry.is_dir {
             json.push_str(format!(",\"size\":{file_size}").as_str());
         }
         json.push_str("},");


Test patch: