Files
Romhack-Plaza---WordPress-P…/ts/submissions/class-server-api.ts
Benjamin f34019c802 Continue Upload Script.
Pause during rewrite of RHPZ Server code.
2026-01-29 18:49:47 +01:00

50 lines
1.3 KiB
TypeScript

import { __, I } from "./globals";
export class Server_Api {
url: string|undefined;
id: number|undefined;
init( server_url: string, server_id: number ){
this.url = server_url;
this.id = server_id;
}
is_init(): boolean {
return this.url !== undefined && this.id !== undefined;
}
private build_url( call: string ): string {
let new_url: string = this.url + "upload.php";
if( call === "check_existence" )
new_url += "?checkExistence=true";
return new_url;
}
async check_file_existence( filename: string ): Promise<boolean> {
return new Promise( ( resolve, reject ) => {
const XHR: XMLHttpRequest = new XMLHttpRequest();
XHR.open( 'POST', this.build_url( 'check_existence' ), true );
let form_data: FormData = new FormData();
form_data.append( "filename", filename );
form_data.append( 'reservedPostID', I.reserved_post_id );
form_data.append( 'custom_post_type', I.custom_post_type );
XHR.onload = () => {
resolve( XHR.responseText === 'exists' );
}
XHR.onerror = () => {
reject( false );
}
XHR.send( form_data );
});
}
}