AWS.config.update({ region: bucketRegion, s3: { endpoint: endpoint }, credentials: new AWS.Credentials({ accessKeyId: key, secretAccessKey: secret, }) }); /* * ROUTER/CONTROLLER*/ const state = {} const router = state => () => { const index = "home"; if !(window.location.hash) { window.location.hash = index } if (window.location.hash == "home") { if (!loadCredentials(state)) { window.location.hash = "configure" return } } } const instance = router(state) window.onhashchange = instance instance() /* HELPERS */ const loadCredentials = state => { if (state.s3) return s3: new AWS.S3({ apiVersion: "2006-03-01" }), } /* EVENTS */ document .querySelector("#plain-text-send") .addEventListener("click", () => { const identifier = new Uint8Array(30); window.crypto.getRandomValues(identifier); const ib64 = btoa(String.fromCharCode(...identifier)); const path = `paste/${ib64}.txt`; const text = document.querySelector("#plain-text-content").value const params = { Bucket: bucketName, Key: path, ContentType: 'text/plain', Body: text }; // Uploading files to the bucket state.s3.upload(params, function(err, data) { if (err) { throw err; } const url = `${host}/${path}`; browser.tabs.create({ url: url, active: true, }) document.querySelector("#output").innerHTML = `Succès, votre texte est disponible à cette adresse : ${url}`; }); })