mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-30 21:23:04 +00:00
Reuse verified host-scoped plugin bundles across client launches and reconstruct complete catalogs when unchanged code is omitted. Keep store ownership on the connected client, including adopted bootstrap clients, and persist in the background with bounded writes. Remove catalog catch-up deferral and fix repeated timeline preparation that promoted cached completed history into a live head. This preserves completed plugin-rendered chat when catalog installation precedes timeline catch-up. Carries forward #6732 on an upstream branch, with the original hash/cache contribution and integration attribution preserved. Co-authored-by: luke <luopeihuan@gmail.com> Co-authored-by: RoundRedDot <roundreddot@gmail.com>
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import * as FileSystem from "expo-file-system/legacy";
|
|
import { CryptoDigestAlgorithm, digestStringAsync, randomUUID } from "expo-crypto";
|
|
import { createPluginClientBundleStore } from "./store";
|
|
|
|
export function createHostPluginClientBundleStore(serverId: string) {
|
|
const directory = `${FileSystem.cacheDirectory}plugin-client-bundles/${encodeURIComponent(serverId)}/`;
|
|
const ensureDirectory = async () => {
|
|
if (!FileSystem.cacheDirectory) throw new Error("Plugin bundle cache directory unavailable");
|
|
await FileSystem.makeDirectoryAsync(directory, { intermediates: true });
|
|
};
|
|
return createPluginClientBundleStore(
|
|
{
|
|
async list() {
|
|
await ensureDirectory();
|
|
return FileSystem.readDirectoryAsync(directory);
|
|
},
|
|
read: (name) => FileSystem.readAsStringAsync(`${directory}${name}`),
|
|
async writeAtomic(name, contents) {
|
|
await ensureDirectory();
|
|
const temporary = `${directory}${randomUUID()}.tmp`;
|
|
try {
|
|
await FileSystem.writeAsStringAsync(temporary, contents);
|
|
await FileSystem.moveAsync({ from: temporary, to: `${directory}${name}` });
|
|
} finally {
|
|
await FileSystem.deleteAsync(temporary, { idempotent: true });
|
|
}
|
|
},
|
|
remove: (name) => FileSystem.deleteAsync(`${directory}${name}`, { idempotent: true }),
|
|
},
|
|
(contents) => digestStringAsync(CryptoDigestAlgorithm.SHA256, contents),
|
|
);
|
|
}
|