Skip to content

Commit

Permalink
Redirect avatar queries to seperate service
Browse files Browse the repository at this point in the history
  • Loading branch information
Electroid committed Jul 16, 2018
1 parent 0e0550a commit df9c758
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/dist/bundle.js

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

10 changes: 9 additions & 1 deletion api/src/api.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, error, invalidRequest } from "./http"
import { json, error, invalidRequest, redirect } from "./http"
import { usernameToUuid, uuidToProfile, uuidToUsernameHistory } from "./mojang"

# If given a username, find its UUID, otherwise
Expand Down Expand Up @@ -40,3 +40,11 @@ export user = (id) ->
cached_at: new Date()]
else
[invalidRequest("Invalid UUID '#{id}'"), null]

# Redirect to the avatar service to render the face of a user.
#
# @param {string} id - UUID of the user.
# @param {integer} size - Size in pixels of the avatar.
# @returns {promise<response>} - Avatar response as a PNG.
export avatar = (id = "Steve", size = 8) ->
redirect("https://avatar.ashcon.app/#{id}/#{size}")
4 changes: 2 additions & 2 deletions api/src/index.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "./util"
import { notFound, get } from "./http"
import { uuid, user } from "./api"
import { uuid, user, avatar } from "./api"

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

0 comments on commit df9c758

Please sign in to comment.