Skip to content

Commit

Permalink
fix: redownload files if actual file on Contentful changed
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Nov 2, 2020
1 parent c61df86 commit 53909a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions packages/gatsby-transformer-video/src/ffmpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,16 @@ export default class FFMPEG {
}

if (type === `ContentfulAsset`) {
path = await cacheContentfulVideo({
video,
cacheDir: this.cacheDirOriginal,
})
contentDigest = createContentDigest([
video.contentful_id,
video.file.url,
video.file.details.size,
])
path = await cacheContentfulVideo({
video,
contentDigest,
cacheDir: this.cacheDirOriginal,
})
}

if (!path) {
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-video/src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs"
import { access } from "fs-extra"
import { resolve } from "path"
import { resolve, extname } from "path"

import PQueue from "p-queue"
import axios from "axios"
Expand All @@ -18,12 +18,12 @@ const downloadCache = {}
* Retry is currently broken: https://github.com/gatsbyjs/gatsby/issues/22010
* Downloaded files are not cached properly: https://github.com/gatsbyjs/gatsby/issues/8324 & https://github.com/gatsbyjs/gatsby/pull/8379
*/
export async function cacheContentfulVideo({ video, cacheDir }) {
export async function cacheContentfulVideo({ video, cacheDir, contentDigest }) {
const {
file: { url, fileName },
} = video

const path = resolve(cacheDir, fileName)
const path = resolve(cacheDir, `${contentDigest}.${extname(fileName)}`)

try {
await access(path, fs.constants.R_OK)
Expand Down

0 comments on commit 53909a2

Please sign in to comment.