Add support for delivering static content from embedded webserver.
Move extjs app to webui/static/app
This commit is contained in:
parent
6bcfbebb70
commit
35a96defca
8 changed files with 64 additions and 27 deletions
|
@ -40,14 +40,6 @@
|
|||
|
||||
extern const char *htsversion;
|
||||
|
||||
#include "obj/tvheadend.jsh"
|
||||
#include "obj/extensions.jsh"
|
||||
#include "obj/acleditor.jsh"
|
||||
#include "obj/cwceditor.jsh"
|
||||
#include "obj/dvb.jsh"
|
||||
#include "obj/ext.cssh"
|
||||
|
||||
|
||||
static void
|
||||
extjs_load(htsbuf_queue_t *hq, const char *script)
|
||||
{
|
||||
|
@ -89,7 +81,7 @@ extjs_root(http_connection_t *hc, http_reply_t *hr,
|
|||
|
||||
htsbuf_qprintf(hq, "<html><body>\n"
|
||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\""EXTJSPATH"/resources/css/ext-all.css\">\n"
|
||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"app/extensions.css\">\n"
|
||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"static/app/ext.css\">\n"
|
||||
"<script type=\"text/javascript\" src=\""EXTJSPATH"/adapter/ext/ext-base.js\"></script>\n"
|
||||
"<script type=\"text/javascript\" src=\""EXTJSPATH"/ext-all-debug.js\"></script>\n");
|
||||
|
||||
|
@ -99,8 +91,7 @@ extjs_root(http_connection_t *hc, http_reply_t *hr,
|
|||
/**
|
||||
* Load extjs extensions
|
||||
*/
|
||||
extjs_load(hq, "app/extensions.js");
|
||||
extjs_load(hq, "app/tabclosemenu.js");
|
||||
extjs_load(hq, "static/app/extensions.js");
|
||||
|
||||
/**
|
||||
* Create a namespace for our app
|
||||
|
@ -110,14 +101,14 @@ extjs_root(http_connection_t *hc, http_reply_t *hr,
|
|||
/**
|
||||
* Load all components
|
||||
*/
|
||||
extjs_load(hq, "app/acleditor.js");
|
||||
extjs_load(hq, "app/cwceditor.js");
|
||||
extjs_load(hq, "app/dvb.js");
|
||||
extjs_load(hq, "static/app/acleditor.js");
|
||||
extjs_load(hq, "static/app/cwceditor.js");
|
||||
extjs_load(hq, "static/app/dvb.js");
|
||||
|
||||
/**
|
||||
* Finally, the app itself
|
||||
*/
|
||||
extjs_load(hq, "app/tvheadend.js");
|
||||
extjs_load(hq, "static/app/tvheadend.js");
|
||||
extjs_exec(hq, "Ext.onReady(tvheadend.app.init, tvheadend.app);");
|
||||
|
||||
|
||||
|
@ -401,16 +392,4 @@ extjs_start(void)
|
|||
http_path_add("/dvbtree", NULL, extjs_dvbtree, ACCESS_WEB_INTERFACE);
|
||||
http_path_add("/dvbadapter", NULL, extjs_dvbadapter, ACCESS_WEB_INTERFACE);
|
||||
http_path_add("/dvbnetworks", NULL, extjs_dvbnetworks, ACCESS_WEB_INTERFACE);
|
||||
|
||||
#define ADD_JS_RESOURCE(path, name) \
|
||||
http_resource_add(path, name, sizeof(name), "text/javascript", "gzip")
|
||||
|
||||
ADD_JS_RESOURCE("/app/extensions.js", embedded_extensions);
|
||||
ADD_JS_RESOURCE("/app/extensions.css", embedded_ext);
|
||||
|
||||
ADD_JS_RESOURCE("/app/tvheadend.js", embedded_tvheadend);
|
||||
|
||||
ADD_JS_RESOURCE("/app/acleditor.js", embedded_acleditor);
|
||||
ADD_JS_RESOURCE("/app/cwceditor.js", embedded_cwceditor);
|
||||
ADD_JS_RESOURCE("/app/dvb.js", embedded_dvb);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "tvhead.h"
|
||||
#include "access.h"
|
||||
#include "http.h"
|
||||
|
@ -62,6 +65,58 @@ page_root(http_connection_t *hc, http_reply_t *hr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Root page, we direct the client to different pages depending
|
||||
* on if it is a full blown browser or just some mobile app
|
||||
*/
|
||||
static int
|
||||
page_static(http_connection_t *hc, http_reply_t *hr,
|
||||
const char *remain, void *opaque)
|
||||
{
|
||||
int fd, r;
|
||||
const char *rootpath = HTS_BUILD_ROOT "/tvheadend/webui/static";
|
||||
char path[500];
|
||||
struct stat st;
|
||||
void *buf;
|
||||
htsbuf_queue_t *hq = &hr->hr_q;
|
||||
const char *content = NULL, *postfix;
|
||||
|
||||
if(strstr(remain, ".."))
|
||||
return HTTP_STATUS_BAD_REQUEST;
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s", rootpath, remain);
|
||||
|
||||
if((fd = open(path, O_RDONLY)) < 0)
|
||||
return 404;
|
||||
|
||||
if(fstat(fd, &st) < 0) {
|
||||
close(fd);
|
||||
return 404;
|
||||
}
|
||||
|
||||
buf = malloc(st.st_size);
|
||||
r = read(fd, buf, st.st_size);
|
||||
close(fd);
|
||||
|
||||
if(r != st.st_size) {
|
||||
free(buf);
|
||||
return 404;
|
||||
}
|
||||
|
||||
postfix = strrchr(remain, '.');
|
||||
if(postfix != NULL) {
|
||||
postfix++;
|
||||
|
||||
if(!strcmp(postfix, "js"))
|
||||
content = "text/javascript; charset=UTF-8";
|
||||
}
|
||||
|
||||
htsbuf_append_prealloc(hq, buf, st.st_size);
|
||||
http_output(hc, hr, content, NULL, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* WEB user interface
|
||||
*/
|
||||
|
@ -70,7 +125,10 @@ webui_start(void)
|
|||
{
|
||||
http_path_add("/", NULL, page_root, ACCESS_WEB_INTERFACE);
|
||||
|
||||
http_path_add("/static", NULL, page_static, ACCESS_WEB_INTERFACE);
|
||||
|
||||
simpleui_start();
|
||||
extjs_start();
|
||||
comet_init();
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue