xxxxxxxxxx
const path = require('path')
const multer = require('multer')
var storage= multer.diskStorage({
destination: function(req,file,cb){
cb(null,'uploads/')
},
filename: function(req, file, cb){
let ext = path.extname(file.originalname)
cb(null, Date.now() + ext)
}
})
var upload = multer({
storage: storage,
fileFilter: function(req, file, callback){
if(
file.mimetype == "image/png" ||
file.mimetype == "image/jpg"
){
callback(null,true)
}else{
console.log('only jpg & png file supported!')
callback(null,false)
//return res.status(401).json({msg: "Invalid Authentication.", ok:false})
//res.send({ msg: 'Adresse Email ou Nom complet, existe déjà', ok: false })
}
},
limits:{
fileSize: 1024 * 1024 * 2
}
})
module.exports= upload
xxxxxxxxxx
1. Add tsconfig.json file to project
2. Integrate with a build tool
3. Change all .js files to .ts files
4. Check for any errors
xxxxxxxxxx
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
xxxxxxxxxx
const Validacao =() => {
const {getFieldProps, handleSubmit, isValid} = useFormik({
initialValues: {
name:'',
contact:{
email:'',
phone:''
}
},
validate: values => {
const err ={}
const message= ' campo obrigatorio'
if(!values.name) err.name = message
if(!values.contact.email) err.email = message
return err
},
onSubmit: (values, bag) => {
console.log(values)
}
})
const [name, metadataName] = getFieldProps('name','text')
const [email, metadataEmail] = getFieldProps('contact.email', 'text')
const [phone, metadataPhone] = getFieldProps('contact.phone', 'text')
xxxxxxxxxx
const swaggerAutogen = require('swagger-autogen')()
const outputFile = './swagger_output.json'
const endpointsFiles = ['./endpoints.js']
swaggerAutogen(outputFile, endpointsFiles)
xxxxxxxxxx
function parseJwt(token) {
var base64Payload = token.split('.')[1];
var payload = Buffer.from(base64Payload, 'base64');
return JSON.parse(payload.toString());
}
xxxxxxxxxx
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none";
} else {
panel.style.display = "block";
}
});
}
xxxxxxxxxx
$('.digit-group').find('input').each(function() {
$(this).attr('maxlength', 1);
$(this).on('keyup', function(e) {
var parent = $($(this).parent());
if(e.keyCode === 8 || e.keyCode === 37) {
var prev = parent.find('input#' + $(this).data('previous'));
if(prev.length) {
$(prev).select();
}
} else if((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 96 && e.keyCode <= 105) || e.keyCode === 39) {
var next = parent.find('input#' + $(this).data('next'));
if(next.length) {
$(next).select();
} else {
if(parent.data('autosubmit')) {
parent.submit();
}
}
}
});
});
xxxxxxxxxx
var myModal = document.getElementById('myModal')
var myInput = document.getElementById('myInput')
myModal.addEventListener('shown.bs.modal', function () {
myInput.focus()
})