2026-01-24 14:43:58 +01:00
import { __ , FORBIDDEN_CARS , I } from "./globals" ;
2026-01-13 19:15:47 +01:00
import { DropContainer } from "./class-drop-container" ;
2026-01-24 14:43:58 +01:00
declare const _romhackplaza_script_uploader : any ;
declare const romhackplaza_modal_submissions : any ;
2026-01-13 19:15:47 +01:00
export class Upload {
file : File ;
2026-01-24 14:43:58 +01:00
progress_bar : HTMLElement | undefined ;
2026-01-13 19:15:47 +01:00
constructor ( file : File ) {
this . file = file ;
this . beginUpload ( ) ;
}
private beginUpload ( ) {
if ( this . checkForbiddenCars ( ) ) {
romhackplaza_manage_modal ( romhackplaza_modal_submissions , "block" , __ ( "Submit error" , 'romhackplaza' ) , __ ( "There is a forbidden character in the file name, please change it." , 'romhackplaza' ) , "" ) ;
return ;
}
if ( ! this . file ) {
console . error ( "WTF at beginUpload method." ) ;
return ;
}
2026-01-24 14:43:58 +01:00
2026-01-13 19:15:47 +01:00
this . switchDuringUpload ( ) ;
if ( typeof I . drop_container !== 'undefined' && I . drop_container instanceof DropContainer )
I . drop_container . switch ( ) ;
2026-01-24 14:43:58 +01:00
let progress = document . getElementById ( 'progress' ) ;
if ( progress !== null ) {
progress . style . display = 'block' ;
this . progress_bar = progress . querySelector ( '.bar' ) as HTMLElement ;
}
if ( I . reserved_post_id === undefined || I . reserved_post_id === null )
console . log ( "ok" ) ;
2026-01-13 19:15:47 +01:00
}
checkForbiddenCars ( ) : boolean {
// @ts-ignore
for ( let char : string of FORBIDDEN_CARS ) {
if ( this . file . name . includes ( char ) )
return true ;
}
return false ;
}
private switchDuringUpload ( ) : void {
// @ts-ignore
2026-01-24 14:43:58 +01:00
I . during_upload = ! I . during_upload ;
this . changeStatus ( __ ( "Preparing upload..." , 'romhackplaza' ) ) ;
2026-01-13 19:15:47 +01:00
this . switchSubmissionButton ( ) ;
}
2026-01-24 14:43:58 +01:00
private changeStatus ( str : string ) {
let sts : HTMLElement | null = document . getElementById ( 'status' ) ;
if ( sts !== null )
sts . textContent = str ;
}
2026-01-13 19:15:47 +01:00
private switchSubmissionButton ( ) : void {
let btn : HTMLElement | null = document . getElementById ( 'submitTranslationButton' ) ;
if ( btn !== null ) {
let conv_btn = btn as HTMLButtonElement ;
if ( conv_btn . disabled ) {
conv_btn . disabled = false ;
conv_btn . innerText = __ ( 'Submit Entry' , 'romhackplaza' ) ;
} else {
conv_btn . disabled = true ;
conv_btn . innerText = __ ( 'Wait for upload...' , 'romhackplaza' ) ;
}
}
}
}