diff --git a/.gitignore b/.gitignore index 59249c9..76b8cf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ *.swp -popup/config.js +static/popup/config.js +lib/ +.merlin +node_modules +src/*.bs.js +src/**/*.bs.js diff --git a/bsconfig.json b/bsconfig.json new file mode 100644 index 0000000..190fc9d --- /dev/null +++ b/bsconfig.json @@ -0,0 +1,17 @@ +{ + "name": "fanzine", + "sources": [ + { + "dir": "src", + "subdirs": true + } + ], + "package-specs": [ + { + "module": "es6", + "in-source": true + } + ], + "suffix": ".bs.js", + "bs-dependencies": [] +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..6fcff2e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,14 @@ +{ + "name": "fanzine", + "version": "0.0.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "rescript": { + "version": "9.1.4", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-9.1.4.tgz", + "integrity": "sha512-aXANK4IqecJzdnDpJUsU6pxMViCR5ogAxzuqS0mOr8TloMnzAjJFu63fjD6LCkWrKAhlMkFFzQvVQYaAaVkFXw==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..c66c7f3 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "fanzine", + "version": "0.0.1", + "description": "A web extension to publish content on a S3 website", + "main": "src/main.bs.js", + "type": "module", + "dependencies": {}, + "devDependencies": { + "rescript": "^9.1.4" + }, + "scripts": { + "re:build": "rescript", + "re:start": "rescript build -w", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git@git.deuxfleurs.fr:quentin/fanzine.git" + }, + "keywords": [ + "s3", + "garage", + "web" + ], + "author": "Quentin Dufour", + "license": "AGPL-3.0-or-later" +} diff --git a/src/main.re b/src/main.re new file mode 100644 index 0000000..02dbe31 --- /dev/null +++ b/src/main.re @@ -0,0 +1 @@ +Js.log("hello world") diff --git a/icons/fanzine-32.png b/static/icons/fanzine-32.png similarity index 100% rename from icons/fanzine-32.png rename to static/icons/fanzine-32.png diff --git a/manifest.json b/static/manifest.json similarity index 100% rename from manifest.json rename to static/manifest.json diff --git a/popup/aws-sdk.js b/static/popup/aws-sdk.js similarity index 100% rename from popup/aws-sdk.js rename to static/popup/aws-sdk.js diff --git a/popup/config.sample.js b/static/popup/config.sample.js similarity index 100% rename from popup/config.sample.js rename to static/popup/config.sample.js diff --git a/popup/fanzine.html b/static/popup/fanzine.html similarity index 91% rename from popup/fanzine.html rename to static/popup/fanzine.html index 3013da4..3af74e3 100644 --- a/popup/fanzine.html +++ b/static/popup/fanzine.html @@ -91,15 +91,16 @@ hr { +
Texte brut - + -
- + +
@@ -113,6 +114,11 @@ hr {
Please wait...
+
+ + +
+ diff --git a/popup/fanzine.js b/static/popup/fanzine.js similarity index 57% rename from popup/fanzine.js rename to static/popup/fanzine.js index dbc0bfb..313a11e 100644 --- a/popup/fanzine.js +++ b/static/popup/fanzine.js @@ -7,11 +7,35 @@ AWS.config.update({ }) }); -const s3 = new AWS.S3({ - apiVersion: "2006-03-01", - params: { Bucket: bucketName } -}); +/* + * 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", () => { @@ -21,15 +45,17 @@ document 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: document.querySelector("#plain-text-content").value + Body: text }; // Uploading files to the bucket - s3.upload(params, function(err, data) { + state.s3.upload(params, function(err, data) { if (err) { throw err; }