HelloZeroNet / HelloZeroNet/ZeroNet
fileQuery: does the implementation match the documentation?
- 主要语言
- JavaScript
- 星标
- 18.8k
- 派生
- 2.3k
- PR 合并指标
- 30 天内没有已合并 PR
描述
[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?
贡献指南
这个仓库没有索引到贡献指南
调研方向
阅读 docs/site_development/zeroframe_api_reference.md,并将其中的 fileQuery 示例与 issue 中展示的实现逻辑进行比较。重现 Page.cmd("fileQuery", "data/users/content.json", ...) 这一情况,然后确定是文档中的模式还是实现定义了预期行为。文档与行为一致、差异已解决,并且由适当的测试覆盖时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, python
- 领域
- api, documentation
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 35/100