@@ -24,7 +24,7 @@ import * as commonStorage from './common_storage';
2424
2525const API_BASE_URL = 'http://localhost:5001' ;
2626
27- async function isServerAvailable ( ) : Promise < boolean > {
27+ export async function isServerAvailable ( ) : Promise < boolean > {
2828 try {
2929 // Create a timeout promise
3030 const timeoutPromise = new Promise < never > ( ( _ , reject ) => {
@@ -33,7 +33,7 @@ async function isServerAvailable(): Promise<boolean> {
3333
3434 // Race between the fetch and timeout
3535 const response = await Promise . race ( [
36- fetch ( `${ API_BASE_URL } /` , { method : 'GET' } ) ,
36+ fetch ( `${ API_BASE_URL } /` ) ,
3737 timeoutPromise
3838 ] ) ;
3939
@@ -44,7 +44,7 @@ async function isServerAvailable(): Promise<boolean> {
4444 }
4545}
4646
47- class ServerSideStorage implements commonStorage . Storage {
47+ export class ServerSideStorage implements commonStorage . Storage {
4848
4949 async saveEntry ( entryKey : string , entryValue : string ) : Promise < void > {
5050 const response = await fetch ( `${ API_BASE_URL } /entries/${ encodeURIComponent ( entryKey ) } ` , {
@@ -86,27 +86,6 @@ class ServerSideStorage implements commonStorage.Storage {
8686 }
8787
8888 async rename ( oldPath : string , newPath : string ) : Promise < void > {
89- if ( oldPath . endsWith ( '/' ) ) {
90- return this . renameDirectory ( oldPath , newPath ) ;
91- }
92- return this . renameFile ( oldPath , newPath ) ;
93- }
94-
95- private async renameDirectory ( oldPath : string , newPath : string ) : Promise < void > {
96- const response = await fetch ( `${ API_BASE_URL } /storage/rename` , {
97- method : 'POST' ,
98- headers : {
99- 'Content-Type' : 'application/json' ,
100- } ,
101- body : JSON . stringify ( { old_path : oldPath , new_path : newPath } ) ,
102- } ) ;
103-
104- if ( ! response . ok ) {
105- throw new Error ( `Failed to rename directory: ${ response . statusText } ` ) ;
106- }
107- }
108-
109- private async renameFile ( oldPath : string , newPath : string ) : Promise < void > {
11089 const response = await fetch ( `${ API_BASE_URL } /storage/rename` , {
11190 method : 'POST' ,
11291 headers : {
@@ -116,7 +95,7 @@ class ServerSideStorage implements commonStorage.Storage {
11695 } ) ;
11796
11897 if ( ! response . ok ) {
119- throw new Error ( `Failed to rename file : ${ response . statusText } ` ) ;
98+ throw new Error ( `Failed to rename: ${ response . statusText } ` ) ;
12099 }
121100 }
122101
@@ -149,34 +128,12 @@ class ServerSideStorage implements commonStorage.Storage {
149128 }
150129
151130 async delete ( path : string ) : Promise < void > {
152- if ( path . endsWith ( '/' ) ) {
153- return this . deleteDirectory ( path ) ;
154- }
155- return this . deleteFile ( path ) ;
156- }
157-
158- private async deleteDirectory ( path : string ) : Promise < void > {
159131 const response = await fetch ( `${ API_BASE_URL } /storage/${ encodeURIComponent ( path ) } ` , {
160132 method : 'DELETE' ,
161133 } ) ;
162134
163135 if ( ! response . ok ) {
164- throw new Error ( `Failed to delete directory : ${ response . statusText } ` ) ;
136+ throw new Error ( `Failed to delete: ${ response . statusText } ` ) ;
165137 }
166138 }
167-
168- private async deleteFile ( filePath : string ) : Promise < void > {
169- const response = await fetch ( `${ API_BASE_URL } /storage/${ encodeURIComponent ( filePath ) } ` , {
170- method : 'DELETE' ,
171- } ) ;
172-
173- if ( ! response . ok ) {
174- if ( response . status === 404 ) {
175- throw new Error ( `File not found: ${ filePath } ` ) ;
176- }
177- throw new Error ( `Failed to delete file: ${ response . statusText } ` ) ;
178- }
179- }
180- }
181-
182- export { ServerSideStorage , isServerAvailable } ;
139+ }
0 commit comments