Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => {
sourceNodeArgs.store = configureMockStore()
ListObjectsMock.mockReset()
// Mock out Gatby's source-filesystem API.
sourceFilesystem.createRemoteFileNode = jest
.fn()
.mockReturnValue(FileSystemNodeMock.build())
})
async downloadStripeHostedFile(url, type, parentNodeId) {
if (!url) return null;
try {
const fileNode = await createRemoteFileNode({
url,
ext: `.${type}`,
parentNodeId,
...this.createRemoteArgs
});
return this.validateFileNodes(fileNode);
} catch (e) {
console.log(
`\x1b[1;31m\u2715\x1b[0m We were unable to download files that Stripe was hosting\nURL: ${url}\n` +
`Error: ${e.message}\n`
);
return null;
}
}
async function createImageNodes ({
entity,
createNode,
createNodeId,
store,
cache,
imageName,
imageCacheKey
}) {
let fileNode
try {
fileNode = await createRemoteFileNode({
url: entity.data.url,
store,
cache,
createNode,
createNodeId
})
} catch (e) {
console.log(e)
}
if (fileNode) {
await cache.set(imageCacheKey, {
fileNodeID: fileNode.id,
modified: entity.data.modified
})
console.log('Image downloaded: ' + imageName)
return {
async function createFileNode({
store,
cache,
createNode,
createNodeId,
url,
node
}) {
try {
const fileNode = await createRemoteFileNode({
url,
parentNodeId: node.id,
store,
cache,
createNode,
createNodeId
});
if (fileNode) {
await saveToCache(cache, cacheKey(url), {
fileNodeId: fileNode.id,
updated: node.updated
});
return fileNode.id;
}
} catch (e) {
.map(url => {
const createRemoteArgs = authFlag
? { url, parentNodeId, ...this.createRemoteArgs }
: { url, parentNodeId, ...createRemoteArgsWithoutAuth };
return createRemoteFileNode(createRemoteArgs);
});
const fileNodes = await Promise.all(fileNodePromises);
async createAssetNode(path) {
const assetNode = await createRemoteFileNode({
url: path,
store: this.store,
cache: this.cache,
createNode: this.createNode,
createNodeId: () => generateNodeId('Asset', `${hash(path)}`),
})
return this.checkIfDownloadIsSuccessful(path, assetNode)
}
async createImageNode(path) {
const imageNode = await createRemoteFileNode({
url: path,
store: this.store,
cache: this.cache,
createNode: this.createNode,
createNodeId: () => generateNodeId('Image', `${hash(path)}`),
})
return this.checkIfDownloadIsSuccessful(path, imageNode)
}