Continue Upload Script.

Pause during rewrite of RHPZ Server code.
This commit is contained in:
2026-01-29 18:49:47 +01:00
parent f029371a68
commit f34019c802
9 changed files with 210 additions and 7 deletions

View File

@@ -0,0 +1,50 @@
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 );
});
}
}