Skip to content

Commit c45c451

Browse files
committed
fix(grabber): Crafatar's false negative issue
1 parent b237899 commit c45c451

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/helper.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ import * as logger from './logger'
66

77
export async function download (apiPath: string, dest: string): Promise<void> {
88
logger.Assets.info('DOWNLOAD', apiPath)
9-
const {data} = await axios.get<fs.ReadStream>(apiPath, {responseType: 'stream'})
9+
const {data} = await axios.get<fs.ReadStream>(apiPath, {
10+
headers: {'Accept': 'image/*'},
11+
responseType: 'stream',
12+
})
1013
.catch(err => {
14+
// Sometimes Crafatar responds with 500 AND the correct image. If this is
15+
// the case, just return the body which is enough of use.
16+
if (err.response.headers['content-length'] && err.response.headers['content-type'].startsWith('image/')) {
17+
return {data: err.response.data}
18+
}
1119
logger.Assets.error('DOWNLOAD', apiPath, err.toJSON())
1220
return {data: null}
1321
})
@@ -38,7 +46,7 @@ export function mergeStats (data: McPlayerStatsJson): McPlayerStatsJson {
3846
}
3947

4048
export function defaultSkin (uuid: LongUuid): 'Alex' | 'Steve' {
41-
// great thanks to Minecrell for research into Minecraft and Java's UUID hashing!
49+
// Great thanks to Minecrell for research into Minecraft and Java's UUID hashing!
4250
// https://git.io/xJpV
4351
// MC uses `uuid.hashCode() & 1` for alex
4452
// that can be compacted to counting the LSBs of every 4th byte in the UUID

0 commit comments

Comments
 (0)