Permalink
Browse files

Added 'donations' information.

  • Loading branch information...
marcomontalbano committed Sep 21, 2018
1 parent d7e3b85 commit 963b69d571150f76cec7a67703905a26bdb7d58e
View
@@ -42,6 +42,7 @@
"babel-preset-env": "^1.7.0",
"dotenv": "^5.0.1",
"file-loader": "^2.0.0",
"https-proxy-agent": "^2.2.1",
"jest": "^23.5.0",
"netlify-lambda": "^0.4.0",
"node-fetch": "^2.1.2",
View
@@ -95,21 +95,21 @@ <h2>Features</h2>
</div>
</section>
<section>
<section class="donations">
<h2>Donations</h2>
<p>If you like this project and its useful to you, support it!</p>
<section>
<section class="invocations">
<div class="progress">
<div style="--percentage: 30.4;"></div>
<div style="--percentage: 0;"></div>
</div>
<small>38000 / 125000</small>
<small>&nbsp;</small>
</section>
<section>
<section class="runtime">
<div class="progress">
<div style="--percentage: 71;"></div>
<div style="--percentage: 0;"></div>
</div>
<small>71 / 100 hours</small>
<small>&nbsp;</small>
</section>
</section>
View
@@ -6,6 +6,8 @@ import ClipboardJS from 'clipboard';
import imageNotFound from './images/not-found.jpg';
import imageLoading from './images/loading.jpg';
const lambdaUrl = `${location.protocol}//${location.host}/.netlify/functions`;
const videoIcons = {
dailymotion: require('./images/providers/dailymotion.png'),
facebook: require('./images/providers/facebook.png'),
@@ -46,6 +48,32 @@ loadImage(imageNotFound);
let videoUrl_memo;
function updateQuota(data, functionType) {
let used = data.capabilities.functions[functionType].used;
let included = data.capabilities.functions[functionType].included;
let unit = data.capabilities.functions[functionType].unit;
const percentage = (used / included * 100);
if (unit === 'seconds') {
used = `~ ${Math.round(used / 3600)}`;
included /= 3600;
unit = 'hours';
}
$(`.donations .${functionType} .progress > div`).attr('style', `--percentage: ${percentage};`);
$(`.donations .${functionType} small`).text(`${used} / ${included} ${unit}`);
}
$.getJSON({
url: `${lambdaUrl}/netlify`
})
.done((data) => {
updateQuota(data, 'invocations');
updateQuota(data, 'runtime');
});
$('form').on('submit', function(e) {
e.preventDefault();
@@ -55,7 +83,6 @@ $('form').on('submit', function(e) {
const title = $form.find('[name="title"]').val();
const videoUrl = $form.find('[name="url"]').val();
const lambdaUrl = `${location.protocol}//${location.host}/.netlify/functions`;
const jsonUrl = `${lambdaUrl}/image-json?url=${videoUrl}`;
const imageUrl = `${lambdaUrl}/image?url=${videoUrl}`;
@@ -1,5 +1,5 @@
import VideoProvider from '../VideoProvider';
import fetch from 'node-fetch';
import fetch from '../proxiedFetch';
// https://developer.dailymotion.com/api
@@ -1,5 +1,5 @@
import VideoProvider from '../VideoProvider';
import fetch from 'node-fetch';
import fetch from '../proxiedFetch';
const { FACEBOOK_ACCESS_TOKEN } = process.env;
@@ -1,5 +1,5 @@
import VideoProvider from '../VideoProvider';
import fetch from 'node-fetch';
import fetch from '../proxiedFetch';
// https://vimeo.com/
@@ -1,5 +1,5 @@
import VideoProvider from '../VideoProvider';
import fetch from 'node-fetch';
import fetch from '../proxiedFetch';
// https://www.youtube.com/
@@ -1,4 +1,4 @@
import fetch from 'node-fetch';
import fetch from './proxiedFetch';
const { CLOUDINARY_CLOUD_NAME } = process.env;
@@ -0,0 +1,13 @@
import nodeFetch from 'node-fetch';
import HttpsProxyAgent from 'https-proxy-agent';
const { HTTP_PROXY, HTTPS_PROXY } = process.env;
module.exports = (url, options = {}) => {
if (HTTP_PROXY) {
options.agent = new HttpsProxyAgent(HTTP_PROXY);
}
return nodeFetch(url, options);
}
View
@@ -45,7 +45,7 @@ exports.handler = (event, context, callback) => {
.catch(error => {
callback(null, {
statusCode: 422,
body: JSON.stringify({ error: error.message })
body: JSON.stringify({ error: true })
});
});
};
View
@@ -46,7 +46,7 @@ exports.handler = (event, context, callback) => {
.catch(error => {
callback(null, {
statusCode: 422,
body: JSON.stringify({ error: error.message })
body: JSON.stringify({ error: true })
});
});
};
View
@@ -1,4 +1,4 @@
import fetch from 'node-fetch';
import fetch from './classes/proxiedFetch';
const { SITE_ID, NETLIFY_ACCESS_TOKEN } = process.env;
@@ -19,7 +19,7 @@ exports.handler = (event, context, callback) => {
.catch((error) => {
callback(null, {
statusCode: 422,
body: JSON.stringify({ error: error.message })
body: JSON.stringify({ error: true })
});
});
;
@@ -114,7 +114,7 @@ form {
height: 100%;
background-color: hsl(calc(120 - var(--percentage) / 100 * 120), 38%, 62%);
border-radius: 4px;
transition: width .8s, background-color .8s;
transition: width 1.2s, background-color 1.2s;
}
~ small {
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 963b69d

Please sign in to comment.