Skip to content

Commit

Permalink
Show json instead of sending it as ogg audio
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Nov 7, 2023
1 parent ecdeb25 commit 1327a84
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion contrib/data/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,13 @@ <h2>File Viewer</h2>
</React.Fragment >
) : (
<React.Fragment>
<a href={`/content${this.state.path}${file.name}?special=${this.state.mode}`} target="_blank" rel="noopener noreferrer">
<a
href={file.name.endsWith(".json")
? `/content/json${this.state.path}${file.name}?special=${this.state.mode}`
: `/content${this.state.path}${file.name}?special=${this.state.mode}`}
target="_blank"
rel="noopener noreferrer"
>
{filename}
</a >
<span>{' '.repeat(maxLen - filename.length)}</span>
Expand Down
1 change: 1 addition & 0 deletions include/handler_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ error_t handleApiPcmUpload(HttpConnection *connection, const char_t *uri, const
error_t handleApiContent(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
error_t handleApiToniesJson(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
error_t handleApiToniesCustomJson(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
error_t handleApiContentJson(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);

#endif
22 changes: 22 additions & 0 deletions src/handler_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1596,4 +1596,26 @@ error_t handleApiToniesJson(HttpConnection *connection, const char_t *uri, const
error_t handleApiToniesCustomJson(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx)
{
return httpSendResponseUnsafe(connection, uri, TONIES_CUSTOM_JSON_PATH);
}
error_t handleApiContentJson(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx)
{
const char *rootPath = settings_get_string("internal.contentdirfull");
char special[16];
osStrcpy(special, "");
if (queryGet(queryString, "special", special, sizeof(special)))
{
TRACE_DEBUG("requested index for special '%s'\r\n", special);
if (!osStrcmp(special, "library"))
{
rootPath = settings_get_string("internal.librarydirfull");

if (rootPath == NULL || !fsDirExists(rootPath))
{
TRACE_ERROR("internal.librarydirfull not set to a valid path: '%s'\r\n", rootPath);
return ERROR_FAILURE;
}
}
}
char *file_path = custom_asprintf("%s%s", rootPath, &uri[13]);
return httpSendResponseUnsafe(connection, uri, file_path);
}
1 change: 1 addition & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ request_type_t request_paths[] = {
/* reverse proxy handler */
{REQ_ANY, "/reverse", &handleReverse},
/* web interface directory */
{REQ_GET, "/content/json/", &handleApiContentJson},
{REQ_GET, "/content/", &handleApiContent},
/* custom API */
{REQ_POST, "/api/fileDelete", &handleApiFileDelete},
Expand Down

0 comments on commit 1327a84

Please sign in to comment.