Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.

Commit 5ab881d

Browse files
committed
Verify editor save by reading back content
1 parent aa52000 commit 5ab881d

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

src/api/files.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { APIError, fetchApiText } from ".";
22

3+
const editUrl = (filename: string): string => {
4+
const urlSearchParams = new URLSearchParams({
5+
configuration: filename,
6+
});
7+
return `./edit?${urlSearchParams.toString()}`;
8+
};
9+
310
// null if file not found.
411
export const getFile = async (filename: string): Promise<string | null> => {
512
try {
6-
const urlSearchParams = new URLSearchParams({
7-
configuration: filename,
8-
});
9-
return fetchApiText(`./edit?${urlSearchParams.toString()}`);
13+
return fetchApiText(editUrl(filename), { cache: "no-store" });
1014
} catch (err) {
1115
if (err instanceof APIError && err.status === 404) {
1216
return null;
@@ -19,11 +23,18 @@ export const writeFile = async (
1923
filename: string,
2024
content: string,
2125
): Promise<string> => {
22-
const urlSearchParams = new URLSearchParams({
23-
configuration: filename,
24-
});
25-
return fetchApiText(`./edit?${urlSearchParams.toString()}`, {
26+
const url = editUrl(filename);
27+
await fetchApiText(url, {
2628
method: "POST",
2729
body: content,
30+
cache: "no-store",
2831
});
32+
33+
const savedContent = await fetchApiText(url, { cache: "no-store" });
34+
if (savedContent !== content) {
35+
throw new Error(
36+
"Save verification failed: saved content does not match editor content",
37+
);
38+
}
39+
return savedContent;
2940
};

0 commit comments

Comments
 (0)