let url = this.globalAPIBaseUrl + 'program/' + this.tmsID + '/updateposters/?posterType=' + imageType;
let j = [{
posterType: imageType,
url: imageUrl
}];
axios.patch(url, {
headers: {
Authorization: 'Bearer ' + localStorage.getItem('accessToken')
}
}, j, {
onUploadProgress: progressEvent => {
this.basic.status = 'Uploaded: ' + progressEvent.loaded + 'b of ' + progressEvent.total + 'b'
}
}).then(response => (this.handleUploadComplete(response)));
before i put in the "headers" is worked fine, and when i use the same auth headers, but no "j" data variable elsewhere it also works fine.
Any advice, i'm kinda new here with axios. (this is in vue2.js btw)
data should be the second parameter, and the third parameter is config object, where you can set headers and onUploadProgress callback
axios.patch(url, j, {
headers: {
Authorization: 'Bearer ' + localStorage.getItem('accessToken')
},
onUploadProgress: progressEvent => {
this.basic.status = 'Uploaded: ' + progressEvent.loaded + 'b of ' + progressEvent.total + 'b'
}
}).then(response => (this.handleUploadComplete(response)));
Related
Is there a way to create a zoom meeting for a specific max number of participants?
For example,
If a player books a "Small" package, which is up to 6 players, is it possible to create a zoom link for 7 players max (1 host + 6 players)?
If a player books a "Mid" package, which is up to 8 players, is it possible to create a zoom link for 9 players max (1 host + 8 players)?
If a player books a "Large" package, which is up to 10 players, is it possible to create a zoom link for 11 players max (1 host + 10 players)?
If a player books a "XL" package, which is for a custom number of players, is it possible to create a zoom link for that specific amount of players + 1 host?
then how can i limit number of participants who join zoom meeting
Is it can be done using Zoom API
let createZoomMeeting = (req, res, next, meetingoption) => {
return new Promise(async resolve => {
if (meetingoption) {
const jwt = require('jsonwebtoken');
const payload = {
iss: ZOOM_API_KEY,
exp: ((new Date()).getTime() + 5000)
};
const token = jwt.sign(payload, ZOOM_API_SECRET);
let optionsForHost = {
conditions: {
user_role_id: FRONT_USER_ROLE_ID,
active: ACTIVE,
is_deleted: NOT_DELETED,
is_verified: VERIFIED,
},
fields: {
_id: 1, full_name: 1, email: 1,
}
};
/**Condition for player Slug*/
optionsForHost.conditions._id = meetingoption.host_id;
/** Get host details **/
let hostResponse = await getUserData(req, res, next, optionsForHost);
/** get global zoom url and set email for particular host **/
let HOST_ZOOM_URL = MEETING_ZOOM_URL;
const host_email = hostResponse.result.email ? hostResponse.result.email : "hello#gamenitesocial.com";
HOST_ZOOM_URL = HOST_ZOOM_URL.replace("me", host_email);
if (hostResponse.status != STATUS_SUCCESS) return next(hostResponse.message);
if (!hostResponse.result) return resolve({ status: STATUS_ERROR, message: res.__("admin.system.invalid_access") });
const options = {
method: 'POST',
url: HOST_ZOOM_URL,
headers: { 'content-type': 'application/json', authorization: `Bearer ${token}` },
body: {
topic: meetingoption.game_type + ' (' + meetingoption.game_name + '-' + meetingoption.game_category_name + ')',
type: 2,
start_time: meetingoption.game_date + 'T' + meetingoption.start_time + ":00:00",
timezone: 'America/New_York',
agenda: meetingoption.game_type + ' (' + meetingoption.game_name + '-' + meetingoption.game_category_name + ')',
settings: {
host_video: true,
participant_video: true,
join_before_host: false,
mute_upon_entry: true,
use_pmi: false,
approval_type: 2,
alternative_hosts: hostResponse.result.email
}
},
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
return resolve({ status: STATUS_SUCCESS, result: body });
});
} else {
return resolve({ status: STATUS_ERROR, result: {} });
}
});
};// End createZoomMeeting().
You can not do this by zoom/SDK zoom SDK does not provide such type of parameter in its documentation
Reference Link: Create Zoom meeting Docs Link
I'm using FormData() in my React app. I was going to use it for registration and login too. I have a working passport.js registration piece of code and was going to use it with busboy but it looks like it reads fields one by one whenever there is one and it seems like I can't use it with Account.register.
I've inserted Account.register in busboy.on('field') but then realized it won't work. I didn't change req.body.username etc in my original code, ignore them.
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
Account.register(new Account({ nickname: req.body.username, email: req.body.email }), req.body.passwordOne, (err, user) => {
if(err){
helpers.errors(err, res);
} else {
helpers.registerSuccess(res);
}
});
});
busboy.on('finish', function() {
console.log('Done parsing form!');
//res.writeHead(303, { Connection: 'close', Location: '/' });
res.end();
});
I'm using nickname instead of username in passport.js because I'm using email as the username field. Working code:
router.post('/register', (req, res, next)=>{
var busboy = new Busboy({ headers: req.headers });
let nickname = '';
let email = '';
let password = '';
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);
file.on('data', function(data) {
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
});
file.on('end', function() {
console.log('File [' + fieldname + '] Finished');
});
});
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
if(fieldname == 'username') { nickname = val; }
if(fieldname == 'email') { email = val; }
if(fieldname == 'password') { password = val; }
});
busboy.on('finish', function() {
console.log('Done parsing form!');
console.log('email: ' + email + 'password: ' + password + 'username: ' + nickname);
Account.register(new Account({ nickname: nickname, email: email }), password, (err, user) => {
if(err){
helpers.errors(err, res);
} else {
helpers.registerSuccess(res);
}
});
});
req.pipe(busboy);
});
I have simple deposit calc. Here is the code.
app.js:
el: '#calcbox',
data: {
newCalc: {
summ: '50000',
currency: 'USD',
duration: '',
percents: '',
},
calcResult: '',
},
computed: {
percents() {
var id = $("#deposit_id").val();
var url = "/get_percent/"+ id + '/' + this.newCalc.currency + '/' + this.newCalc.duration;
this.$http.get(url, function(response){
return this.newCalc.percents = response;
});
},
calcResult() {
var deposit_id = $("#deposit_id").val();
var url = "/api/calc/"+ deposit_id + '/' + this.newCalc.summ + '/' + this.newCalc.currency + '/' + this.newCalc.duration;
this.$http.get(url, function(response){
return this.calcResult = response;
});
}
},
frontend:
<span>#{{newCalc.percents}}%:</span>
<span>#{{calcResult}}:</span>
So the problem is that result isn't appears in frontend, console.log shows the correct result.
Percentage value is showing well.
calcResult() {
var deposit_id = $("#deposit_id").val();
var url = "/api/calc/"+ deposit_id + '/' + this.newCalc.summ + '/' + this.newCalc.currency + '/' + this.newCalc.duration;
this.$http.get(url, function(response){
return this.calcResult = response;
});
}
add .bind(this)
calcResult() {
var deposit_id = $("#deposit_id").val();
var url = "/api/calc/"+ deposit_id + '/' + this.newCalc.summ + '/' + this.newCalc.currency + '/' + this.newCalc.duration;
this.$http.get(url, function(response){
return this.calcResult = response;
}.bind(this));
}
Or use fat arrow notation since you're using ES6 syntax
calcResult() {
var deposit_id = $("#deposit_id").val();
var url = "/api/calc/"+ deposit_id + '/' + this.newCalc.summ + '/' + this.newCalc.currency + '/' + this.newCalc.duration;
this.$http.get(url, response => {
return this.calcResult = response;
});
}
the this in the .then callback is not the same context as the one outside or within your vue method
In PhantomJS, webpage.open takes a callback with a status parameter that's set to 'success' or 'fail'. According to the docs, it wll be "'success' if no network errors occurred, otherwise 'fail'." Is there a way to see the underlying network error that caused the failure?
The url I'm trying to load works fine when I put it in my browser, and when I take a screenshot after getting the 'fail' message I see the page that I was on before I called webpage.open (so I can't just ignore the fail). I'm using Phantom for testing, so ideally I'd like a robust way of easily getting a helpful error messsage when webpage.open fails (or better yet have it never fail!)
Found this post which explains how to set up callbacks to get at the underlying reason for the failure: http://newspaint.wordpress.com/2013/04/25/getting-to-the-bottom-of-why-a-phantomjs-page-load-fails/
Based on the that page, you could print out errors as follows:
page.onResourceError = function(resourceError) {
console.error(resourceError.url + ': ' + resourceError.errorString);
};
The page goes on to show an example of detailed logging for phantoms
var system = require('system');
page.onResourceRequested = function (request) {
system.stderr.writeLine('= onResourceRequested()');
system.stderr.writeLine(' request: ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function(response) {
system.stderr.writeLine('= onResourceReceived()' );
system.stderr.writeLine(' id: ' + response.id + ', stage: "' + response.stage + '", response: ' + JSON.stringify(response));
};
page.onLoadStarted = function() {
system.stderr.writeLine('= onLoadStarted()');
var currentUrl = page.evaluate(function() {
return window.location.href;
});
system.stderr.writeLine(' leaving url: ' + currentUrl);
};
page.onLoadFinished = function(status) {
system.stderr.writeLine('= onLoadFinished()');
system.stderr.writeLine(' status: ' + status);
};
page.onNavigationRequested = function(url, type, willNavigate, main) {
system.stderr.writeLine('= onNavigationRequested');
system.stderr.writeLine(' destination_url: ' + url);
system.stderr.writeLine(' type (cause): ' + type);
system.stderr.writeLine(' will navigate: ' + willNavigate);
system.stderr.writeLine(' from page\'s main frame: ' + main);
};
page.onResourceError = function(resourceError) {
system.stderr.writeLine('= onResourceError()');
system.stderr.writeLine(' - unable to load url: "' + resourceError.url + '"');
system.stderr.writeLine(' - error code: ' + resourceError.errorCode + ', description: ' + resourceError.errorString );
};
page.onError = function(msg, trace) {
system.stderr.writeLine('= onError()');
var msgStack = [' ERROR: ' + msg];
if (trace) {
msgStack.push(' TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
});
}
system.stderr.writeLine(msgStack.join('\n'));
};
Can someone helps me with some example using haraka librairy?
We use Haraka as our application mail server. We have written a simple plugin which takes any incoming mail and post it to our application web server.
Here is the plugin script. Just save it to a file do the necessary name changes and add the path to Harakas config/plugins file.
var
fs = require('fs'),
query_string = require('querystring'),
logger = require('./logger'),
DROP_DIRECTORY_PATH = '/path/haraka/drop/',
RETRY_DIRECTORY_PATH = '/path/haraka/retry/',
HOST_NAME = 'this_haraka_servers_name';
exports.hook_queue = function (next, connection, params) {
'use strict';
function haraka_log(function_name_in, section_in, text_in) {
var log_text = '[HttpMail]';
log_text += ' [' + function_name_in + ']';
log_text += ' [' + section_in + ']';
log_text += ' ' + text_in;
logger.lognotice(log_text);
}//function haraka_log
function move_file(filename_in) {
fs.rename(DROP_DIRECTORY_PATH + filename_in, RETRY_DIRECTORY_PATH + filename_in, function (err) {
if (err) {
//throw err;
haraka_log('move_file', 'fs.rename ... failed', filename_in + '\n' + JSON.stringify(err));
} else {
haraka_log('move_file', 'fs.rename ... success', filename_in);
}
});
}//function move_file
function delete_file(filename_in) {
fs.unlink(DROP_DIRECTORY_PATH + filename_in, function (err) {
if (err) {
//throw err;
haraka_log('delete_file', 'fs.unlink ... failed', filename_in + '\n' + JSON.stringify(err));
} else {
haraka_log('delete_file', 'fs.unlink ... success', filename_in);
}
});
}//function delete_file
function http_post_file(filename_in) {
var
http = require('http'),
post_options = {
host: 'my.server.com',
port: 80,
path: '/http_mail/' + HOST_NAME + '?' + query_string.stringify({FileName: filename_in}),
method: 'POST',
headers: {'Content-Type': 'text/plain'}
},
post_request,
read_stream;
haraka_log('http_post_file', 'Before http.request', filename_in);
post_request = http.request(post_options, function (post_response) {
haraka_log('http_post_file', 'post_response', ' post_response.statusCode = ' + post_response.statusCode + ' : ' + filename_in);
if (post_response.statusCode === 200) {
delete_file(filename_in);
} else {
move_file(filename_in);//Posted later by retry script;
}
post_response.resume();
});//post_request = http.request(post_options, function(post_response) {
post_request.on('error', function (err) {
haraka_log('http_post_file post_request.on(\'error\' ...)', err.message, filename_in);
move_file(filename_in);
});//post_request.on('error', function(err) {
read_stream = fs.createReadStream(DROP_DIRECTORY_PATH + filename_in);
read_stream.pipe(post_request);
}//function http_post_file
var
x_sender = connection.transaction.mail_from,
x_receiver_list = connection.transaction.rcpt_to,
filename = x_sender + '_' + new Date().toISOString() + '_' + connection.uuid,
writeStream;
filename = filename.replace(/\//g, '');
connection.transaction.add_header('x-sender', x_sender.toString());
x_receiver_list.forEach(function (value) {
connection.transaction.add_header('x-receiver', value.toString());
});
haraka_log('main', 'filename', filename);
writeStream = fs.createWriteStream(DROP_DIRECTORY_PATH + filename);
//connection.transaction.message_stream.pipe(writeStream, {dot_stuffing: true, ending_dot: true});
connection.transaction.message_stream.pipe(writeStream, {dot_stuffing: true});
writeStream.on("close", function () {
haraka_log('main writeStream.on("close"...', 'File Saved!', filename);
http_post_file(filename);
next(OK);
});//writeStream.on("close", function()
};//exports.hook_queue = function(next, connection, params) {