mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-23 00:53:38 +02:00
Polish plugin local folder host utilities
This commit is contained in:
1 parent
4de53ef96f
commit
667102c1a8
4 files changed
+23
-4
No files matched your search
@@ -10,6 +10,7 @@ import {
|
||||
preparePluginLocalFolder,
|
||||
readPluginLocalFolderText,
|
||||
resolvePluginLocalFolderPath,
|
||||
deletePluginLocalFolderFile,
|
||||
writePluginLocalFolderTextAtomic,
|
||||
} from "../services/plugin-local-folders.js";
|
||||
|
||||
@@ -218,6 +219,16 @@ describe("plugin local folders", () => {
|
||||
expect(leftovers.filter((name) => name.includes(".paperclip-"))).toEqual([]);
|
||||
});
|
||||
|
||||
it("returns the real folder key after deleting a file", async () => {
|
||||
const root = await makeRoot();
|
||||
await fs.writeFile(path.join(root, "stale.md"), "delete me", "utf8");
|
||||
|
||||
const status = await deletePluginLocalFolderFile(root, "stale.md", "content-root");
|
||||
|
||||
expect(status.folderKey).toBe("content-root");
|
||||
await expect(fs.stat(path.join(root, "stale.md"))).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
|
||||
it("lists nested local folder entries without following symlink escapes", async () => {
|
||||
const root = await makeRoot();
|
||||
const outside = await makeRoot();
|
||||
|
||||
@@ -25,8 +25,15 @@ export {
|
||||
resolvePaperclipSpaceRoot,
|
||||
};
|
||||
|
||||
const defaultConfigPathCache = new Map<string, string>();
|
||||
|
||||
export function resolveDefaultConfigPath(): string {
|
||||
return resolvePaperclipConfigPathForInstance();
|
||||
const cacheKey = `${process.env.PAPERCLIP_HOME ?? ""}\0${process.env.PAPERCLIP_INSTANCE_ID ?? ""}`;
|
||||
const cached = defaultConfigPathCache.get(cacheKey);
|
||||
if (cached) return cached;
|
||||
const resolved = resolvePaperclipConfigPathForInstance();
|
||||
defaultConfigPathCache.set(cacheKey, resolved);
|
||||
return resolved;
|
||||
}
|
||||
|
||||
export function resolveDefaultEmbeddedPostgresDir(): string {
|
||||
|
||||
@@ -897,7 +897,7 @@ export function buildHostServices(
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
const status = await inspectStoredLocalFolder(companyId, params.folderKey);
|
||||
assertWritableConfiguredLocalFolder(status);
|
||||
await deletePluginLocalFolderFile(status.realPath!, params.relativePath);
|
||||
await deletePluginLocalFolderFile(status.realPath!, params.relativePath, params.folderKey);
|
||||
return inspectStoredLocalFolder(companyId, params.folderKey);
|
||||
},
|
||||
},
|
||||
|
||||
@@ -541,6 +541,7 @@ export async function writePluginLocalFolderTextAtomic(
|
||||
export async function deletePluginLocalFolderFile(
|
||||
rootPath: string,
|
||||
relativePath: string,
|
||||
folderKey: string,
|
||||
) {
|
||||
const rootRealPath = await fs.realpath(rootPath);
|
||||
let resolved: Awaited<ReturnType<typeof resolvePluginLocalFolderPath>>;
|
||||
@@ -553,7 +554,7 @@ export async function deletePluginLocalFolderFile(
|
||||
const code = typeof error === "object" && error && "code" in error ? String((error as { code?: unknown }).code) : "";
|
||||
if (code !== "ENOENT") throw error;
|
||||
return inspectPluginLocalFolder({
|
||||
folderKey: "delete-result",
|
||||
folderKey,
|
||||
storedConfig: {
|
||||
path: rootPath,
|
||||
access: "readWrite",
|
||||
@@ -578,7 +579,7 @@ export async function deletePluginLocalFolderFile(
|
||||
}
|
||||
|
||||
return inspectPluginLocalFolder({
|
||||
folderKey: "delete-result",
|
||||
folderKey,
|
||||
storedConfig: {
|
||||
path: rootPath,
|
||||
access: "readWrite",
|
||||
|
||||
Reference in new issue
Block a user