HelloZeroNet / HelloZeroNet/ZeroNet
fileQuery: does the implementation match the documentation?
- Vorherrschende Sprache
- JavaScript
- Sterne
- 18.8k
- Forks
- 2.3k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
[The documentation](https://github.com/HelloZeroNet/Documentation/blob/master/docs/site_development/zeroframe_api_reference.md) states:
> ### fileQuery _dir_inner_path, query_
> Simple json file query command
>
> Parameter | Description
> --- | ---
> **dir_inner_path** | Pattern of queried files
> **query** | Query command (optional)
>
> **Return**: Matched content
>
> **Query examples:**
>
> - `["data/users/*/data.json", "topics"]`: Returns all topics node from all user files
> - `["data/users/*/data.json", "comments.1@2"]`: Returns `user_data["comments"]["1@2"]` value from all user files
> - `["data/users/*/data.json", ""]`: Returns all data from users files
> - `["data/users/*/data.json"]`: Returns all data from users files (same as above)
>
> **Example:**
> ```coffeescript
> @cmd "fileQuery", ["data/users/*/data.json", "topics"], (topics) =>
> topics.sort (a, b) -> # Sort by date
> return a.added - b.added
> for topic in topics
> @log topic.topic_id, topic.inner_path, topic.title
> ```
Since there is no definition there, what the "pattern of queried files" is, it is logical to assume that the pattern works similar to the usual wildcard file pattern. So, if one queries "folder/data.json", she should get back exactly 1 result. In fact it is not so:
```
Page.cmd("fileQuery", "data/users/content.json", function(r) {console.log(r.length);})
7
```
The result contains files from the whole `data/users/` subtree.
If the pattern has no `/*/` part, the implementation silently assumes it before the last part of the file path:
```
if "/*/" in path_pattern: # Wildcard search
root_dir, file_pattern = path_pattern.replace("\\", "/").split("/*/")
else: # No wildcard
root_dir, file_pattern = re.match("(.*)/(.*?)$", path_pattern.replace("\\", "/")).groups()
```
Is it actually how it is supposed to work? What is wrong: the documentation or the implementation?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.