Version 0.0.2 - FIxed delete-url

This commit is contained in:
Maximilian Stumpf 2024-12-20 21:58:43 +01:00
parent fdaeee4cd7
commit 7b829ce606
5 changed files with 28 additions and 20 deletions

View File

@ -70,7 +70,7 @@ PUSHOVER_APP_TOKEN=dein_pushover_app_token
TESTFLIGHT_URLS='[{"name":"App 1", "url":"https://testflight.apple.com/join/abcd1234"}]'
OTP_SECRET=AendereDiesenString
OTP_VALIDITY=300
USER_AGENT=Testflight-Watcher/0.0.1
USER_AGENT=Testflight-Watcher/0.0.2
PORT=3000
HTTP_URL=http://localhost:3000
PUSHOVER_PRIORITY=1

View File

@ -9,21 +9,21 @@ const crypto = require("crypto");
const path = require("path");
const express = require("express");
const CURRENT_VERSION = "0.0.1";
const CURRENT_VERSION = "0.0.2";
const UPDATE_CHECK_URL =
"https://git.lunoxia.net/MaximilianGT500/testflight-watcher/raw/branch/main/version.json";
const SETUP_FILE_NAME = process.env.SETUP_FILE_NAME || "setup.js";
const SERVER_FILE_NAME = process.env.SERVER_FILE_NAME || "index.js";
const USER_AGENT =
process.env.USER_AGENT || "Testflight-Watcher/0.0.1 (Monitoring Script)";
process.env.USER_AGENT || "Testflight-Watcher/0.0.2 (Monitoring Script)";
const OTP_SECRET = process.env.OTP_SECRET || "AendereDiesenString";
const OTP_VALIDITY = process.env.OTP_VALIDITY || "300";
const OTP_VALIDITY = process.env.OTP_VALIDITY || "5 * 60 * 1000";
const PORT = process.env.PORT || "3000";
const HTTP_URL = process.env.HTTP_URL || `http://localhost:${PORT}`;
const PUSHOVER_PRIORITY = process.env.PUSHOVER_PRIORITY || `1`;
const CHECK_INTERVAL = process.env.CHECK_INTERVAL || `30`;
let TESTFLIGHT_URLS = [];
let OTP_STOREAGE = {};
let OTP_STORAGE = {};
function loadConfig() {
if (!fs.existsSync(".env")) {
@ -146,7 +146,7 @@ async function checkTestFlight(app, pushoverAPI) {
return clc.red(`${app.name}: Beta akzeptiert keine neuen Tester.`);
} else {
const otp = generateOTP(app.url);
OTP_STOREAGE[app.url] = otp;
OTP_STORAGE[app.url] = otp;
await sendPushoverNotification(
pushoverAPI,
`🎉 TestFlight Beta verfügbar für ${app.name}!`,
@ -176,7 +176,7 @@ async function sendPushoverNotification(pushoverAPI, title, message) {
}
function generateOTP(url) {
const timeWindow = Math.floor((Date.now() / OTP_VALIDITY) * 1000);
const timeWindow = Math.floor(Date.now() / OTP_VALIDITY);
return crypto
.createHmac("sha256", OTP_SECRET)
.update(`${timeWindow}-${url}`)
@ -185,15 +185,15 @@ function generateOTP(url) {
}
function verifyOTP(otp, url) {
const timeWindow = Math.floor((Date.now() / OTP_VALIDITY) * 1000);
const timeWindow = Math.floor(Date.now() / OTP_VALIDITY);
const validOTP = crypto
.createHmac("sha256", OTP_SECRET)
.update(`${timeWindow}-${url}`)
.digest("hex")
.slice(0, 6);
if (otp === validOTP && OTP_STOREAGE[url] === otp) {
delete OTP_STOREAGE[url];
if (otp === validOTP && OTP_STORAGE[url] === otp) {
delete OTP_STORAGE[url];
return true;
}
return false;

View File

@ -8,7 +8,7 @@
"nodemon": "^3.1.7"
},
"name": "testflight-watcher",
"version": "0.0.1",
"version": "0.0.2",
"description": "Dies ist ein einfacher TestFlight-Watcher, der alle 30 Sekunden die Website auf verfügbare Plätze überprüft. Sobald ein Platz frei wird, erfolgt eine Benachrichtigung über Pushover.",
"main": "index.js",
"scripts": {

View File

@ -184,6 +184,7 @@ async function sendPushoverNotification(userKey, appToken, title, message) {
throw err;
}
}
async function configureEnvironment() {
const env = loadEnv();
displayMessage("\n🎉 Willkommen zum Setup!\n", "info");
@ -197,9 +198,8 @@ async function configureEnvironment() {
},
{
key: "OTP_VALIDITY",
prompt:
'Gültigkeitsdauer für das OTP in Sekunden (z.B. "300" für 5 Min.)',
defaultValue: "300",
prompt: 'Gültigkeitsdauer für das OTP in Minuten (z.B. "5" für 5 Min.)',
defaultValue: "5 * 60 * 1000",
},
{
key: "SETUP_FILE_NAME",
@ -208,7 +208,7 @@ async function configureEnvironment() {
},
{
key: "SERVER_FILE_NAME",
prompt: "Name der Server-Datei (Fals Du ihn angepasst hast)",
prompt: "Name der Server-Datei (Falls Du ihn angepasst hast)",
defaultValue: "index.js",
},
{
@ -225,7 +225,7 @@ async function configureEnvironment() {
{
key: "USER_AGENT",
prompt: "User-Agent für Anfragen",
defaultValue: "Testflight-Watcher/0.0.1 (Monitoring Script)",
defaultValue: "Testflight-Watcher/0.0.2 (Monitoring Script)",
},
{
key: "PUSHOVER_PRIORITY",
@ -236,7 +236,7 @@ async function configureEnvironment() {
{
key: "CHECK_INTERVAL",
prompt:
"In welchen Abstand soll das Script nach einen neuen Platz prüfen in Sekunden (z.B. 30)",
"In welchem Abstand soll das Script nach einem neuen Platz prüfen in Sekunden (z.B. 30)",
defaultValue: "30",
},
];
@ -250,11 +250,19 @@ async function configureEnvironment() {
continue;
}
const currentValue = defaultValue;
let currentValue = defaultValue;
const answer = await prompt(
clc.cyan(`${question} [Standard: ${currentValue}]: `)
);
env[key] = answer || currentValue;
if (key === "OTP_VALIDITY") {
const minutes = parseFloat(answer || "5");
currentValue = `${minutes} * 60 * 1000`;
} else {
currentValue = answer || currentValue;
}
env[key] = currentValue;
saveEnv(env);
}

View File

@ -1,3 +1,3 @@
{
"version": "0.0.1"
"version": "0.0.2"
}