Skip to content

Commit 9350a6a

Browse files
authored
Merge pull request #449 from nater0000/main
Change to support serving files from a c-embed filesystem
2 parents d01c8a8 + bbcdb9c commit 9350a6a

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

src/webui.c

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7975,7 +7975,45 @@ static int _webui_http_handler(struct mg_connection* client, void * _win) {
79757975
// [Path][Sep][folder]
79767976
char* folder_path = _webui_get_full_path(win, url);
79777977

7978-
if (_webui_folder_exist(folder_path)) {
7978+
if (_webui_file_exist(folder_path)) {
7979+
7980+
// [/file]
7981+
7982+
bool script = false;
7983+
if (win->runtime != None) {
7984+
const char* extension = _webui_get_extension(url);
7985+
const char* index_extensions[] = {
7986+
"js", "ts"
7987+
};
7988+
for (size_t i = 0; i < (sizeof(index_extensions) / sizeof(index_extensions[0])); i++) {
7989+
if (strcmp(extension, index_extensions[i]) == 0) {
7990+
script = true;
7991+
break;
7992+
}
7993+
}
7994+
}
7995+
7996+
if (script) {
7997+
7998+
#ifdef WEBUI_LOG
7999+
printf("[Core]\t\t_webui_http_handler() -> Interpret local script file\n");
8000+
#endif
8001+
8002+
// Serve as a script file to be interpreted by
8003+
// an external interpreter (Deno, Bun, Nodejs)
8004+
http_status_code = _webui_interpret_file(win, client, NULL, client_id);
8005+
}
8006+
else {
8007+
8008+
#ifdef WEBUI_LOG
8009+
printf("[Core]\t\t_webui_http_handler() -> Local file\n");
8010+
#endif
8011+
8012+
// Serve as a normal text-based file
8013+
http_status_code = _webui_serve_file(win, client, client_id);
8014+
}
8015+
}
8016+
else if (_webui_folder_exist(folder_path)) {
79798017

79808018
// [/folder]
79818019

@@ -8012,42 +8050,16 @@ static int _webui_http_handler(struct mg_connection* client, void * _win) {
80128050
http_status_code = 404;
80138051
}
80148052
else {
8015-
8016-
// [/file]
8017-
8018-
bool script = false;
8019-
if (win->runtime != None) {
8020-
const char* extension = _webui_get_extension(url);
8021-
const char* index_extensions[] = {
8022-
"js", "ts"
8023-
};
8024-
for (size_t i = 0; i < (sizeof(index_extensions) / sizeof(index_extensions[0])); i++) {
8025-
if (strcmp(extension, index_extensions[i]) == 0) {
8026-
script = true;
8027-
break;
8028-
}
8029-
}
8030-
}
8031-
8032-
if (script) {
8033-
8034-
#ifdef WEBUI_LOG
8035-
printf("[Core]\t\t_webui_http_handler() -> Interpret local script file\n");
8036-
#endif
8037-
8038-
// Serve as a script file to be interpreted by
8039-
// an external interpreter (Deno, Bun, Nodejs)
8040-
http_status_code = _webui_interpret_file(win, client, NULL, client_id);
8041-
}
8042-
else {
8043-
8044-
#ifdef WEBUI_LOG
8045-
printf("[Core]\t\t_webui_http_handler() -> Local file\n");
8046-
#endif
8047-
8048-
// Serve as a normal text-based file
8049-
http_status_code = _webui_serve_file(win, client, client_id);
8050-
}
8053+
8054+
// [invalid]
8055+
8056+
#ifdef WEBUI_LOG
8057+
printf("[Core]\t\t_webui_http_handler() -> Not found\n");
8058+
#endif
8059+
8060+
// No file or folder is found at this path
8061+
http_status_code = _webui_serve_file(win, client, client_id);
8062+
http_status_code = 404;
80518063
}
80528064

80538065
// Clear

0 commit comments

Comments
 (0)