added Docker support with env variables
This commit is contained in:
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
FROM node:18-alpine
|
||||||
|
|
||||||
|
# Create app directory
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
# Install app dependencies
|
||||||
|
# A wildcard is used to ensure both package.json AND package-lock.json are copied
|
||||||
|
# where available (npm@5+)
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
# If you are building your code for production
|
||||||
|
# RUN npm ci --omit=dev
|
||||||
|
|
||||||
|
# Bundle app source
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD [ "node", "." ]
|
51
index.js
51
index.js
@ -1,59 +1,56 @@
|
|||||||
const settings = require('./settings.json');
|
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const cache = {};
|
const cache = {};
|
||||||
|
|
||||||
const default_headers = {
|
const default_headers = {
|
||||||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
|
||||||
"accept-language": "en-US,en;q=0.9",
|
'accept-language': 'en-US,en;q=0.9',
|
||||||
"upgrade-insecure-requests": "1",
|
'upgrade-insecure-requests': '1',
|
||||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
|
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',
|
||||||
}
|
};
|
||||||
|
|
||||||
function isFull(t) {
|
function isFull(t) {
|
||||||
return (t.includes("This beta is full.") || t.includes("This beta isn't accepting any new testers right now."));
|
return (t.includes('This beta is full.') || t.includes('This beta isn\'t accepting any new testers right now.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getName(t) {
|
function getName(t) {
|
||||||
return (t.includes("<title>Join the ") ? t.split("<title>Join the ")[1].split(" - TestFlight - Apple</title>")[0] : "App");
|
return (t.includes('<title>Join the ') ? t.split('<title>Join the ')[1].split(' - TestFlight - Apple</title>')[0] : 'App');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function do_request(a, h, m = "GET", d = null) {
|
async function do_request(a, h, m = 'GET', d = null) {
|
||||||
let r = await fetch(a, {
|
const r = await fetch(a, {
|
||||||
headers: Object.assign(h),
|
headers: Object.assign(h),
|
||||||
method: m,
|
method: m,
|
||||||
redirect: "manual",
|
redirect: 'manual',
|
||||||
body: m == 'POST' ? JSON.stringify(d) : null
|
body: m == 'POST' ? JSON.stringify(d) : null,
|
||||||
});
|
});
|
||||||
return (await r.text());
|
return (await r.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
console.log(`Watching over ${settings.programs.length} programs`);
|
setInterval(async () => {
|
||||||
|
console.log('Refreshing now.');
|
||||||
setInterval(() => {
|
const p = {
|
||||||
console.log("Refreshing now.")
|
id: process.env.TESTFLIGHT_ID,
|
||||||
settings.programs.forEach(async p => {
|
url: process.env.DISCORD_WEBHOOK_URL,
|
||||||
let r = await do_request("https://testflight.apple.com/join/" + p.id, default_headers);
|
};
|
||||||
|
const r = await do_request('https://testflight.apple.com/join/' + p.id, default_headers);
|
||||||
if (!isFull(r)) {
|
if (!isFull(r)) {
|
||||||
if (!cache[p.id]) {
|
if (!cache[p.id]) {
|
||||||
let message = getName(r) + " is available at https://testflight.apple.com/join/" + p.id;
|
const message = getName(r) + ' is available at https://testflight.apple.com/join/' + p.id;
|
||||||
if (p.url) {
|
if (p.url) {
|
||||||
await do_request(
|
await do_request(
|
||||||
p.url,
|
p.url,
|
||||||
Object.assign(default_headers, { "Content-Type": "application/json" }),
|
Object.assign(default_headers, { 'Content-Type': 'application/json' }),
|
||||||
"POST", {
|
'POST', { 'content': message },
|
||||||
"content": message
|
);
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
console.log(message);
|
console.log(message);
|
||||||
}
|
}
|
||||||
cache[p.id] = true;
|
cache[p.id] = true;
|
||||||
} else {
|
} else {
|
||||||
delete cache[p.id];
|
delete cache[p.id];
|
||||||
console.log(getName(r) + " is still full.")
|
console.log(getName(r) + ' is still full.');
|
||||||
}
|
}
|
||||||
});
|
}, 30000);
|
||||||
}, 30000)
|
|
||||||
|
|
||||||
})();
|
})();
|
Reference in New Issue
Block a user