Compare commits

..

No commits in common. "221f276c4b92bb85b0246214bfe1d0d90afb2742" and "9f71ec61941ea4c6042334b848dd07e0fc04f44c" have entirely different histories.

4 changed files with 57 additions and 19 deletions

View File

@ -211,6 +211,10 @@ async function socket(request, response, client) {
if (process && process.timeout > 0) {
setTimeout(ping, process.timeout);
}
} else if (message.action == 'enableStats') {
if (process) {
core.enableStats(process, message.enabled);
}
} else if (message.action == 'resetPermission') {
if (process) {
process.resetPermission(message.permission);

View File

@ -1274,6 +1274,7 @@ function _receive_websocket_message(message) {
document.getElementById('viewPane').style.display = message.edit_only
? 'none'
: 'flex';
send({action: 'enableStats', enabled: true});
} else if (message && message.action == 'ping') {
send({action: 'pong'});
} else if (message && message.action == 'stats') {

View File

@ -8,6 +8,10 @@ let gStatsTimer = false;
const k_content_security_policy =
'sandbox allow-downloads allow-top-navigation-by-user-activation';
let k_static_files = [
{uri: '/', path: 'index.html', type: 'text/html; charset=UTF-8'},
];
const k_global_settings = {
index: {
type: 'string',
@ -286,6 +290,7 @@ async function getProcessBlob(blobId, key, options) {
process.lastActive = Date.now();
process.lastPing = null;
process.timeout = options.timeout;
process.stats = false;
process.ready = new Promise(function (resolve, reject) {
resolveReady = resolve;
rejectReady = reject;
@ -777,10 +782,6 @@ async function getProcessBlob(blobId, key, options) {
}
await process.task.execute({name: appSourceName, source: appSource});
resolveReady(process);
if (!gStatsTimer) {
gStatsTimer = true;
sendStats();
}
} catch (error) {
if (process.app) {
if (process?.task?.onError) {
@ -917,6 +918,34 @@ async function useAppHandler(
* @returns
*/
async function blobHandler(request, response, blobId, uri) {
// TODO(tasiaiso): break this down ?
for (let i in k_static_files) {
if (uri === k_static_files[i].uri && k_static_files[i].path) {
let stat = await File.stat('core/' + k_static_files[i].path);
let id = `${stat.mtime}_${stat.size}`;
if (request.headers['if-none-match'] === '"' + id + '"') {
response.writeHead(304, {'Content-Length': '0'});
response.end();
} else {
let data = await File.readFile('core/' + k_static_files[i].path);
response.writeHead(
200,
Object.assign(
{
'Content-Type': k_static_files[i].type,
'Content-Length': data.byteLength,
etag: '"' + id + '"',
},
k_static_files[i].headers || {}
)
);
response.end(data);
}
return;
}
}
if (!uri) {
response.writeHead(303, {
Location:
@ -1203,7 +1232,7 @@ async function loadSettings() {
*/
function sendStats() {
let apps = Object.values(gProcesses)
.filter((process) => process.app)
.filter((process) => process.app && process.stats)
.map((process) => process.app);
if (apps.length) {
let stats = getStats();
@ -1216,6 +1245,19 @@ function sendStats() {
}
}
/**
* TODOC
* @param {*} process
* @param {*} enabled
*/
function enableStats(process, enabled) {
process.stats = enabled;
if (!gStatsTimer) {
gStatsTimer = true;
sendStats();
}
}
/**
* TODOC
*/
@ -1332,6 +1374,7 @@ function storePermission(user, packageOwner, packageName, permission, allow) {
export {
gGlobalSettings as globalSettings,
setGlobalSettings,
enableStats,
invoke,
getSessionProcessBlob,
};

View File

@ -905,23 +905,14 @@ static void _httpd_endpoint_static(tf_http_request_t* request)
const char* file_path = NULL;
for (int i = 0; i < tf_countof(k_map) && !after; i++)
{
const char* next_after = _after(request->path, k_map[i][0]);
if (next_after)
{
after = next_after;
after = _after(request->path, k_map[i][0]);
file_path = k_map[i][1];
is_core = after && i == 0;
}
is_core = is_core || (after && i == 0);
}
if ((!after || !*after) && request->path[strlen(request->path) - 1] == '/')
if (strcmp(request->path, "/speedscope/") == 0)
{
after = "index.html";
if (!file_path)
{
file_path = "core/";
is_core = true;
}
}
if (!after || strstr(after, ".."))
@ -1677,7 +1668,6 @@ void tf_httpd_register(JSContext* context)
tf_http_add_handler(http, "/speedscope/*", _httpd_endpoint_static, NULL, task);
tf_http_add_handler(http, "/static/*", _httpd_endpoint_static, NULL, task);
tf_http_add_handler(http, "/.well-known/*", _httpd_endpoint_static, NULL, task);
tf_http_add_handler(http, "/~*/*/", _httpd_endpoint_static, NULL, task);
tf_http_add_handler(http, "/robots.txt", _httpd_endpoint_robots_txt, NULL, NULL);
tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, NULL, task);