11import { 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.
411export 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