forked from cory/tildefriends
		
	require -> import
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3904 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		@@ -1,7 +1,5 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
var auth = require('auth');
 | 
			
		||||
var core = require('core');
 | 
			
		||||
import * as auth from './auth.js';
 | 
			
		||||
import * as core from './core.js';
 | 
			
		||||
 | 
			
		||||
var gSessionIndex = 0;
 | 
			
		||||
 | 
			
		||||
@@ -164,5 +162,4 @@ function socket(request, response, client) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.socket = socket;
 | 
			
		||||
exports.App = App;
 | 
			
		||||
export { socket, App };
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										14
									
								
								core/auth.js
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								core/auth.js
									
									
									
									
									
								
							@@ -1,11 +1,8 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
import * as core from './core.js';
 | 
			
		||||
import * as http from './http.js';
 | 
			
		||||
import * as form from './form.js';
 | 
			
		||||
 | 
			
		||||
var gTokens = {};
 | 
			
		||||
 | 
			
		||||
var core = require('core');
 | 
			
		||||
var form = require('form');
 | 
			
		||||
var http = require('http');
 | 
			
		||||
 | 
			
		||||
var gDatabase = new Database("auth");
 | 
			
		||||
 | 
			
		||||
function readSession(session) {
 | 
			
		||||
@@ -86,7 +83,7 @@ function getCookies(headers) {
 | 
			
		||||
	return cookies;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function authHandler(request, response) {
 | 
			
		||||
function handler(request, response) {
 | 
			
		||||
	var session = getCookies(request.headers).session;
 | 
			
		||||
	if (request.uri == "/login") {
 | 
			
		||||
		var sessionIsNew = false;
 | 
			
		||||
@@ -219,5 +216,4 @@ function query(headers) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.handler = authHandler;
 | 
			
		||||
exports.query = query;
 | 
			
		||||
export { handler, query };
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								core/core.js
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								core/core.js
									
									
									
									
									
								
							@@ -1,7 +1,6 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
var auth = require("auth");
 | 
			
		||||
var app = require("app");
 | 
			
		||||
import * as auth from './auth.js';
 | 
			
		||||
import * as app from './app.js';
 | 
			
		||||
import * as httpd from './httpd.js';
 | 
			
		||||
 | 
			
		||||
var gProcessIndex = 0;
 | 
			
		||||
var gProcesses = {};
 | 
			
		||||
@@ -559,8 +558,6 @@ function enableStats(process, enabled) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
loadSettings().then(function() {
 | 
			
		||||
	var auth = require("auth");
 | 
			
		||||
	var httpd = require("httpd");
 | 
			
		||||
	httpd.all("/login", auth.handler);
 | 
			
		||||
	httpd.all("", function(request, response) {
 | 
			
		||||
		var match;
 | 
			
		||||
@@ -600,12 +597,14 @@ loadSettings().then(function() {
 | 
			
		||||
	httpd.registerSocketHandler("/app/socket", app.socket);
 | 
			
		||||
}).catch(function(error) {
 | 
			
		||||
	print('Failed to load settings.');
 | 
			
		||||
	print(error);
 | 
			
		||||
	printError({print: print}, error);
 | 
			
		||||
	exit(1);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
exports.getSessionProcessBlob = getSessionProcessBlob;
 | 
			
		||||
exports.invoke = invoke;
 | 
			
		||||
exports.globalSettings = gGlobalSettings;
 | 
			
		||||
exports.setGlobalSettings = setGlobalSettings;
 | 
			
		||||
exports.enableStats = enableStats;
 | 
			
		||||
export {
 | 
			
		||||
	gGlobalSettings as globalSettings,
 | 
			
		||||
	setGlobalSettings,
 | 
			
		||||
	enableStats,
 | 
			
		||||
	invoke,
 | 
			
		||||
	getSessionProcessBlob
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,3 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
function decode(encoded) {
 | 
			
		||||
	var result = "";
 | 
			
		||||
	for (var i = 0; i < encoded.length; i++) {
 | 
			
		||||
@@ -32,4 +30,4 @@ function decodeForm(encoded, initial) {
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.decodeForm = decodeForm;
 | 
			
		||||
export { decodeForm };
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,7 @@ function parseResponse(data) {
 | 
			
		||||
	return {body: data};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function get(url) {
 | 
			
		||||
export function get(url) {
 | 
			
		||||
	var parsed = parseUrl(url);
 | 
			
		||||
	return new Promise(function(resolve, reject) {
 | 
			
		||||
		var socket = new Socket();
 | 
			
		||||
@@ -57,5 +57,3 @@ function get(url) {
 | 
			
		||||
		});
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.get = get;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,5 @@
 | 
			
		||||
import * as sha1 from './sha1.js';
 | 
			
		||||
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
var gHandlers = [];
 | 
			
		||||
@@ -332,7 +334,7 @@ function handleWebSocketRequest(request, response, client) {
 | 
			
		||||
function webSocketAcceptResponse(key) {
 | 
			
		||||
	var kMagic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
 | 
			
		||||
	var kAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
 | 
			
		||||
	var hex = require("sha1").hash(key + kMagic)
 | 
			
		||||
	var hex = sha1.hash(key + kMagic)
 | 
			
		||||
	var binary = "";
 | 
			
		||||
	for (var i = 0; i < hex.length; i += 6) {
 | 
			
		||||
		var characters = hex.substring(i, i + 6);
 | 
			
		||||
@@ -634,5 +636,4 @@ if (tildefriends.https_port) {
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.all = all;
 | 
			
		||||
exports.registerSocketHandler = registerSocketHandler;
 | 
			
		||||
export { all, registerSocketHandler };
 | 
			
		||||
 
 | 
			
		||||
@@ -157,4 +157,4 @@ if (typeof String.prototype.utf8Decode == 'undefined') {
 | 
			
		||||
if (typeof module != 'undefined' && module.exports) module.exports = Sha1; // CommonJs export
 | 
			
		||||
if (typeof define == 'function' && define.amd) define([], function() { return Sha1; }); // AMD
 | 
			
		||||
 | 
			
		||||
exports.hash = Sha1.hash;
 | 
			
		||||
export let hash = Sha1.hash;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										25
									
								
								src/task.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/task.c
									
									
									
									
									
								
							@@ -1044,7 +1044,7 @@ JSValue _tf_task_require(JSContext* context, JSValueConst this_val, int argc, JS
 | 
			
		||||
				};
 | 
			
		||||
				task->_scriptExports = export;
 | 
			
		||||
				const char* source = _task_loadFile(path);
 | 
			
		||||
				printf("Requiring script %s\n", path);
 | 
			
		||||
				printf("Requiring script %sn", path);
 | 
			
		||||
				if (source)
 | 
			
		||||
				{
 | 
			
		||||
					JSValue global = JS_GetGlobalObject(task->_context);
 | 
			
		||||
@@ -1408,17 +1408,26 @@ JSModuleDef* _tf_task_module_loader(JSContext* context, const char* module_name,
 | 
			
		||||
{
 | 
			
		||||
	tf_task_t* task = opaque;
 | 
			
		||||
	JSValue source_value = JS_GetPropertyStr(context, task->_loadedFiles, module_name);
 | 
			
		||||
 | 
			
		||||
	char* source = NULL;
 | 
			
		||||
	size_t length = 0;
 | 
			
		||||
	uint8_t* array = tf_util_try_get_array_buffer(context, &length, source_value);
 | 
			
		||||
	if (array)
 | 
			
		||||
 | 
			
		||||
	if (!JS_IsUndefined(source_value))
 | 
			
		||||
	{
 | 
			
		||||
		source = tf_malloc(length + 1);
 | 
			
		||||
		memcpy(source, array, length);
 | 
			
		||||
		source[length] = '\0';
 | 
			
		||||
		uint8_t* array = tf_util_try_get_array_buffer(context, &length, source_value);
 | 
			
		||||
		if (array)
 | 
			
		||||
		{
 | 
			
		||||
			source = tf_malloc(length + 1);
 | 
			
		||||
			memcpy(source, array, length);
 | 
			
		||||
			source[length] = '\0';
 | 
			
		||||
		}
 | 
			
		||||
		JS_FreeValue(context, source_value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!source && task->_trusted)
 | 
			
		||||
	{
 | 
			
		||||
		source = (char*)_task_loadFile(module_name);
 | 
			
		||||
		length = source ? strlen(source) : 0;
 | 
			
		||||
	}
 | 
			
		||||
	JS_FreeValue(context, source_value);
 | 
			
		||||
 | 
			
		||||
	if (!source)
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user