Skip to content

Commit df9c758

Browse files
committed
Redirect avatar queries to seperate service
1 parent 0e0550a commit df9c758

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

api/dist/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/src/api.coffee

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { json, error, invalidRequest } from "./http"
1+
import { json, error, invalidRequest, redirect } from "./http"
22
import { usernameToUuid, uuidToProfile, uuidToUsernameHistory } from "./mojang"
33

44
# If given a username, find its UUID, otherwise
@@ -40,3 +40,11 @@ export user = (id) ->
4040
cached_at: new Date()]
4141
else
4242
[invalidRequest("Invalid UUID '#{id}'"), null]
43+
44+
# Redirect to the avatar service to render the face of a user.
45+
#
46+
# @param {string} id - UUID of the user.
47+
# @param {integer} size - Size in pixels of the avatar.
48+
# @returns {promise<response>} - Avatar response as a PNG.
49+
export avatar = (id = "Steve", size = 8) ->
50+
redirect("https://avatar.ashcon.app/#{id}/#{size}")

api/src/index.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./util"
22
import { notFound, get } from "./http"
3-
import { uuid, user } from "./api"
3+
import { uuid, user, avatar } from "./api"
44

55
addEventListener("fetch", (event) ->
66
event.respondWith(route(event.request)))
@@ -13,5 +13,5 @@ route = (request) ->
1313
if method == "user"
1414
[err, res] = await user(id)
1515
else if method == "avatar"
16-
res = get("https://us-central1-stratus-197318.cloudfunctions.net/avatar/#{id}/#{extra}", ttl: 86400)
16+
res = avatar(id, extra)
1717
err || res || notFound("Unknown Route")

0 commit comments

Comments
 (0)