45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
AWS.config.update({
|
|
region: bucketRegion,
|
|
s3: { endpoint: endpoint },
|
|
credentials: new AWS.Credentials({
|
|
accessKeyId: key,
|
|
secretAccessKey: secret,
|
|
})
|
|
});
|
|
|
|
const s3 = new AWS.S3({
|
|
apiVersion: "2006-03-01",
|
|
params: { Bucket: bucketName }
|
|
});
|
|
|
|
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 params = {
|
|
Bucket: bucketName,
|
|
Key: path,
|
|
ContentType: 'text/plain',
|
|
Body: document.querySelector("#plain-text-content").value
|
|
};
|
|
|
|
// Uploading files to the bucket
|
|
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}`;
|
|
});
|
|
})
|