Skip to content

Commit d4ca1d4

Browse files
authored
fix: include extension when generating hash (#46)
1 parent 42dcdd5 commit d4ca1d4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/utils/deploy.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createHash } from 'node:crypto'
22
import { access } from 'node:fs/promises'
3+
import { extname } from 'pathe'
34
import { joinURL } from 'ufo'
45
import { ofetch } from 'ofetch'
56
import { createStorage } from 'unstorage'
@@ -9,9 +10,10 @@ import { withTilde, MAX_ASSET_SIZE, MAX_UPLOAD_CHUNK_SIZE, MAX_UPLOAD_ATTEMPTS,
910
import prettyBytes from 'pretty-bytes'
1011
import { gzipSize as getGzipSize } from 'gzip-size'
1112

12-
export function hashFile(data) {
13+
export function hashFile(filePath, data) {
14+
const extension = extname(filePath).substring(1)
1315
return createHash('sha256')
14-
.update(data)
16+
.update(data + extension)
1517
.digest('hex')
1618
.slice(0, 32) // required by Cloudflare
1719
}
@@ -112,7 +114,7 @@ export async function getFile(storage, path, encoding = 'utf-8') {
112114
size: dataAsBuffer.length,
113115
gzipSize,
114116
encoding,
115-
hash: hashFile(data),
117+
hash: hashFile(path, data),
116118
contentType: mime.getType(path) || 'application/octet-stream'
117119
}
118120
}

0 commit comments

Comments
 (0)