Repository: syncthing/syncthing (language: go)

Issue:
The browse API response has changed as of Syncthing v1.29.0
### What happened?

When querying the "browse" REST API (e.g. `curl -X GET -H 'Authorization: Bearer …' 'http://localhost:8080/rest/db/browse?folder=music'`) Syncthing returns the type of the items as an integer (e.g. `"type": 1`) as of v1.29.0. Before it returned the type as a string (e.g. `"type": "FILE_INFO_TYPE_DIRECTORY"`). The latter is still documented and I suspect the change is unintended. As there was refactoring done it probably is a side-effect of that.

I suppose the old behavior should be restored or the documentation should be updated.

(Note that I don't care about the way the type is returned. I only stumbled across this as it broke the file browser in Syncthing Tray. If integers are more convenient to work with then I'm fine with that. It wasn't hard at all to figure out that the "magic" numbers correspond to entries in `enum FileInfoType` (in `syncthing/proto/bep/bep.proto`) although this should then probably be mentioned in the documentation.)

### Syncthing version

v1.29.0

### Platform & operating system

all

### Browser version

_No response_

### Relevant log output

_No response_


Discussion / hints:
I'd favor fixing the API to bring back the old behavior.  Such things shouldn't change needlessly and since we have public documentation about it, we should assume someone might depend on the details.
Yep should be string for sure. 

Fix patch:
diff --git a/lib/model/model.go b/lib/model/model.go
index deef90c3a94..9e898395d0b 100644
--- a/lib/model/model.go
+++ b/lib/model/model.go
@@ -2732,11 +2732,11 @@ func (m *model) Revert(folder string) {
 }
 
 type TreeEntry struct {
-	Name     string                `json:"name"`
-	ModTime  time.Time             `json:"modTime"`
-	Size     int64                 `json:"size"`
-	Type     protocol.FileInfoType `json:"type"`
-	Children []*TreeEntry          `json:"children,omitempty"`
+	Name     string       `json:"name"`
+	ModTime  time.Time    `json:"modTime"`
+	Size     int64        `json:"size"`
+	Type     string       `json:"type"`
+	Children []*TreeEntry `json:"children,omitempty"`
 }
 
 func findByName(slice []*TreeEntry, name string) *TreeEntry {
@@ -2804,7 +2804,7 @@ func (m *model) GlobalDirectoryTree(folder, prefix string, levels int, dirsOnly
 
 		parent.Children = append(parent.Children, &TreeEntry{
 			Name:    base,
-			Type:    f.Type,
+			Type:    f.Type.String(),
 			ModTime: f.ModTime(),
 			Size:    f.FileSize(),
 		})


Test patch:
diff --git a/lib/model/model_test.go b/lib/model/model_test.go
index 4935bf1634c..1c79f0e1e16 100644
--- a/lib/model/model_test.go
+++ b/lib/model/model_test.go
@@ -1729,7 +1729,7 @@ func TestGlobalDirectoryTree(t *testing.T) {
 			Name:    name,
 			ModTime: time.Unix(0x666, 0),
 			Size:    0xa,
-			Type:    protocol.FileInfoTypeFile,
+			Type:    protocol.FileInfoTypeFile.String(),
 		}
 	}
 	d := func(name string, entries ...*TreeEntry) *TreeEntry {
@@ -1737,7 +1737,7 @@ func TestGlobalDirectoryTree(t *testing.T) {
 			Name:     name,
 			ModTime:  time.Unix(0x666, 0),
 			Size:     128,
-			Type:     protocol.FileInfoTypeDirectory,
+			Type:     protocol.FileInfoTypeDirectory.String(),
 			Children: entries,
 		}
 	}