fix image urls, fix context menu

This commit is contained in:
Nystik
2026-03-10 20:49:10 +01:00
parent b48ef720b8
commit d8d12054b7
9 changed files with 157 additions and 39 deletions

View File

@@ -10,8 +10,10 @@ export function createFsSync(metadataCache, contentCache, transport) {
statSync(path) {
const stat = metadataCache.toStat(path);
if (!stat) {
const err = new Error(`ENOENT: no such file or directory, stat '${path}'`);
err.code = 'ENOENT';
const err = new Error(
`ENOENT: no such file or directory, stat '${path}'`,
);
err.code = "ENOENT";
throw err;
}
return stat;
@@ -19,39 +21,52 @@ export function createFsSync(metadataCache, contentCache, transport) {
accessSync(path, mode) {
if (!metadataCache.has(path)) {
const err = new Error(`ENOENT: no such file or directory, access '${path}'`);
err.code = 'ENOENT';
const err = new Error(
`ENOENT: no such file or directory, access '${path}'`,
);
err.code = "ENOENT";
throw err;
}
},
readFileSync(path, encoding) {
if (typeof encoding === 'object') encoding = encoding?.encoding;
if (typeof encoding === "object") encoding = encoding?.encoding;
// Short-circuit: reading a directory is an error
const meta = metadataCache.get(path);
if (meta && meta.type === "directory") {
const e = new Error("EISDIR: illegal operation on a directory, read");
e.code = "EISDIR";
throw e;
}
// Try content cache first
const cached = contentCache.get(path);
if (cached !== null) {
if (encoding === 'utf8' || encoding === 'utf-8') {
return typeof cached === 'string' ? cached : new TextDecoder().decode(cached);
if (encoding === "utf8" || encoding === "utf-8") {
return typeof cached === "string"
? cached
: new TextDecoder().decode(cached);
}
return cached;
}
// Fallback: synchronous XHR
console.warn('[shim:fs] readFileSync cache miss, using sync XHR:', path);
console.warn("[shim:fs] readFileSync cache miss, using sync XHR:", path);
const data = transport.readFileSync(path, encoding);
contentCache.set(path, data);
return data;
},
writeFileSync(path, data, encoding) {
if (typeof encoding === 'object') encoding = encoding?.encoding;
if (typeof encoding === "object") encoding = encoding?.encoding;
// Write to cache immediately (sync return)
contentCache.set(path, data);
const size = typeof data === 'string' ? data.length : (data.byteLength || 0);
const size =
typeof data === "string" ? data.length : data.byteLength || 0;
metadataCache.set(path, {
type: 'file',
type: "file",
size,
mtime: Date.now(),
ctime: metadataCache.get(path)?.ctime || Date.now(),
@@ -59,7 +74,11 @@ export function createFsSync(metadataCache, contentCache, transport) {
// Fire-and-forget async send to server
transport.writeFile(path, data, encoding).catch((e) => {
console.error('[shim:fs] writeFileSync background save failed:', path, e);
console.error(
"[shim:fs] writeFileSync background save failed:",
path,
e,
);
});
},
@@ -67,15 +86,21 @@ export function createFsSync(metadataCache, contentCache, transport) {
contentCache.delete(path);
metadataCache.delete(path);
// Fire-and-forget
// Fire-and-forget - suppress ENOENT (file already gone, e.g. .OBSIDIANTEST race)
transport.unlink(path).catch((e) => {
console.error('[shim:fs] unlinkSync background delete failed:', path, e);
if (e.code !== "ENOENT") {
console.error(
"[shim:fs] unlinkSync background delete failed:",
path,
e,
);
}
});
},
readdirSync(path) {
const entries = metadataCache.readdir(path);
return entries.map(e => e.name);
return entries.map((e) => e.name);
},
};
}