Skip to content

Commit

Permalink
Move clientRelease url generator (#460)
Browse files Browse the repository at this point in the history
* move github link to the browser, so server-startup will not fail due a rate-limit of the github-api #418

* directly go to latest client release
  • Loading branch information
fcaps committed Nov 13, 2023
1 parent 65936e0 commit 06a76f8
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
indent_style = space
indent_size = 2
indent_size = 4
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,4 @@ public/styles/css/*
#Ignore environment
.env

#Ignore link.json
link.json

public/js/*.js
3 changes: 1 addition & 2 deletions express.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ process.env.SESSION_SECRET_KEY = process.env.SESSION_SECRET_KEY || '12345';

//Execute Middleware
app.use(middleware.initLocals);
app.use(middleware.getLatestClientRelease);
app.use(middleware.clientChecks);

//Set static public directory path
Expand Down Expand Up @@ -292,7 +291,7 @@ app.get(`/${process.env.CALLBACK}`, passport.authenticate('faforever', {
});

// Run scripts initially on startup
let requireRunArray = ['extractor', 'getLatestClientRelease'];
let requireRunArray = ['extractor'];
for (let i = 0; i < requireRunArray.length; i++) {
try {
require(`./scripts/${requireRunArray[i]}`).run();
Expand Down
1 change: 0 additions & 1 deletion grunt/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = {
'node_modules/**',
'grunt/**',
'Gruntfile.js',
'link.json',
'public/js/app/members/**'
]
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"express": "^4.18.1",
"express-session": "^1.17.3",
"express-validator": "7.0.1",
"github-api": "3.4.0",
"moment": "^2.29.4",
"node-fetch": "^2.6.7",
"npm-check": "^6.0.1",
Expand Down
54 changes: 54 additions & 0 deletions public/js/app/play.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {Octokit} from "https://esm.sh/@octokit/core";

const githubOrg = 'faforever'
const githubRepository = 'downlords-faf-client'
const githubFallbackUrl = 'https://github.com/FAForever/downlords-faf-client/releases/latest';
const downloadButtonId = 'faf-client-download'

const startDownloadFile = (url) => window.location.assign(url)

const openFallbackDownloadPage = () => open(githubFallbackUrl, '_blank')

const getWindowsDownloadLink = (response) => {
let [exeAsset] = response?.data?.assets?.filter?.(function (asset) {
return asset.name?.includes?.('.exe')
}) ?? []

if (exeAsset) {
try {
new URL(exeAsset.browser_download_url ?? false)

return exeAsset.browser_download_url
} catch (e) {}
}

return false
}

const onGithubResponse = (response) => {
const windowsDownloadLink = getWindowsDownloadLink(response)

if (windowsDownloadLink) {
startDownloadFile(windowsDownloadLink)

return
}

openFallbackDownloadPage()
}

const onDownloadButtonClicked = (event) => {
event.preventDefault()
const octokit = new Octokit()

octokit
.request(`GET /repos/${githubOrg}/${githubRepository}/releases/latest`)
.then(onGithubResponse)
.catch(() => openFallbackDownloadPage())
}

const downloadButton = document.getElementById(downloadButtonId)

if (downloadButton) {
downloadButton.addEventListener("click", onDownloadButtonClicked)
}
25 changes: 0 additions & 25 deletions routes/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,13 @@
the navigation in the header, you may wish to change this array
or replace it with your own templates / logic.
*/
const express = require('express');
const fs = require('fs');
const {exec} = require("child_process");
const app = express();
exports.initLocals = function(req, res, next) {
let locals = res.locals;
locals.navLinks = [];
locals.cNavLinks = [];
next();
};
exports.getLatestClientRelease = function(req, res, next) {
try {
let locals = res.locals;
const fs = require('fs');
let clientLink;
let exec = require('child_process').exec;

fs.readFile('link.json', 'utf8', function (err, data) {
try {
clientLink = JSON.parse(data);
} catch (e) {
clientLink = {};
clientLink.fafClientLink = 'https://github.com/FAForever/downlords-faf-client/releases';
}
locals.fafClientDownloadLink = clientLink.fafClientLink;
next();
});
} catch (e) {
console.log(e);
}

};

exports.clientChecks = function(req, res, next) {
let locals = res.locals;
Expand Down
60 changes: 0 additions & 60 deletions scripts/getLatestClientRelease.js

This file was deleted.

6 changes: 5 additions & 1 deletion templates/views/play.pug
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ block content
.playContainer
h1 1 - Download and install FAF
p Download the FAF Client and install it. FAF is open source and safe to use. <br> If your Windows computer stops you from running FAF, click on "More info" and you'll be able to run it. <br> This happens because FAF doesn't pay Microsoft for security certifications. So it's an "unrecognized app" for Windows. <br> If you have any issues or troubleshooting, join our Discord or use our forum for help.
a(href=fafClientDownloadLink)
a(href="#" id="faf-client-download")
button Download FAF
br
br
Expand Down Expand Up @@ -96,3 +96,7 @@ block content
br
br
iframe(style="width:75%; height:45vh;" src="https://www.youtube.com/embed/Nks9loE96ok" title="NEW TO FAF? || SUPREME COMMANDER TUTORIAL", allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture;" allowfullscreen )

block js
script(src="../../js/app/play.js" type="module" defer="true")

29 changes: 1 addition & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,6 @@ axios@1.6.1:
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axios@^0.21.1:
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "^1.14.0"

babel-walk@3.0.0-canary-5:
version "3.0.0-canary-5"
resolved "https://registry.yarnpkg.com/babel-walk/-/babel-walk-3.0.0-canary-5.tgz#f66ecd7298357aee44955f235a6ef54219104b11"
Expand Down Expand Up @@ -1961,7 +1954,7 @@ flagged-respawn@^1.0.1:
resolved "https://registry.yarnpkg.com/flagged-respawn/-/flagged-respawn-1.0.1.tgz#e7de6f1279ddd9ca9aac8a5971d618606b3aab41"
integrity sha512-lNaHNVymajmk0OJMBn8fVUAU1BtDeKIqKoVhk4xAALB57aALg6b4W0MfJ/cUE0g9YBXy5XhSlPIpYIJ7HaY/3Q==

follow-redirects@^1.14.0, follow-redirects@^1.15.0:
follow-redirects@^1.15.0:
version "1.15.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.3.tgz#fe2f3ef2690afce7e82ed0b44db08165b207123a"
integrity sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==
Expand Down Expand Up @@ -2109,16 +2102,6 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"

github-api@3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/github-api/-/github-api-3.4.0.tgz#5da2f56442d4839d324e9faf0ffb2cf30f7650b8"
integrity sha512-2yYqYS6Uy4br1nw0D3VrlYWxtGTkUhIZrumBrcBwKdBOzMT8roAe8IvI6kjIOkxqxapKR5GkEsHtz3Du/voOpA==
dependencies:
axios "^0.21.1"
debug "^2.2.0"
js-base64 "^2.1.9"
utf8 "^2.1.1"

giturl@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/giturl/-/giturl-1.0.3.tgz#27f9d1f251d138eb2a5a56cc9dd8512b0fc0bbc6"
Expand Down Expand Up @@ -3057,11 +3040,6 @@ jit-grunt@0.10.0:
resolved "https://registry.yarnpkg.com/jit-grunt/-/jit-grunt-0.10.0.tgz#008c3a7fe1e96bd0d84e260ea1fa1783457f79c2"
integrity sha512-eT/f4c9wgZ3buXB7X1JY1w6uNtAV0bhrbOGf/mFmBb0CDNLUETJ/VRoydayWOI54tOoam0cz9RooVCn3QY1WoA==

js-base64@^2.1.9:
version "2.6.4"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.6.4.tgz#f4e686c5de1ea1f867dbcad3d46d969428df98c4"
integrity sha512-pZe//GGmwJndub7ZghVHz7vjb2LgC1m8B07Au3eYqeqv9emhESByMXxaEgkUkEqJe87oBbSniGYoQNIBklc7IQ==

js-stringify@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/js-stringify/-/js-stringify-1.0.2.tgz#1736fddfd9724f28a3682adc6230ae7e4e9679db"
Expand Down Expand Up @@ -5754,11 +5732,6 @@ use@^3.1.0:
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==

utf8@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/utf8/-/utf8-2.1.2.tgz#1fa0d9270e9be850d9b05027f63519bf46457d96"
integrity sha512-QXo+O/QkLP/x1nyi54uQiG0XrODxdysuQvE5dtVqv7F5K2Qb6FsN+qbr6KhF5wQ20tfcV3VQp0/2x1e1MRSPWg==

util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down

0 comments on commit 06a76f8

Please sign in to comment.