Skip to content

Commit

Permalink
update. license keys not guaranteeed. i will give if i figure out how…
Browse files Browse the repository at this point in the history
… to get them working
  • Loading branch information
0mgRod committed Aug 30, 2024
1 parent f23f7ce commit dd0cd0c
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 13 deletions.
45 changes: 37 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const express = require('express');
const path = require('path');
const axios = require('axios');

const app = express();
const PORT = process.env.PORT || 3000;

// Use port 0 to let the OS assign an available port
const PORT = 0;

// Set EJS as the template engine
app.set('view engine', 'ejs');
Expand All @@ -13,16 +16,42 @@ app.set('views', path.join(__dirname, 'views'));
// Serve static files from the 'public' directory
app.use(express.static(path.join(__dirname, 'public')));

// Function to get the latest release file URLs
async function getLatestFileUrls() {
const repo = 'ScriptBlocks/ScriptBlocks';
const filenames = ['scriptblocks.exe', 'scriptblocks.dmg', 'scriptblocks.tar.gz'];
const apiUrl = `https://api.github.com/repos/${repo}/releases/latest`;

try {
const response = await axios.get(apiUrl);
const assets = response.data.assets;

const fileUrls = {};
filenames.forEach(filename => {
const file = assets.find(asset => asset.name === filename);
fileUrls[filename] = file ? file.browser_download_url : null;
});

return fileUrls;
} catch (error) {
console.error('Error fetching the latest release data:', error);
return {};
}
}

// Define routes
app.get('/', (req, res) => {
res.render('index', { title: 'Home' });
app.get('/', async (req, res) => {
const fileUrls = await getLatestFileUrls();
res.render('index', { title: 'Home', fileUrls });
});

app.get('/', (req, res) => {
res.render('downloads', { title: 'Downloads' });
app.get('/store', async (req, res) => {
res.render('store', { title: 'Store' });
});

// Start the server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
const server = app.listen(PORT, () => {
// Retrieve the dynamically assigned port
const port = server.address().port;
console.log(`Server is running on http://localhost:${port}`);
});
72 changes: 72 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.7.5",
"bootstrap": "^5.3.3",
"ejs": "^3.1.10",
"express": "^4.19.2",
Expand Down
1 change: 0 additions & 1 deletion views/downloads.ejs

This file was deleted.

8 changes: 4 additions & 4 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ app.render()</code></pre>
<div class="downloads-section">
<h2>Downloads</h2>
<div class="btn-container">
<a class="btn btn-primary"><i class="fa-brands fa-windows"></i> Windows v1.0.0 (latest) 0MB</a>
<a class="btn btn-primary"><i class="fa-brands fa-apple"></i> MacOS v1.0.0 (latest) 0MB</a>
<a class="btn btn-primary"><i class="fa-brands fa-linux"></i> Linux v1.0.0 (latest) 0MB</a>
<a class="btn btn-primary" href="<%= fileUrls['scriptblocks.exe'] %>"><i class="fa-brands fa-windows"></i> Windows (latest)</a>
<a class="btn btn-primary" href="<%= fileUrls['scriptblocks.dmg'] %>"><i class="fa-brands fa-apple"></i> MacOS (latest)</a>
<a class="btn btn-primary" href="<%= fileUrls['scriptblocks.tar.gz'] %>"><i class="fa-brands fa-linux"></i> Linux (latest)</a>
</div>
<a href="/downloads"><i class="fa-solid fa-chevron-left"></i> Older versions</a>
<a href="https://github.com/ScriptBlocks/ScriptBlocks/releases/latest"><i class="fa-solid fa-chevron-left"></i> Older versions</a>
</div>
<div class="documentation-section">
<h2>Documentation</h2>
Expand Down
2 changes: 2 additions & 0 deletions views/partials/navbar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
<a href="/docs">Docs</a>
<span class="divider"></span>
<a href="https://github.com/ScriptBlocks/ScriptBlocks/releases/latest" target="_blank">Download</a>
<span class="divider"></span>
<a href="/store">Store</a>
</div>
</nav>
60 changes: 60 additions & 0 deletions views/store.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<!-- Include the head partial and pass the title -->
<%- include('partials/head', { title: title }) %>
<style>
body {
display: flex;
justify-content: center; /* Centers items horizontally */
align-items: center; /* Centers items vertically */
height: 100vh; /* Full viewport height, adjust if necessary */
flex-direction: column;
}
.store-item {
display: flex;
flex-direction: column; /* Align children vertically */
justify-content: center; /* Center content vertically within the store-item */
align-items: center; /* Center content horizontally within the store-item */
text-align: center; /* Center text within store-item */
}
.btn-container {
margin-top: 20px; /* Adjust margin if needed */
}
</style>
<script async src="https://js.stripe.com/v3/buy-button.js"></script>
<body>
<!-- Include the navbar partial -->
<%- include('partials/navbar') %>

<h1>Store</h1>

<split>
<div class="store-item">
<h2>ScriptBlocks License Key (1 Year)</h2>
<div class="btn-container">
<!-- <stripe-buy-button
buy-button-id="buy_btn_1PtVPsKgmSOOnEm6sWCe11G0"
publishable-key="pk_live_51PX5ReKgmSOOnEm6l1URdzBLvgR85mQgFaP53ctpmGNIofFADz6i89WfiaLbUDevqG6Gv0xnzWbkOVCjgBQUcJZN00OGYuPIcg"
>
</stripe-buy-button> -->
This product is unavailable.<br>Message from owner: If anyone knows how to use Stripe APIs, feel free to contribute to get a free license key.
</div>
</div>
<!-- <div class="store-item">
<h2>ScriptBlocks License Key (1 Year)</h2>
<div class="btn-container">
<stripe-buy-button
buy-button-id="buy_btn_1PtVPsKgmSOOnEm6sWCe11G0"
publishable-key="pk_live_51PX5ReKgmSOOnEm6l1URdzBLvgR85mQgFaP53ctpmGNIofFADz6i89WfiaLbUDevqG6Gv0xnzWbkOVCjgBQUcJZN00OGYuPIcg"
>
</stripe-buy-button>
</div>
</div> -->
</split>

<!-- Include the JavaScript for copy functionality -->
<script src="/js/script.js"></script>
</body>
</html>

0 comments on commit dd0cd0c

Please sign in to comment.