Added Download file, play for homebrews and ZIP explorer.

This commit is contained in:
2026-06-16 18:35:01 +02:00
parent 7e1e26f20b
commit 279160c1cb
12 changed files with 215 additions and 24 deletions

View File

@@ -0,0 +1,43 @@
window.PlayOnline = function( filePath = "", emulatorJsConfig = {} ){
return {
fileUrl: filePath,
emuConfig: emulatorJsConfig,
init(){
this.launchEmulatorJs();
},
cleanEmulatorJsVars() {
['EJS_player','EJS_core','EJS_gameUrl','EJS_pathtodata',
'EJS_startOnLoaded','EJS_threads']
.forEach(k => delete window[k]);
},
prepareEmulatorJs(){
window.EJS_player = '#game';
window.EJS_core = this.emuConfig.core;
window.EJS_gameUrl = this.filePath;
window.EJS_pathtodata = "https://cdn.emulatorjs.org/stable/data/";
window.EJS_startOnLoaded = true;
window.EJS_threads = this.emuConfig.threads ?? false;
},
launchEmulatorJs(){
this.cleanEmulatorJsVars();
this.prepareEmulatorJs();
const script = document.createElement('script');
script.id = 'ejs-loader';
script.src = 'https://cdn.emulatorjs.org/stable/data/loader.js';
document.body.appendChild(script);
this.launchGame = true;
}
}
}

View File

@@ -1,6 +1,6 @@
/** @typedef { import('types/UploadchunkResponse.js').UploadchunkResponse} UploadchunkResponse */
export const CHUNK_SIZE = 8192;
export const CHUNK_SIZE = 8192 * 1024;
const PATCH_EXTENSIONS = new Set([
'ips', 'bps', 'ups', 'aps', 'ppf', 'xdelta', "zip"
@@ -72,6 +72,15 @@ export function FSFileData(name, totalChunks, rawFile ) {
*/
state: 'public',
file_explorer: null,
file_explorer_files: null,
/**
* For files already uploaded, download URL.
*/
download_url: null,
can_be_online_patched: PATCH_EXTENSIONS.has(extension),
/**

View File

@@ -105,6 +105,29 @@ export function FSUploader(){
},
handleDownloadFile( index ){
let download_url = this.files[index].download_url;
window.location.href = download_url;
},
async handleFileExplorer( index ){
if( this.files[index].file_explorer_files !== null )
return;
let file_explorer_url = this.files[index].file_explorer;
let response = await fetch(file_explorer_url, { method: 'GET', headers: { 'Content-Type': 'application/json' } });
let json = await response.json();
if( !json.files ){
this.files[index].file_explorer_files = [ "An error occurred during request" ];
return;
}
this.files[index].file_explorer_files = json.files;
},
/**
* Retry file uploading.
*
@@ -126,6 +149,8 @@ export function FSUploader(){
* @param {number} index FSFileData index in this.files.
*/
handleRemoveFile( index ){
if( this.files[index].state === 'archived')
return;
this.files.splice(index, 1);
},