Make Puter.js verbosity optional via debug flag.

This commit is contained in:
Nariman Jelveh 2024-04-13 17:31:29 -07:00
parent 965d99d137
commit 255e80d077
5 changed files with 21 additions and 12 deletions

View File

@ -48,6 +48,9 @@ window.puter = (function() {
// Event handling properties
eventHandlers = {};
// debug flag
debugMode = false;
// --------------------------------------------
// Constructor
// --------------------------------------------
@ -307,7 +310,6 @@ window.puter = (function() {
}
}
// Create a new Puter object and return it
const puterobj = new Puter();

View File

@ -69,7 +69,6 @@ class AI{
testMode = true;
}
console.log(args, options);
return await utils.make_driver_method(['source'], 'puter-ocr', 'recognize', {
test_mode: testMode ?? false,
transform: async (result) => {

View File

@ -75,31 +75,38 @@ class FileSystem{
bindSocketEvents() {
this.socket.on('connect', () => {
console.log('FileSystem Socket: Connected', this.socket.id);
if(puter.debugMode)
console.log('FileSystem Socket: Connected', this.socket.id);
});
this.socket.on('disconnect', () => {
console.log('FileSystem Socket: Disconnected');
if(puter.debugMode)
console.log('FileSystem Socket: Disconnected');
});
this.socket.on('reconnect', (attempt) => {
console.log('FileSystem Socket: Reconnected', this.socket.id);
if(puter.debugMode)
console.log('FileSystem Socket: Reconnected', this.socket.id);
});
this.socket.on('reconnect_attempt', (attempt) => {
console.log('FileSystem Socket: Reconnection Attemps', attempt);
if(puter.debugMode)
console.log('FileSystem Socket: Reconnection Attemps', attempt);
});
this.socket.on('reconnect_error', (error) => {
console.log('FileSystem Socket: Reconnection Error', error);
if(puter.debugMode)
console.log('FileSystem Socket: Reconnection Error', error);
});
this.socket.on('reconnect_failed', () => {
console.log('FileSystem Socket: Reconnection Failed');
if(puter.debugMode)
console.log('FileSystem Socket: Reconnection Failed');
});
this.socket.on('error', (error) => {
console.error('FileSystem Socket Error:', error);
if(puter.debugMode)
console.error('FileSystem Socket Error:', error);
});
}

View File

@ -386,7 +386,8 @@ const upload = async function(items, dirPath, options = {}){
else{
if(!resp || !resp.results || resp.results.length === 0){
// no results
console.log('no results');
if(puter.debugMode)
console.log('no results');
}
let items = resp.results;

View File

@ -120,7 +120,8 @@ window.fsTests = [
throw("testFSWrite failed to delete file:", error);
}
} catch (error) {
console.log(error);
if(puter.debugMode)
console.log(error);
throw("testFSWrite failed:", error);
}
},
@ -598,7 +599,6 @@ window.fsTests = [
let randName = puter.randName();
for(let i = 0; i < naughtyStrings.length; i++) {
let filename = randName + naughtyStrings[i];
console.log(filename);
let result = await puter.fs.write(filename, 'testValue');
assert(result.uid, "Failed to write to file");
// check name