Compare commits
	
		
			2 Commits
		
	
	
		
			9f71ec6194
			...
			221f276c4b
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 221f276c4b | |||
| 24cec21465 | 
@@ -211,10 +211,6 @@ async function socket(request, response, client) {
 | 
				
			|||||||
				if (process && process.timeout > 0) {
 | 
									if (process && process.timeout > 0) {
 | 
				
			||||||
					setTimeout(ping, process.timeout);
 | 
										setTimeout(ping, process.timeout);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else if (message.action == 'enableStats') {
 | 
					 | 
				
			||||||
				if (process) {
 | 
					 | 
				
			||||||
					core.enableStats(process, message.enabled);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			} else if (message.action == 'resetPermission') {
 | 
								} else if (message.action == 'resetPermission') {
 | 
				
			||||||
				if (process) {
 | 
									if (process) {
 | 
				
			||||||
					process.resetPermission(message.permission);
 | 
										process.resetPermission(message.permission);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1274,7 +1274,6 @@ function _receive_websocket_message(message) {
 | 
				
			|||||||
		document.getElementById('viewPane').style.display = message.edit_only
 | 
							document.getElementById('viewPane').style.display = message.edit_only
 | 
				
			||||||
			? 'none'
 | 
								? 'none'
 | 
				
			||||||
			: 'flex';
 | 
								: 'flex';
 | 
				
			||||||
		send({action: 'enableStats', enabled: true});
 | 
					 | 
				
			||||||
	} else if (message && message.action == 'ping') {
 | 
						} else if (message && message.action == 'ping') {
 | 
				
			||||||
		send({action: 'pong'});
 | 
							send({action: 'pong'});
 | 
				
			||||||
	} else if (message && message.action == 'stats') {
 | 
						} else if (message && message.action == 'stats') {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										53
									
								
								core/core.js
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								core/core.js
									
									
									
									
									
								
							@@ -8,10 +8,6 @@ let gStatsTimer = false;
 | 
				
			|||||||
const k_content_security_policy =
 | 
					const k_content_security_policy =
 | 
				
			||||||
	'sandbox allow-downloads allow-top-navigation-by-user-activation';
 | 
						'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 = {
 | 
					const k_global_settings = {
 | 
				
			||||||
	index: {
 | 
						index: {
 | 
				
			||||||
		type: 'string',
 | 
							type: 'string',
 | 
				
			||||||
@@ -290,7 +286,6 @@ async function getProcessBlob(blobId, key, options) {
 | 
				
			|||||||
			process.lastActive = Date.now();
 | 
								process.lastActive = Date.now();
 | 
				
			||||||
			process.lastPing = null;
 | 
								process.lastPing = null;
 | 
				
			||||||
			process.timeout = options.timeout;
 | 
								process.timeout = options.timeout;
 | 
				
			||||||
			process.stats = false;
 | 
					 | 
				
			||||||
			process.ready = new Promise(function (resolve, reject) {
 | 
								process.ready = new Promise(function (resolve, reject) {
 | 
				
			||||||
				resolveReady = resolve;
 | 
									resolveReady = resolve;
 | 
				
			||||||
				rejectReady = reject;
 | 
									rejectReady = reject;
 | 
				
			||||||
@@ -782,6 +777,10 @@ async function getProcessBlob(blobId, key, options) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			await process.task.execute({name: appSourceName, source: appSource});
 | 
								await process.task.execute({name: appSourceName, source: appSource});
 | 
				
			||||||
			resolveReady(process);
 | 
								resolveReady(process);
 | 
				
			||||||
 | 
								if (!gStatsTimer) {
 | 
				
			||||||
 | 
									gStatsTimer = true;
 | 
				
			||||||
 | 
									sendStats();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		} catch (error) {
 | 
							} catch (error) {
 | 
				
			||||||
			if (process.app) {
 | 
								if (process.app) {
 | 
				
			||||||
				if (process?.task?.onError) {
 | 
									if (process?.task?.onError) {
 | 
				
			||||||
@@ -918,34 +917,6 @@ async function useAppHandler(
 | 
				
			|||||||
 * @returns
 | 
					 * @returns
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
async function blobHandler(request, response, blobId, uri) {
 | 
					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) {
 | 
						if (!uri) {
 | 
				
			||||||
		response.writeHead(303, {
 | 
							response.writeHead(303, {
 | 
				
			||||||
			Location:
 | 
								Location:
 | 
				
			||||||
@@ -1232,7 +1203,7 @@ async function loadSettings() {
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
function sendStats() {
 | 
					function sendStats() {
 | 
				
			||||||
	let apps = Object.values(gProcesses)
 | 
						let apps = Object.values(gProcesses)
 | 
				
			||||||
		.filter((process) => process.app && process.stats)
 | 
							.filter((process) => process.app)
 | 
				
			||||||
		.map((process) => process.app);
 | 
							.map((process) => process.app);
 | 
				
			||||||
	if (apps.length) {
 | 
						if (apps.length) {
 | 
				
			||||||
		let stats = getStats();
 | 
							let stats = getStats();
 | 
				
			||||||
@@ -1245,19 +1216,6 @@ function sendStats() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * TODOC
 | 
					 | 
				
			||||||
 * @param {*} process
 | 
					 | 
				
			||||||
 * @param {*} enabled
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
function enableStats(process, enabled) {
 | 
					 | 
				
			||||||
	process.stats = enabled;
 | 
					 | 
				
			||||||
	if (!gStatsTimer) {
 | 
					 | 
				
			||||||
		gStatsTimer = true;
 | 
					 | 
				
			||||||
		sendStats();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * TODOC
 | 
					 * TODOC
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@@ -1374,7 +1332,6 @@ function storePermission(user, packageOwner, packageName, permission, allow) {
 | 
				
			|||||||
export {
 | 
					export {
 | 
				
			||||||
	gGlobalSettings as globalSettings,
 | 
						gGlobalSettings as globalSettings,
 | 
				
			||||||
	setGlobalSettings,
 | 
						setGlobalSettings,
 | 
				
			||||||
	enableStats,
 | 
					 | 
				
			||||||
	invoke,
 | 
						invoke,
 | 
				
			||||||
	getSessionProcessBlob,
 | 
						getSessionProcessBlob,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -905,14 +905,23 @@ static void _httpd_endpoint_static(tf_http_request_t* request)
 | 
				
			|||||||
	const char* file_path = NULL;
 | 
						const char* file_path = NULL;
 | 
				
			||||||
	for (int i = 0; i < tf_countof(k_map) && !after; i++)
 | 
						for (int i = 0; i < tf_countof(k_map) && !after; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		after = _after(request->path, k_map[i][0]);
 | 
							const char* next_after = _after(request->path, k_map[i][0]);
 | 
				
			||||||
 | 
							if (next_after)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								after = next_after;
 | 
				
			||||||
			file_path = k_map[i][1];
 | 
								file_path = k_map[i][1];
 | 
				
			||||||
		is_core = is_core || (after && i == 0);
 | 
								is_core = after && i == 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcmp(request->path, "/speedscope/") == 0)
 | 
						if ((!after || !*after) && request->path[strlen(request->path) - 1] == '/')
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		after = "index.html";
 | 
							after = "index.html";
 | 
				
			||||||
 | 
							if (!file_path)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								file_path = "core/";
 | 
				
			||||||
 | 
								is_core = true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!after || strstr(after, ".."))
 | 
						if (!after || strstr(after, ".."))
 | 
				
			||||||
@@ -1668,6 +1677,7 @@ void tf_httpd_register(JSContext* context)
 | 
				
			|||||||
	tf_http_add_handler(http, "/speedscope/*", _httpd_endpoint_static, NULL, task);
 | 
						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, "/static/*", _httpd_endpoint_static, NULL, task);
 | 
				
			||||||
	tf_http_add_handler(http, "/.well-known/*", _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, "/robots.txt", _httpd_endpoint_robots_txt, NULL, NULL);
 | 
				
			||||||
	tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, NULL, task);
 | 
						tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, NULL, task);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user