442 lines
12 KiB
JavaScript
442 lines
12 KiB
JavaScript
async function api_token_request_async(axios, secret_key) {
|
|
console.log('****************** API Token Request ******************');
|
|
console.log('Requesting API temporary token...');
|
|
|
|
if (waiting_on_api_token) {
|
|
console.log('Already waiting on an API token request. Not starting another until finished.');
|
|
return false;
|
|
} else {
|
|
waiting_on_api_token = true;
|
|
|
|
const url = '/api_token_request';
|
|
|
|
let data = { secret_key: secret_key };
|
|
|
|
const result = await axios.post(url, data)
|
|
.then(function (response) {
|
|
//console.log(response);
|
|
const api_temporary_token = response.data.temporary_token;
|
|
//console.log('API Temporary Token: '+temporary_token);
|
|
return api_temporary_token;
|
|
})
|
|
.catch(function (error) {
|
|
console.error(error);
|
|
return false;
|
|
});
|
|
|
|
waiting_on_api_token = false;
|
|
return result;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
async function get_event_details(axios, event_id) {
|
|
console.log('Requesting event details...');
|
|
const url = '/event/'+event_id;
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
//console.log(response.data);
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function get_event_location_details(axios, event_id, event_location_id) {
|
|
console.log('Requesting event location details...');
|
|
const url = '/event/'+event_id+'/location/'+event_location_id;
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
//console.log(response.data);
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function get_event_location_sessions(axios, event_id, event_location_id) {
|
|
console.log('Requesting location sessions...');
|
|
const url = '/event/'+event_id+'/location/'+event_location_id+'/session';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
//console.log(response.data);
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function get_session_presentations(axios, event_id, event_session_id) {
|
|
console.log('Requesting session presentations...');
|
|
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
//console.log(response.data);
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function get_presentation_presenters(axios, event_id, event_session_id, event_presentation_id) {
|
|
console.log('Requesting presentation presenters...');
|
|
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation/'+event_presentation_id+'/presenter';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
//console.log(response.data);
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function get_files_for_type_for_id(axios, for_type, for_id) {
|
|
console.log('Requesting files for '+for_type+' '+for_id);
|
|
const url = '/event/file/'+for_type+'/'+for_id;
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
//console.log(response.data);
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
/*
|
|
async function download_file_id(axios, file_id, filename) {
|
|
|
|
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // in render thread
|
|
|
|
console.log('1: download file id '+file_id);
|
|
const url = '/event/file/'+file_id+'/download';
|
|
|
|
//const data = await axios.get(url, responseType: 'stream')
|
|
const data = await axios({
|
|
method: "get",
|
|
url: url,
|
|
responseType: "stream"
|
|
})
|
|
.then(function (response) {
|
|
console.log('2: downloaded file id '+file_id);
|
|
console.log(response);
|
|
//console.log(response.data);
|
|
|
|
let filename = 'default.txt';
|
|
|
|
if (typeof filename_override === 'undefined' || filename_override == null) {
|
|
let headerLine = response.data.headers['content-disposition'];
|
|
|
|
console.log(headerLine);
|
|
console.log(headerLine.indexOf('="'));
|
|
console.log(headerLine.indexOf('='));
|
|
if (headerLine.indexOf('="') != -1) {
|
|
let startFileNameIndex = headerLine.indexOf('="') + 2;
|
|
let endFileNameIndex = headerLine.lastIndexOf('"');
|
|
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
|
|
} else if (headerLine.indexOf('=') != -1) {
|
|
let startFileNameIndex = headerLine.indexOf('=') + 1;
|
|
let endFileNameIndex = headerLine.length;
|
|
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
|
|
} else {
|
|
filename = 'filename_not_found_in_header.txt';
|
|
}
|
|
} else {
|
|
filename = filename_override;
|
|
}
|
|
|
|
let directory = 'file_cache/';
|
|
|
|
directory_and_filename = path.join(directory, filename);
|
|
|
|
//console.log(directory_and_filename);
|
|
|
|
if (fs.existsSync(directory_and_filename)) {
|
|
console.log('3a: file already exists: '+directory_and_filename);
|
|
} else {
|
|
console.log('3b: saving file: '+directory_and_filename);
|
|
response.data.pipe(fs.createWriteStream(directory_and_filename));
|
|
}
|
|
//data = response.data;
|
|
console.log('4: saved file id '+file_id);
|
|
return true;
|
|
//return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
//return data;
|
|
}
|
|
*/
|
|
|
|
/* v2 Section */
|
|
|
|
async function v2_get_account_events(axios, account_id) {
|
|
console.log('Requesting account events...');
|
|
const url = '/v2/account/'+account_id+'/events';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 account events data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 account events data: ^^^');
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function v2_get_event_locations(axios, event_id) {
|
|
console.log('Requesting event locations...');
|
|
const url = '/v2/event/'+event_id+'/event_locations';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 event locations data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 event locations data: ^^^');
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function v2_get_event_sessions(axios, event_id) {
|
|
console.log('Requesting event sessions...');
|
|
const url = '/v2/event/'+event_id+'/event_sessions';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 location sessions data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 location sessions data: ^^^');
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
|
|
async function v2_get_event_location_sessions(axios, event_location_id) {
|
|
console.log('Requesting location sessions...');
|
|
const url = '/v2/event_location/'+event_location_id+'/event_sessions';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 location sessions data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 location sessions data: ^^^');
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function v2_get_event_location_presentations(axios, event_location_id) {
|
|
console.log('Requesting location presentations...');
|
|
const url = '/v2/event_location/'+event_location_id+'/event_presentations';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 location presentations data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 location presentations data: ^^^');
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function v2_get_event_location_presenters(axios, event_location_id) {
|
|
console.log('Requesting location presenters...');
|
|
const url = '/v2/event_location/'+event_location_id+'/event_presenters';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 location presenters data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 location presenters data: ^^^');
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function v2_get_event_files(axios, event_id) {
|
|
console.log('Requesting event files...');
|
|
const url = '/v2/event/'+event_id+'/event_files';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 location files data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 location files data: ^^^');
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function v2_get_event_location_files(axios, event_location_id) {
|
|
console.log('Requesting location files...');
|
|
const url = '/v2/event_location/'+event_location_id+'/event_files';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 location files data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 location files data: ^^^');
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function v2_get_event_location_files_sessions(axios, event_location_id) {
|
|
console.log('Requesting all session files for a location...');
|
|
const url = '/v2/event_location/'+event_location_id+'/event_files/sessions';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 location files data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 location files data: ^^^');
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function v2_get_event_location_files_presentations(axios, event_location_id) {
|
|
console.log('Requesting all presentation files for a location...');
|
|
const url = '/v2/event_location/'+event_location_id+'/event_files/presentations';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 location files data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 location files data: ^^^');
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
async function v2_get_event_location_files_presenters(axios, event_location_id) {
|
|
console.log('Requesting all presenter files for a location...');
|
|
const url = '/v2/event_location/'+event_location_id+'/event_files/presenters';
|
|
|
|
const data = await axios.get(url)
|
|
.then(function (response) {
|
|
console.log('v2 location files data: ***');
|
|
console.log(response.data);
|
|
console.log('v2 location files data: ^^^');
|
|
//data = response.data;
|
|
return response.data;
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
return error;
|
|
});
|
|
|
|
return data;
|
|
}
|