Skip to content

Commit

Permalink
append to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Feb 5, 2024
1 parent 14da551 commit 8428987
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 6 additions & 4 deletions example/hashes.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"index.js": "1f49271e60e53b00-",
"index.html": "8e27d2f424d541b4-",
"index.css": "712708f47c759d37-",
"images/sample.jpg": "4c67e0488b3afa81-"
"index.js": "1f49271e60e53b00",
"index.html": "8e27d2f424d541b4",
"index.css": "712708f47c759d37",
"images/sample.jpg": "4c67e0488b3afa81",
"test.html": "6944c8b16078a588",
"test.css": "b305efc33fe211f7"
}
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,8 @@ async function fastifyStatic (fastify, opts) {
}

function getHashedStaticPath (unhashedRelativePath) {
const relativeDirectory = path.posix.dirname(unhashedRelativePath)
const fileName = path.basename(unhashedRelativePath)
const hash = fastify[kFileHashes].get(unhashedRelativePath)
return `${prefix}${relativeDirectory === '.' ? '' : `${relativeDirectory}/`}${hash ?? ''}${fileName}`
return `${prefix}${unhashedRelativePath}${hash ? `.${hash}` : ''}`
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fastq = require('fastq')
async function generateFileHash (filePath) {
try {
const fileBuffer = await fs.readFile(filePath)
return `${crypto.createHash('md5').update(fileBuffer).digest('hex').slice(0, 16)}-`
return crypto.createHash('md5').update(fileBuffer).digest('hex').slice(0, 16)
} catch {
return ''
}
Expand Down

0 comments on commit 8428987

Please sign in to comment.