Skip to content

Commit

Permalink
Merge pull request #52 from TibiNonEst/model-query-option
Browse files Browse the repository at this point in the history
Add ability to request skin model by query params
  • Loading branch information
astei authored Mar 28, 2022
2 parents 1ed7910 + 2a45a62 commit 5f98fd7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,5 @@ async function renderImage(skin: Response, request: CraftheadRequest): Promise<R
}

function getCacheKey(interpreted: CraftheadRequest): string {
return `https://crafthead.net/__public${CACHE_BUST}/${interpreted.requested}/${interpreted.armored}/${interpreted.identity.toLocaleLowerCase('en-US')}/${interpreted.size}`
return `https://crafthead.net/__public${CACHE_BUST}/${interpreted.requested}/${interpreted.armored}/${interpreted.model}/${interpreted.identity.toLocaleLowerCase('en-US')}/${interpreted.size}`
}
6 changes: 5 additions & 1 deletion worker/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface CraftheadRequest {
identityType: IdentityKind;
size: number;
armored: boolean;
model: string | null;
}

function stringKindToRequestedKind(kind: string): RequestedKind | null {
Expand Down Expand Up @@ -58,6 +59,9 @@ export function interpretRequest(request: Request): CraftheadRequest | null {
url.href = url.href.substring(0, url.href.length - 4)
}

let model = url.searchParams.get("model")
if (model && !["slim", "default"].includes(model)) model = null

let armored = false
let sliceAmt = 1

Expand Down Expand Up @@ -95,5 +99,5 @@ export function interpretRequest(request: Request): CraftheadRequest | null {
return null
}

return { requested, identityType, identity, size, armored }
return { requested, identityType, identity, size, armored, model }
}
2 changes: 1 addition & 1 deletion worker/services/mojang/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class MojangRequestService {
status: 200,
headers: {
'X-Crafthead-Profile-Cache-Hit': lookup.source,
'X-Crafthead-Skin-Model': textureResponse.model || 'default'
'X-Crafthead-Skin-Model': request.model || textureResponse.model || 'default'
}
});
}
Expand Down

0 comments on commit 5f98fd7

Please sign in to comment.