src/app/www/js/functions.js
/**
 * Saves the current editor code as a file inside ESP32 through an API SAVE 
 * call.
 * @param {String} filename 
 */
Saves the current editor code as a file inside ESP32 through an API SAVE
call.
@param {String} filename
Saves the current editor code as a file inside ESP32 through an API SAVE call . @param { String } filename
async function saveScript(filename) {
    if(!filename) {
        return;
    }
    if(!filename.startsWith("/")) {
        filename = "/" + filename;
    }
    hideOptionsMenu();
    status.filename = filename;
    const preProcessedCode = preProcessCode(editor.getValue());
    const form = API.createRequestForm({
        Filename: filename
    });
    if(API.getActiveModule() == API.Module.BLUETOOTH) {
        form.append("File-Bytes", preProcessedCode);
    }
    else {
        const file = new File([preProcessedCode], filename, {
            type: "text/plain",
        });
        form.append("Script-File", file);
    }
    return API.call(API.Resource.SAVE, form)
              .then(() => {
                   status.lastVersion = editor.getValue();
                   status.isSaved = true;
                   const options = ID("filename-open").options;
                   if(!Array.from(options).find(el => el.value == filename)) {
                       options.add(new Option(filename, filename));
                   }
              })
              .catch(() => {});
}
async function saveScript ( filename ) { if ( ! filename ) { return ; } if ( ! filename . startsWith ( "/" ) ) { filename = "/" + filename ; } hideOptionsMenu ( ) ; status . filename = filename ; const preProcessedCode = preProcessCode ( editor . getValue ( ) ) ; const form = API . createRequestForm ( { Filename : filename } ) ; if ( API . getActiveModule ( ) == API . Module . BLUETOOTH ) { form . append ( "File-Bytes" , preProcessedCode ) ; } else { const file = new File ( [ preProcessedCode ] , filename , { type : "text/plain" , } ) ; form . append ( "Script-File" , file ) ; } return API . call ( API . Resource . SAVE , form ) . then ( ( ) => { status . lastVersion = editor . getValue ( ) ; status . isSaved = true ; const options = ID ( "filename-open" ) . options ; if ( ! Array . from ( options ) . find ( el => el . value == filename ) ) { options . add ( new Option ( filename , filename ) ) ; } } ) . catch ( ( ) => { } ) ; }
Saves the current editor code as a file inside ESP32 through an API SAVE
 call.
Saves the current editor code as a file inside ESP32 through an API SAVE call .
// update filename-open options