HelloZeroNet / HelloZeroNet/ZeroNet

fileQuery: does the implementation match the documentation?

Abierto
#1,689 3 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
18.8k
Forks
2.3k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

[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?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.