![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/keeview_app/html/ |
Upload File : |
const idbfs = Object.freeze(function () { var maincore = {}; var idbfs_retval = {}; var dbver = 1; var core = { partitions: {} }; core.getPartitionInstance = function (partitionName) { var retval = {}; retval.mkdir = function (path, callbackfunc) { core.mkdir(partitionName, path, callbackfunc); } retval.remove = function (path, callbackfunc) { core.remove(partitionName, path, callbackfunc); } retval.readDir = function (path, callbackfunc) { core.readDir(partitionName, path, callbackfunc); } retval.readFile = function (path, callbackfunc) { core.readFile(partitionName, path, callbackfunc); } retval.writeFile = function (path, content, callbackfunc) { core.writeFile(partitionName, path, content, callbackfunc); } retval.terminate = function () { delete retval.mkdir; delete retval.remove; delete retval.readDir; delete retval.readFile; delete retval.writeFile; delete retval.terminate; } return retval; }; core.open = function (partitionName, callbackfunc) { if (core.partitions[partitionName] !== undefined) { if (core.partitions[partitionName].ready === true) { if (core.partitions[partitionName].status === true) { Thread.setTimeout({ func: callbackfunc, args: [true, core.getPartitionInstance(partitionName)] }); } else { Thread.setTimeout({ func: callbackfunc, args: [false, core.partitions[partitionName].err] }); } return; } Thread.wait( function () { return core.partitions[partitionName].ready === true; }, function () { Thread.setTimeout({ func: callbackfunc, args: [true, core.getPartitionInstance(partitionName)] }); } ); return; } core.partitions[partitionName] = { ready: false, keyQueue: [], readQueue: [], writeQueue: [], reading: false, writing: false }; jscache.open (partitionName, function (success, content) { core.partitions[partitionName].ready = true; if (!success) { core.partitions[partitionName].status = false; core.partitions[partitionName].err = content; Thread.setTimeout({ func: callbackfunc, args: [false, content] }); return; } core.partitions[partitionName].instance = content; core.partitions[partitionName].status = true; Thread.setTimeout({ func: callbackfunc, args: [true, core.getPartitionInstance(partitionName)] }); }, dbver); }; var readThread = function (partitionName) { var callbackqueue = []; var keyMark = {}; var keyList = []; var queue, key; var i, j, t; var returnCall = function (queue) { var r = []; var i, key; for (i = 0; i < queue.keys.length; i++) { key = queue.keys[i]; if (keyMark[key].success) r.push({ key: key, value: keyMark[key] }); } delete queue.keys; try { queue.func(r); } catch (e) { delete queue.func; queue = null; if (e.stack !== undefined) { e.message = e.message + "\r\n" + e.stack; } throw e; } delete queue.func; queue = null; } var readStep = function (index) { var i; if (index == keyList.length) { for (i = 0; i < callbackqueue.length; i++) { if (callbackqueue[i] !== null) { Thread.setTimeout({ func: returnCall, args: [callbackqueue[i]] }); callbackqueue[i] = null; } } callbackqueue = null; keyList = null; Thread.setTimeout({ func: readThread, args: [partitionName] }); return; } core.partitions[partitionName].instance.read(keyList[index], function (success, content) { var i, j, queue, ok; if (success) { keyMark[keyList[index]] = { success: true, value: content }; } else { keyMark[keyList[index]] = { success: false }; } for (i = 0; i < callbackqueue.length; i++) { if (callbackqueue[i] !== null) { queue = callbackqueue[i]; ok = true; for (j = 0; j < queue.keys.length; j++) { if (keyMark[queue.keys] === undefined) { ok = false; break; } } if (ok) { callbackqueue[i] = null; Thread.setTimeout({ func: returnCall, args: [queue] }); } } } queue = null; keyList[index] = null; Thread.setTimeout({ func: readStep, args: [index + 1] }); }); } core.partitions[partitionName].reading = true; if (core.partitions[partitionName].keyQueue.length > 0) { queue = core.partitions[partitionName].keyQueue.shift(); core.partitions[partitionName].instance.keys2(queue.key, function (returnValues) { Thread.setTimeout({ func: readThread, args: [partitionName] }); setTimeout(function (func) { return function () { func(returnValues); } } (queue.callbackfunc)); delete queue.callbackfunc; delete queue.key; queue = null; }); return; } for (i = 0; i < core.partitions[partitionName].readQueue.length; i++) { queue = core.partitions[partitionName].readQueue[i]; if (queue.keys.length > 0) { t = []; for (j = 0; j < queue.keys.length; j++) { key = queue.keys[j]; if (EncodingClass.type.isString(key)) { t.push(key); if (keyMark[key] === undefined) { keyMark[key] = true; keyList.push(key); } } } queue.keys = t; t = null; if (queue.callbackfunc !== undefined) { if (EncodingClass.type.isFunction(queue.callbackfunc)) { callbackqueue.push({ keys: queue.keys, func: queue.callbackfunc }); } } } else if (queue.callbackfunc !== undefined) { if (EncodingClass.type.isFunction(queue.callbackfunc)) { Thread.setTimeout({ func: queue.callbackfunc, args: [true, []] }); } } } queue = null; keyMark = {}; core.partitions[partitionName].readQueue = []; if (keyList.length > 0) { Thread.setTimeout({ func: readStep, args: [0] }); } else { for (i = 0; i < callbackqueue.length; i++) { Thread.setTimeout({ func: returnCall, args: [callbackqueue[i]] }); } callbackqueue = null; core.partitions[partitionName].reading = false; } } var writeThread = function (partitionName) { var callbackqueue = []; var keyMark = {}; var queue, key; var i, j, t; var returnCall = function (queue) { try { queue.func(); } catch (e) { delete queue.func; queue = null; if (e.stack !== undefined) { e.message = e.message + "\r\n" + e.stack; } throw e; } delete queue.func; queue = null; } var writeStep = function () { var contents = []; var i; if (callbackqueue.length == 0) { Thread.setTimeout({ func: writeThread, args: [partitionName] }); return; } queue = callbackqueue.shift(); if (queue.keys.length == 0) { delete queue.keys; Thread.setTimeout({ func: writeStep }); Thread.setTimeout({ func: returnCall, args: [queue] }); return; } for (i = 0; i < queue.keys.length; i++) { contents.push({ key: queue.keys[i], value: keyMark[queue.keys[i]] }); } core.partitions[partitionName].instance.write2(contents, function (success) { for (i = 0; i < queue.keys.length; i++) { delete keyMark[queue.keys[i]]; } delete queue.keys; Thread.setTimeout({ func: writeStep }); Thread.setTimeout({ func: returnCall, args: [queue] }); }); } core.partitions[partitionName].writing = true; if (core.partitions[partitionName].writeQueue.length == 0) { core.partitions[partitionName].writing = false; return; } if (core.partitions[partitionName].writeQueue[0].task == "delete") { queue = core.partitions[partitionName].writeQueue.shift(); if (queue.contents === null) { core.partitions[partitionName].instance.clear(function (callbackfunc) { return function () { Thread.setTimeout({ func: writeThread, args: [partitionName] }); Thread.setTimeout({ func: returnCall, args: [{func: callbackfunc}] }); } } (queue.callbackfunc)); } else { core.partitions[partitionName].instance.deleteRange2(queue.contents, function (callbackfunc) { return function () { Thread.setTimeout({ func: writeThread, args: [partitionName] }); Thread.setTimeout({ func: returnCall, args: [{func: callbackfunc}] }); } } (queue.callbackfunc)); } return; } while (core.partitions[partitionName].writeQueue.length > 0) { if (core.partitions[partitionName].writeQueue[0].task != "write") break; queue = core.partitions[partitionName].writeQueue.shift(); t = []; for (j = 0; j < queue.contents.length; j++) { key = queue.contents[j].key; if (keyMark[key] === undefined) { t.push(queue.contents[j].key); } keyMark[key] = queue.contents[j].value; } callbackqueue.push({ keys: t, func: queue.callbackfunc }); } queue = null; t = null; Thread.setTimeout({ func: writeStep }); } core.key = function (partitionName, keyRange, callbackfunc) { core.partitions[partitionName].keyQueue.push({ key: keyRange, callbackfunc: callbackfunc }); if (core.partitions[partitionName].reading === false) readThread(partitionName); } core.read = function (partitionName, keys, callbackfunc) { core.partitions[partitionName].readQueue.push({ keys: EncodingClass.string.duplicateObject(keys), callbackfunc: callbackfunc }); if (core.partitions[partitionName].reading === false) readThread(partitionName); } core.write = function (partitionName, contents, callbackfunc) { core.partitions[partitionName].writeQueue.push({ task: "write", contents: contents, callbackfunc: callbackfunc }); if (core.partitions[partitionName].writing === false) writeThread(partitionName); } core.delete = function (partitionName, keyRange, callbackfunc) { core.partitions[partitionName].writeQueue.push({ task: "delete", contents: keyRange, callbackfunc: callbackfunc }); if (core.partitions[partitionName].writing === false) writeThread(partitionName); } core.mkdir = function (partitionName, path, callbackfunc) { var createDir = function (index) { var st = "", sx; if (index == path.length) { Thread.setTimeout({ func: callbackfunc, args: [true] }); return; } for (i = 0; i < index; i++) { sx = path[i].length.toString(16).toLowerCase(); while (sx.length < 3) sx = "0" + sx; if (i < index - 1) { sx = "a" + sx + path[i]; } else { sx = "b" + sx + path[i]; } if (i == 0) { st = sx; } else { st = st + "/" + sx; } } core.key(partitionName, IDBKeyRange.only(st), function (retval) { if (retval.length > 0) { Thread.setTimeout({ func: createDir, args: [index + 1] }); return; } core.write(partitionName, [{key: st, value: true}], function (success) { if (success) { Thread.setTimeout({ func: createDir, args: [index + 1] }); return; } Thread.setTimeout({ func: callbackfunc, args: [false] }); }); }); } path = path.split("/"); createDir(0); } core.readDir = function (partitionName, path, callbackfunc) { var st = "", sx; var i; path = path.split("/"); for (i = 0; i < path.length; i++) { sx = path[i].length.toString(16).toLowerCase(); while (sx.length < 3) sx = "0" + sx; sx = "a" + sx + path[i]; if (i == 0) { st = sx; } else { st = st + "/" + sx; } } core.key(partitionName, IDBKeyRange.bound(st + "/b", st + "/d", false, true), function (retval) { var i, r = [], t, slen; retval.sort(); for (i = 0; i < retval.length; i++) { sx = retval[i].split("/"); sx = sx[sx.length - 1]; t = { type: (sx.substr(0, 1) == "b") ? "directory" : "file" }; slen = parseInt(sx.substr(1, 3), 16); t.name = EncodingClass.string.substr(sx, 4, slen); if (t.type == "directory") { r.push(t); } else if (sx.substr(slen + 4, 1) == "_") { r.push(t); } } Thread.setTimeout({ func: callbackfunc, args: [r] }); }); } core.remove = function (partitionName, path, callbackfunc) { var st = "", sx, sn, sa, sb; if (path.trim().length == 0) { core.delete(partitionName, null, callbackfunc); return; } path = path.split("/"); for (i = 0; i < path.length - 1; i++) { sx = path[i].length.toString(16).toLowerCase(); while (sx.length < 3) sx = "0" + sx; sx = "a" + sx + path[i]; st += sx + "/"; } sn = path[i].length.toString(16).toLowerCase(); while (sn.length < 3) sn = "0" + sn; sn += path[i]; sa = sb = 0; core.delete(partitionName, IDBKeyRange.bound(st + "a" + sn + "/", jscache.nextKey(st + "a" + sn + "/"), false, true), function () { sb = 1; if (sa == sb) callbackfunc(); }); core.delete(partitionName, IDBKeyRange.only(st + "b" + sn), function () { sa = 1; if (sa == sb) callbackfunc(); }); core.delete(partitionName, IDBKeyRange.bound(st + "c" + sn, jscache.nextKey(st + "c" + sn), false, true), function () { sb = 1; if (sa == sb) callbackfunc(); }); } core.writeFile = function (partitionName, path, content, callbackfunc) { var st = "", sx, sn, start, next, slength, length, xlen, index, buf; var wcontents = []; var oldPath = path; path = path.split("/"); if (path.length > 0) { for (i = 0; i < path.length - 1; i++) { sx = path[i].length.toString(16).toLowerCase(); while (sx.length < 3) sx = "0" + sx; sx = "a" + sx + path[i]; st += sx + "/"; } } sn = path[path.length - 1].length.toString(16).toLowerCase(); while (sn.length < 3) sn = "0" + sn; st += "c" + sn + path[i]; if (EncodingClass.type.isString(content)) { content = EncodingClass.string.toUint8Array(content); } slength = length = content.length; if (length > 0) { index = start = 0; while (length > 0) { xlen = length; if (xlen > 262144) xlen = 262144; buf = new Uint8Array(xlen); next = start + xlen; buf.set(content.subarray(start, next)); start = next; length -= xlen; wcontents.push({ key: st + (index++), value: buf }); } } wcontents.push({ key: st + "_", value: slength }); core.write(partitionName, wcontents, callbackfunc); }; core.readFile = function (partitionName, path, callbackfunc) { var st = "", sx, sn, start, next, slength, length, xlen, index, buf; var wcontents = []; var oldPath = path; path = path.split("/"); if (path.length > 0) { for (i = 0; i < path.length - 1; i++) { sx = path[i].length.toString(16).toLowerCase(); while (sx.length < 3) sx = "0" + sx; sx = "a" + sx + path[i]; st += sx + "/"; } } sn = path[path.length - 1].length.toString(16).toLowerCase(); while (sn.length < 3) sn = "0" + sn; st += "c" + sn + path[i]; core.read(partitionName, [st + "_"], function (retval) { if (retval.length == 0) { Thread.setTimeout({ func: callbackfunc, args: [null] }); return; } slength = length = retval[0].value.value; if (length > 0) { start = index = 0; while (length > 0) { xlen = length; if (xlen > 262144) xlen = 262144; next = start + xlen; start = next; length -= xlen; wcontents.push(st + (index++)); } core.read(partitionName, wcontents, function (retval) { var i; if (retval.length != index) { Thread.setTimeout({ func: callbackfunc, args: [null] }); return; } buf = new Uint8Array (slength); for (i = 0; i < retval.length; i++) { buf.set(retval[i].value.value, i * 262144); } Thread.setTimeout({ func: callbackfunc, args: [buf] }); }); } else { Thread.setTimeout({ func: callbackfunc, args: [new Uint8Array(0)] }); } }); }; idbfs_retval.open = function (partitionName, callbackfunc) { core.open(partitionName, callbackfunc); }; return idbfs_retval; } ());