fix: omit default params in avatar URL for cleaner URLs
- getAvatarUrl now omits direction=2, head_direction=3, size=m when they match defaults - URL now matches: figure=xxx&effect=14&img_format=apng
This commit is contained in:
1 parent
3213126a12
commit
0aef27efc4
2 files changed
+10
-7
No files matched your search
@@ -39,13 +39,13 @@ describe("getAvatarUrl", () => {
|
|||||||
envMock.env.NEXT_PUBLIC_IMAGER_URL = "https://img.example.com";
|
envMock.env.NEXT_PUBLIC_IMAGER_URL = "https://img.example.com";
|
||||||
});
|
});
|
||||||
|
|
||||||
it("builds a query string with defaults", () => {
|
it("builds a query string with defaults (omits default params)", () => {
|
||||||
const url = getAvatarUrl("hd-180-1");
|
const url = getAvatarUrl("hd-180-1");
|
||||||
expect(url.startsWith("https://img.example.com?")).toBe(true);
|
expect(url.startsWith("https://img.example.com?")).toBe(true);
|
||||||
expect(url).toContain("figure=hd-180-1");
|
expect(url).toContain("figure=hd-180-1");
|
||||||
expect(url).toContain("direction=2");
|
expect(url).not.toContain("direction=2");
|
||||||
expect(url).toContain("head_direction=3");
|
expect(url).not.toContain("head_direction=3");
|
||||||
expect(url).toContain("size=m");
|
expect(url).not.toContain("size=m");
|
||||||
expect(url).toContain("img_format=apng");
|
expect(url).toContain("img_format=apng");
|
||||||
expect(url).toContain("effect=14");
|
expect(url).toContain("effect=14");
|
||||||
});
|
});
|
||||||
|
|||||||
+6
-3
@@ -29,6 +29,7 @@ export function resolveImagerBase(): string {
|
|||||||
* Build an avatar image URL using the configured imager.
|
* Build an avatar image URL using the configured imager.
|
||||||
* Uses effect=14 and img_format=apng by default for epicnabbo.nl compatibility.
|
* Uses effect=14 and img_format=apng by default for epicnabbo.nl compatibility.
|
||||||
* Automatically converts old Habbo figure format to new epicnabbo.nl format.
|
* Automatically converts old Habbo figure format to new epicnabbo.nl format.
|
||||||
|
* Omits default parameters (direction=2, head_direction=3, size=m) for cleaner URLs.
|
||||||
*/
|
*/
|
||||||
export function getAvatarUrl(
|
export function getAvatarUrl(
|
||||||
figure: string,
|
figure: string,
|
||||||
@@ -48,13 +49,15 @@ export function getAvatarUrl(
|
|||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
figure: convertedFigure,
|
figure: convertedFigure,
|
||||||
direction: String(direction),
|
|
||||||
head_direction: String(headDirection),
|
|
||||||
size,
|
|
||||||
img_format,
|
img_format,
|
||||||
effect: String(effect),
|
effect: String(effect),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Only add non-default params
|
||||||
|
if (direction !== 2) params.set("direction", String(direction));
|
||||||
|
if (headDirection !== 3) params.set("head_direction", String(headDirection));
|
||||||
|
if (size !== "m") params.set("size", size);
|
||||||
|
|
||||||
if (headOnly) params.set("headonly", "1");
|
if (headOnly) params.set("headonly", "1");
|
||||||
if (gesture) params.set("gesture", gesture);
|
if (gesture) params.set("gesture", gesture);
|
||||||
if (action) params.set("action", action);
|
if (action) params.set("action", action);
|
||||||
|
|||||||
Reference in new issue
Block a user