Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline (Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/* packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { File, Paths } from "expo-file-system";
|
|
import * as Sharing from "expo-sharing";
|
|
import { rpc } from "./api";
|
|
import { artifactCacheFileName } from "./artifact-file";
|
|
import { t } from "./i18n";
|
|
|
|
export type MobileArtifactTarget = { botId: string } | { groupId: string };
|
|
|
|
async function cacheMobileArtifact(
|
|
target: MobileArtifactTarget,
|
|
artifactId: string,
|
|
mimeType: string,
|
|
): Promise<File> {
|
|
const artifact = await rpc<{ contentBase64: string }>("artifacts/get", {
|
|
...target,
|
|
artifactId,
|
|
});
|
|
const file = new File(Paths.cache, artifactCacheFileName(artifactId, mimeType));
|
|
file.create({ overwrite: true });
|
|
file.write(artifact.contentBase64, { encoding: "base64" });
|
|
return file;
|
|
}
|
|
|
|
export async function readMobileArtifactText(
|
|
target: MobileArtifactTarget,
|
|
artifactId: string,
|
|
mimeType: string,
|
|
): Promise<string> {
|
|
const file = await cacheMobileArtifact(target, artifactId, mimeType);
|
|
return file.text();
|
|
}
|
|
|
|
export async function openMobileArtifact(
|
|
target: MobileArtifactTarget,
|
|
artifactId: string,
|
|
name: string,
|
|
mimeType: string,
|
|
): Promise<void> {
|
|
const file = await cacheMobileArtifact(target, artifactId, mimeType);
|
|
if (await Sharing.isAvailableAsync()) {
|
|
await Sharing.shareAsync(file.uri, { mimeType });
|
|
return;
|
|
}
|
|
throw new Error(t("Saved {name} locally", { name }));
|
|
}
|