Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const tasks = remoteFiles.map(({ url, metadataPath, ...options }) => cb => {
cb = once(cb)
const start = Date.now()
console.log('Requesting', url)
// I tried doing this by adding streams to the zipfile, but it's really hard
// to catch errors when trying to download an image, so you end up with
// corrupt files in the zip. This uses a bit more memory, but images are
// only added once they have downloaded correctly
ky.get(url)
.arrayBuffer()
.then(arrBuf => {
console.log('Req end in ' + (Date.now() - start) + 'ms ' + metadataPath)
zipfile.addBuffer(Buffer.from(arrBuf), metadataPath, {
...options,
store: true
})
cb()
})
.catch(err => {
missing.push(metadataPath)
console.log('Error downloading file ' + metadataPath, err)
cb()
})
})
const start = Date.now()
history = JSON.parse(json);
} catch (err) {
console.error(
'Error loading cached shortUrls from localStorage:',
err
);
localStorage.removeItem('shortUrls');
history = [];
}
}
if (history.length > 0) {
const url = new URL(window.location.origin);
url.pathname = '/shortened';
url.searchParams.set('urls', history.join(','));
const { environments } = await ky.get(url).json();
cache = environments;
return environments;
} else {
cache = [];
}
}
return cache;
},
async fetchCommits() {
const { owner, repo } = this.state;
this.startLoad('commits');
try {
const commitsUrl = new URL(window.location.origin);
commitsUrl.pathname = '/githubapi/commits';
commitsUrl.searchParams.set('owner', owner);
commitsUrl.searchParams.set('repo', repo);
commitsUrl.searchParams.set('per_page', 100);
const commits = await ky.get(commitsUrl).json();
this.setState({ commits });
} catch (error) {
this.setState({ error });
} finally {
this.finishLoad('commits');
}
}
async decode(code) {
if (code.startsWith('s-')) {
code = code.slice(2);
}
const params = await ky.get(`/lengthenit/${code}`).json();
return params;
},