Skip to content

Commit 83eac83

Browse files
authored
feat: switch avatar provider from Crafatar to VZGE (#1762)
Crafatar has become unreliable. VZGE (vzge.me) is a well-established alternative that has been running since 2015 with support for optimized formats (WebP/JXL), 3D renders, and proper caching. - Replace all Crafatar URLs with VZGE equivalents (face/full endpoints) - Add `unoptimized` to Next.js Image to bypass server-side fetching, since VZGE already serves optimized formats and requires non-generic User-Agent headers for server-side requests - Add custom User-Agent header to the server-side OG card avatar fetch - Adjust body render dimensions to match VZGE's 8:13 aspect ratio - Remove unused `scale` prop from Avatar component - Fix docker-compose.yml for MySQL 8.4 compatibility (default-authentication-plugin removed in 8.4) - Fix seed script to encrypt server password before inserting
1 parent 1fb830d commit 83eac83

8 files changed

Lines changed: 25 additions & 12 deletions

File tree

components/Avatar.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Image from 'next/image'
22
import { useEffect, useState } from 'react'
33

4-
const Avatar = ({ height, width, scale = '6', uuid, className = '', type = 'avatar' }) => {
4+
const Avatar = ({ height, width, uuid, className = '', type = 'avatar' }) => {
55
const [error, setError] = useState(null)
6-
let url = 'https://crafatar.com/'
6+
let url = 'https://vzge.me/'
77

88
if (type === 'avatar') {
9-
url += `avatars/${uuid}?size=${width}&overlay=true`
9+
url += `face/${width}/${uuid}.png`
1010
} else if (type === 'body') {
11-
url += `renders/body/${uuid}?scale=${scale}&overlay=true`
11+
url += `full/${height}/${uuid}.png`
1212
}
1313

1414
let fallbackSrc = (process.env.BASE_PATH || '') + '/images/'
@@ -22,6 +22,7 @@ const Avatar = ({ height, width, scale = '6', uuid, className = '', type = 'avat
2222

2323
return (
2424
<Image
25+
unoptimized
2526
width={width}
2627
height={height}
2728
onError={setError}

components/home/AccountPanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const AccountPanel = () => {
2020
{user
2121
? (
2222
<div className='flex flex-col items-center w-full gap-2'>
23-
<Avatar type='body' height='148' width='66' uuid={user.id} />
23+
<Avatar type='body' height='148' width='91' uuid={user.id} />
2424
<Link href='/dashboard' passHref>
2525
<Button>My Dashboard</Button>
2626
</Link>

components/player/PlayerAvatar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { usePalette } from '@universemc/react-palette'
66
const fullConfig = resolveConfig(tailwindConfig)
77

88
const PlayerAvatar = ({ id }) => {
9-
const { data: colourData } = usePalette(!id ? null : `https://crafatar.com/renders/body/${id}?scale=10&overlay=true`)
9+
const { data: colourData } = usePalette(!id ? null : `https://vzge.me/full/384/${id}.png`)
1010

1111
const backgroundStyle = {
1212
backgroundImage: `linear-gradient(-45deg, ${colourData.vibrant || fullConfig.theme.colors.accent['700']}, ${colourData.darkVibrant || fullConfig.theme.colors.accent['900']}, ${fullConfig.theme.colors.primary['500']})`,
@@ -16,7 +16,7 @@ const PlayerAvatar = ({ id }) => {
1616

1717
return (
1818
<div className='relative w-20 md:w-60 mx-auto flex justify-center'>
19-
<Avatar className='z-10 relative drop-shadow-[1rem_1rem_1rem_rgba(0,0,0,0.9)]' scale='5' uuid={id} type='body' height='225' width='100' />
19+
<Avatar className='z-10 relative drop-shadow-[1rem_1rem_1rem_rgba(0,0,0,0.9)]' uuid={id} type='body' height='225' width='138' />
2020
<div className='absolute hidden md:block top-0 left-0 h-full w-full translate-x-1/4'>
2121
<div className='block absolute top-0 left-0 bottom-0 right-0 z-10'>
2222
<div className='block rounded-3xl before:rounded-l-3xl absolute bottom-0 left-16 w-5/12 h-full -translate-x-1/2 -skew-x-10 before:contents before:absolute before:top-0 before:w-1/2 before:right-1/2 before:bottom-0 before:mix-blend-overlay before:bg-opacity-20 before:bg-white' style={backgroundStyle} />

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020
command:
2121
- --character-set-server=utf8mb4
2222
- --collation-server=utf8mb4_unicode_ci
23-
- --default-authentication-plugin=mysql_native_password
23+
- --mysql-native-password=ON
2424
- --sql-require-primary-key=ON
2525

2626
volumes:

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const nextConfig = (phase) => {
4545
remotePatterns: [
4646
{
4747
protocol: 'https',
48-
hostname: 'crafatar.com',
48+
hostname: 'vzge.me',
4949
pathname: '**'
5050
}
5151
]

public/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ self.addEventListener('push', function (event) {
55
body: data.body,
66
data: data.data,
77
tag: `bm-web-notification-${data.data.notificationId}`,
8-
icon: `https://crafatar.com/avatars/${data.data.actorId}?size=${256}&overlay=true`
8+
icon: `https://vzge.me/face/256/${data.data.actorId}.png`
99
}))
1010
})
1111

scripts/seed.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const {
2222
} = require('../server/test/fixtures')
2323
const createAppealComment = require('../server/test/fixtures/appeal-comment')
2424
const { hash } = require('../server/data/hash')
25+
const { encrypt } = require('../server/data/crypto')
2526

2627
const DB_NAME = process.env.DB_NAME || 'bm_local_dev'
2728
const FORCE = process.argv.includes('--force')
@@ -166,6 +167,11 @@ async function seed () {
166167

167168
// Create server
168169
const server = await createServer(playerConsole.id, DB_NAME)
170+
171+
if (server.password) {
172+
server.password = await encrypt(process.env.ENCRYPTION_KEY, server.password)
173+
}
174+
169175
await dbPool('bm_web_servers').insert(server)
170176
console.log(' - Created server connection')
171177

server/routes/opengraph/player.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module.exports = async function (ctx) {
9090
gravity: 'northwest'
9191
},
9292
{
93-
input: avatar,
93+
input: await sharp(avatar).resize(256, 416).toBuffer(),
9494
top: 109,
9595
left: 60,
9696
gravity: 'northwest'
@@ -103,7 +103,13 @@ module.exports = async function (ctx) {
103103

104104
const fetchAvatar = async function (id) {
105105
return new Promise((resolve, reject) => {
106-
const req = https.get(`https://crafatar.com/renders/body/${id}?scale=10&overlay=true&w=256`, res => {
106+
const options = {
107+
headers: {
108+
'User-Agent': 'BanManager-WebUI/1.0 (+https://banmanagement.com)'
109+
}
110+
}
111+
112+
const req = https.get(`https://vzge.me/full/416/${id}.png`, options, res => {
107113
if (res.statusCode < 200 || res.statusCode >= 300) {
108114
return reject(new Error(`Status Code: ${res.statusCode}`))
109115
}

0 commit comments

Comments
 (0)