Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = async function() {
let cache = flatcache.load("github-stargazers", path.resolve("./_datacache"));
let key = getCacheKey();
let cachedData = cache.getKey(key);
if(!cachedData) {
console.log( "Fetching new github stargazers count…" );
// https://developer.github.com/v3/repos/#get
try {
let newData = await fetch("https://api.github.com/repos/11ty/eleventy")
.then(res => res.json())
.then(json => {
return {
stargazers: json.stargazers_count
};
});
cache.setKey(key, newData);
cache.save();
module.exports = async function() {
let cache = flatcache.load("google-fonts-roboto-mono", path.resolve("./_datacache"));
let key = getCacheKey();
let cachedData = cache.getKey(key);
if(!cachedData) {
console.log( "Fetching new Roboto Mono CSS…" );
try {
// let fontSrcUrl = "https://fonts.googleapis.com/css?family=Roboto+Mono&display=swap";
let fontSrcUrl = "https://fonts.googleapis.com/css?family=Roboto+Mono:400,700display=swap";
let newData = await fetch(fontSrcUrl, {
headers: {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
}
})
.then(res => res.text());
cache.setKey(key, newData);
cache.save();
create: function ( cacheId, _path ) {
var fs = require( 'fs' );
var flatCache = require( 'flat-cache' );
var cache = flatCache.load( cacheId, _path );
var assign = require( 'object-assign' );
var normalizedEntries = { };
var removeNotFoundFiles = function removeNotFoundFiles() {
const cachedEntries = cache.keys();
// remove not found entries
cachedEntries.forEach( function remover( fPath ) {
try {
fs.statSync( fPath );
} catch (err) {
if ( err.code === 'ENOENT' ) {
cache.removeKey( fPath );
}
}
} );
};
import { auth as oauth2 } from 'google-oauth2-node';
import { RoutingModule, Period, Graph } from '../../common/interfaces';
import { fetch } from 'guess-ga';
const clientId = '329457372673-hda3mp2vghisfobn213jpj8ck1uohi2d.apps.googleusercontent.com';
const clientSecret = '4camaoQPOz9edR-Oz19vg-lN';
const scope = 'https://www.googleapis.com/auth/analytics.readonly';
const year = 365 * 24 * 60 * 60 * 1000;
const flatCache = require('flat-cache');
const cache = flatCache.load('guess-plugin');
const id = (r: T) => r;
export interface Config {
jwt?: any;
viewId: string;
routes: RoutingModule[];
formatter?: (path: string) => string;
period?: Period;
}
const serializePeriod = (period: Period) => `${period.startDate.getTime()}-${period.endDate.getTime()}`;
export const getReport = (c: Config): Promise => {
const period = c.period || { startDate: new Date(Date.now() - year), endDate: new Date() };
const key = `${c.viewId}-${serializePeriod(period)}`;
loadCache(type) {
let cache;
if (this[`_${type}`]) {
cache = this[`_${type}`];
} else {
cache = flatCache.load(type, this._cacheDir);
this[`_${type}`] = cache;
}
return cache;
}
constructor (workflow: string, workspace: string) {
this.file = `.${workflow || 'workflow'}-cache`
this.cache = load(this.file, path.resolve(workspace || process.cwd()))
this.get = this.cache.getKey.bind(this.cache)
this.set = this.cache.setKey.bind(this.cache)
this.all = this.cache.all.bind(this.cache)
this.del = this.cache.removeKey.bind(this.cache)
this.save = this.cache.save.bind(this.cache, true)
process.on('exit', () => {
if (this.cache.keys().length > 0) {
this.save()
}
})
}
}