Initial import of LogDarioSeq baseline
Establishes version control for the personal Logseq DB fork before starting the server-client architecture migration and domain features described in docs/agent-guide and the approved implementation plan. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
56
resources/js/worker.js
Normal file
56
resources/js/worker.js
Normal file
@@ -0,0 +1,56 @@
|
||||
importScripts(
|
||||
// Batched optimization
|
||||
"./lightning-fs.min.js",
|
||||
// Fixed a bug
|
||||
"./magic_portal.js"
|
||||
);
|
||||
|
||||
const detect = () => {
|
||||
if (typeof window !== 'undefined' && !self.skipWaiting) {
|
||||
return 'window'
|
||||
} else if (typeof self !== 'undefined' && !self.skipWaiting) {
|
||||
return 'Worker'
|
||||
} else if (typeof self !== 'undefined' && self.skipWaiting) {
|
||||
return 'ServiceWorker'
|
||||
}
|
||||
};
|
||||
|
||||
const fsName = 'logseq';
|
||||
const createFS = () => new LightningFS(fsName);
|
||||
let fs = createFS();
|
||||
let pfs = fs.promises;
|
||||
|
||||
if (typeof self !== 'undefined') {
|
||||
self.fs = fs;
|
||||
self.pfs = pfs;
|
||||
}
|
||||
|
||||
if (detect() === 'Worker') {
|
||||
const portal = new MagicPortal(self);
|
||||
portal.set('fs', fs);
|
||||
portal.set('pfs', pfs);
|
||||
|
||||
portal.set('workerThread', {
|
||||
rimraf: async function (path) {
|
||||
// Knowing path is a directory,
|
||||
// first, assume everything inside path is a file.
|
||||
let files = await pfs.readdir(path);
|
||||
for (let file of files) {
|
||||
let child = path + '/' + file
|
||||
try {
|
||||
await pfs.unlink(child)
|
||||
} catch (err) {
|
||||
if (err.code !== 'EISDIR') throw err
|
||||
}
|
||||
}
|
||||
// Assume what's left are directories and recurse.
|
||||
let dirs = await pfs.readdir(path)
|
||||
for (let dir of dirs) {
|
||||
let child = path + '/' + dir
|
||||
await rimraf(child, pfs)
|
||||
}
|
||||
// Finally, delete the empty directory
|
||||
await pfs.rmdir(path)
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user