Convert to ReasonML

This commit is contained in:
Quentin 2022-03-29 14:45:52 +02:00
parent 9b7ec52ef6
commit f9dcdeeef0
11 changed files with 106 additions and 10 deletions

7
.gitignore vendored
View file

@ -1,2 +1,7 @@
*.swp
popup/config.js
static/popup/config.js
lib/
.merlin
node_modules
src/*.bs.js
src/**/*.bs.js

17
bsconfig.json Normal file
View file

@ -0,0 +1,17 @@
{
"name": "fanzine",
"sources": [
{
"dir": "src",
"subdirs": true
}
],
"package-specs": [
{
"module": "es6",
"in-source": true
}
],
"suffix": ".bs.js",
"bs-dependencies": []
}

14
package-lock.json generated Normal file
View file

@ -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
}
}
}

27
package.json Normal file
View file

@ -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"
}

1
src/main.re Normal file
View file

@ -0,0 +1 @@
Js.log("hello world")

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -91,15 +91,16 @@ hr {
</style>
</head>
<body>
<section id="home">
<div class="menu-title">Publier sur mon site web</div>
<a class="menu-elem" href="#plain-text">Texte brut</a>
<div class="menu-elem">Brève</div>
<!--<div class="menu-elem">Brève</div>-->
<div class="menu-elem">Galerie photo</div>
<div class="menu-elem">Fichiers</div>
<div class="menu-elem">Podcast</div>
<hr>
<div class="menu-elem">Manuellement</div>
<div class="menu-elem">Site statique</div>
<hr>
<div class="menu-elem">Paramètres</div>
</section>
@ -113,6 +114,11 @@ hr {
<div id="output">Please wait...</div>
</section>
<section id="configure">
<div class="menu-title">Paramètres</div>
</section>
<script src="aws-sdk.js"></script>
<script src="config.js"></script>
<script src="fanzine.js"></script>

View file

@ -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;
}