diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..c089687 --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,33 @@ +name: Docker build image + +on: + workflow_dispatch: + push: + +jobs: + build: + runs-on: 'runner' + steps: + - name: Check Out Repo + uses: actions/checkout@v3 + + - name: Login to git.nadeko.net + uses: docker/login-action@v2 + with: + registry: git.nadeko.net + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + version: latest + + - name: Build and push docker image + uses: docker/build-push-action@v3 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64 + push: true + tags: git.nadeko.net/Fijxu/youtube-po-token-generator:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..678f9db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM node:20-alpine +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +CMD [ "node", "index.js" ] diff --git a/index.js b/index.js index 05b207b..f7dfb9a 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,14 @@ const { createTask } = require('./lib/task') const { fetchVisitorData } = require('./lib/workflow') +const { Redis } = require('ioredis') + + +const redis = new Redis({ host: process.env.HOST || config.host }); + +redis.on('error', (error) => { + console.error('Could not connect to Redis:', error); + process.exit(1); +}); const generate = async () => { const visitorData = await fetchVisitorData() @@ -8,4 +17,18 @@ const generate = async () => { return { visitorData, poToken } } +const run = async () => { + try { + const { visitorData, poToken } = await generate(); + p = redis.set("invidious:po_token", poToken) + v = redis.set("invidious:visitor_data", visitorData) + } catch(e) { + console.error(`Fuck: ${e}`) + } + console.log("New tokens sent to redis") +} + +run(); +setTimeout(run, (process.env.RENEW_INTERVAL || 60) * 1000) + module.exports = { generate } diff --git a/package.json b/package.json index e8f9e7c..d76803c 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "main": "index.js", "license": "MIT", "dependencies": { + "ioredis": "^5.4.1", "jsdom": "^24.1.1" }, "engines": {