Skip to content

Commit

Permalink
chore: update to latest deps, en nog veel meer (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben authored Dec 29, 2023
1 parent 8bd53bc commit ddf1441
Show file tree
Hide file tree
Showing 11 changed files with 812 additions and 475 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Docker

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
schedule:
- cron: '0 8 1 * *'
workflow_dispatch: {}

env:
IMAGE_NAME: infobord

jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=docker.pkg.github.com/djoamersfoort/infobord/$IMAGE_NAME
# Use Docker `latest` tag convention
VERSION=latest
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
slides.json
.idea
.env
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:20

WORKDIR /app
COPY . /app/

RUN npm ci

CMD ["npm", "start"]
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.8"
services:
infobord:
image: infobord
container_name: infobord

volumes:
- ./data:/app/data
ports:
- "8180:8180"
45 changes: 22 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const registerFolder = require("./lib/express_register_folder.js");
const _slides = require("./lib/slides.js").slides;
const onExit = require("./lib/onexit.js");
const { Slides } = require("./lib/slides.js");

const fs = require("fs");
const { exec } = require('child_process');

const express = require('express');
const http = require("http");
const _io = require("socket.io");
const SocketIO = require("socket.io");

const { AuthorizationCode } = require("simple-oauth2")
const https = require("https")

const port = 8180;
let authorized = {};
Expand All @@ -17,10 +17,10 @@ let config = {
};

// oath2
const oauth2 = require('simple-oauth2').create({
const oauth2 = new AuthorizationCode({
client: {
id: "eE4hlNNn1RLffmBgb9eyWS0N6hIsn8ng0lrJ7eom",
secret: "<jajaegnie>"
id: process.env.CLIENT_ID,
secret: process.env.CLIENT_SECRET
},
auth: {
tokenHost: "https://leden.djoamersfoort.nl",
Expand All @@ -29,7 +29,7 @@ const oauth2 = require('simple-oauth2').create({
}
});

let slides = new _slides();
const slides = new Slides();

// all slide styles
const styles = [
Expand All @@ -40,15 +40,14 @@ const styles = [
];

// read slides from file
slides.slides = JSON.parse(fs.readFileSync(__dirname+"/slides.json", {encoding:"utf8"}));
slides.slides = JSON.parse(fs.readFileSync("data/slides.json", {encoding:"utf8"}));


// webshite
const app = express();
var httpServer = http.Server(app);
const io = _io(httpServer);

registerFolder(app, "/home/infobord/html", "");
app.use(express.static("html"))
const httpServer = new http.Server(app);
const io = new SocketIO.Server(httpServer);

// cycle slides
let slideIndex = -1;
Expand All @@ -67,8 +66,8 @@ nextSlide();

// oauth2
app.get("/auth", async function(req, res) {
const authorizationUri = oauth2.authorizationCode.authorizeURL({
redirect_uri: 'https://infobord.djoamersfoort.nl/authed',
const authorizationUri = oauth2.authorizeURL({
redirect_uri: `${process.env.BASE_URL}/authed`,
scope: 'user/basic user/names',
state: "infobord"
});
Expand All @@ -77,15 +76,15 @@ app.get("/auth", async function(req, res) {
});
app.get("/authed", async function(req, res) {
try {
const result = await oauth2.authorizationCode.getToken({
const result = await oauth2.getToken({
code: req.query.code,
redirect_uri: 'https://infobord.djoamersfoort.nl/authed',
redirect_uri: `${process.env.BASE_URL}/authed`,
scope: 'user/basic user/names'
});
})

accessToken = result.access_token;
const accessToken = result.token.access_token;

require("https").request({
https.request({
host: "leden.djoamersfoort.nl",
port: 443,
path: "/api/v1/member/details",
Expand Down Expand Up @@ -114,7 +113,7 @@ app.get("/authed", async function(req, res) {
res.send("<script>localStorage.person='"+output.firstName+"';location.href = '/lid';</script>");
}
});
}).on("error", function(error) {
}).on("error", function () {
res.redirect("/auth");
}).end();
} catch (error) {
Expand All @@ -130,7 +129,7 @@ io.on("connection", function(socket) {

socket.on("save", function(args) {
if(args.code && authorized[args.code] !== undefined) {
fs.writeFile(__dirname+"/slides.json", JSON.stringify(slides.get()), function(err) {
fs.writeFile("data/slides.json", JSON.stringify(slides.get()), function(err) {
if(err) {
console.log("Error while saving slides!", err);
socket.emit("notify", [{message:"Uh Oh... Your progress could not be saved. This was not meant to happen!"},{type:"warning"}]);
Expand Down
3 changes: 0 additions & 3 deletions lib/auth.js

This file was deleted.

34 changes: 0 additions & 34 deletions lib/express_register_folder.js

This file was deleted.

16 changes: 0 additions & 16 deletions lib/onexit.js

This file was deleted.

9 changes: 1 addition & 8 deletions lib/slides.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
slides: function() {
Slides: function() {
this.slides = [];

this.add = (slide) => {
Expand All @@ -19,13 +19,6 @@ module.exports = {
}
};

return this;
},
slide: function(background, title, content) {
this.background = background;
this.title = title;
this.content = content;

return this;
}
};
Loading

0 comments on commit ddf1441

Please sign in to comment.