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