Skip to content

Commit a0f23a2

Browse files
authored
Fix normalized skins uploading to Mojang (#4646)
* Fix normalized skins uploading to Mojang * Run app-frontend > fix
1 parent 08e316a commit a0f23a2

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

apps/app-frontend/src/components/ui/skin/EditSkinModal.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import {
130130
remove_custom_skin,
131131
type Skin,
132132
type SkinModel,
133+
type SkinTextureUrl,
133134
unequip_skin,
134135
} from '@/helpers/skins.ts'
135136
@@ -142,7 +143,7 @@ const currentSkin = ref<Skin | null>(null)
142143
const shouldRestoreModal = ref(false)
143144
const isSaving = ref(false)
144145
145-
const uploadedTextureUrl = ref<string | null>(null)
146+
const uploadedTextureUrl = ref<SkinTextureUrl | null>(null)
146147
const previewSkin = ref<string>('')
147148
148149
const variant = ref<SkinModel>('CLASSIC')
@@ -188,7 +189,7 @@ function getSortedCapeExcluding(excludeId: string): Cape | undefined {
188189
189190
async function loadPreviewSkin() {
190191
if (uploadedTextureUrl.value) {
191-
previewSkin.value = uploadedTextureUrl.value
192+
previewSkin.value = uploadedTextureUrl.value.normalized
192193
} else if (currentSkin.value) {
193194
try {
194195
previewSkin.value = await get_normalized_skin_texture(currentSkin.value)
@@ -253,11 +254,11 @@ async function show(e: MouseEvent, skin?: Skin) {
253254
modal.value?.show(e)
254255
}
255256
256-
async function showNew(e: MouseEvent, skinTextureUrl: string) {
257+
async function showNew(e: MouseEvent, skinTextureUrl: SkinTextureUrl) {
257258
mode.value = 'new'
258259
currentSkin.value = null
259260
uploadedTextureUrl.value = skinTextureUrl
260-
variant.value = await determineModelType(skinTextureUrl)
261+
variant.value = await determineModelType(skinTextureUrl.original)
261262
selectedCape.value = undefined
262263
visibleCapeList.value = []
263264
initVisibleCapeList()
@@ -267,7 +268,7 @@ async function showNew(e: MouseEvent, skinTextureUrl: string) {
267268
modal.value?.show(e)
268269
}
269270
270-
async function restoreWithNewTexture(skinTextureUrl: string) {
271+
async function restoreWithNewTexture(skinTextureUrl: SkinTextureUrl) {
271272
uploadedTextureUrl.value = skinTextureUrl
272273
await loadPreviewSkin()
273274
@@ -361,7 +362,7 @@ async function save() {
361362
let textureUrl: string
362363
363364
if (uploadedTextureUrl.value) {
364-
textureUrl = uploadedTextureUrl.value
365+
textureUrl = uploadedTextureUrl.value.original
365366
} else {
366367
textureUrl = currentSkin.value!.texture
367368
}

apps/app-frontend/src/helpers/skins.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export interface Skin {
2222
is_equipped: boolean
2323
}
2424

25+
export interface SkinTextureUrl {
26+
original: string
27+
normalized: string
28+
}
29+
2530
export const DEFAULT_MODEL_SORTING = ['Steve', 'Alex'] as string[]
2631

2732
export const DEFAULT_MODELS: Record<string, SkinModel> = {

apps/app-frontend/src/pages/Skins.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { get_default_user, login as login_flow, users } from '@/helpers/auth'
3131
import type { RenderResult } from '@/helpers/rendering/batch-skin-renderer.ts'
3232
import { generateSkinPreviews, skinBlobUrlMap } from '@/helpers/rendering/batch-skin-renderer.ts'
3333
import { get as getSettings } from '@/helpers/settings.ts'
34-
import type { Cape, Skin } from '@/helpers/skins.ts'
34+
import type { Cape, Skin, SkinTextureUrl } from '@/helpers/skins.ts'
3535
import {
3636
equip_skin,
3737
filterDefaultSkins,
@@ -245,16 +245,18 @@ function openUploadSkinModal(e: MouseEvent) {
245245
246246
function onSkinFileUploaded(buffer: ArrayBuffer) {
247247
const fakeEvent = new MouseEvent('click')
248-
normalize_skin_texture(`data:image/png;base64,` + arrayBufferToBase64(buffer)).then(
249-
(skinTextureNormalized: Uint8Array) => {
250-
const skinTexUrl = `data:image/png;base64,` + arrayBufferToBase64(skinTextureNormalized)
251-
if (editSkinModal.value && editSkinModal.value.shouldRestoreModal) {
252-
editSkinModal.value.restoreWithNewTexture(skinTexUrl)
253-
} else {
254-
editSkinModal.value?.showNew(fakeEvent, skinTexUrl)
255-
}
256-
},
257-
)
248+
const originalSkinTexUrl = `data:image/png;base64,` + arrayBufferToBase64(buffer)
249+
normalize_skin_texture(originalSkinTexUrl).then((skinTextureNormalized: Uint8Array) => {
250+
const skinTexUrl: SkinTextureUrl = {
251+
original: originalSkinTexUrl,
252+
normalized: `data:image/png;base64,` + arrayBufferToBase64(skinTextureNormalized),
253+
}
254+
if (editSkinModal.value && editSkinModal.value.shouldRestoreModal) {
255+
editSkinModal.value.restoreWithNewTexture(skinTexUrl)
256+
} else {
257+
editSkinModal.value?.showNew(fakeEvent, skinTexUrl)
258+
}
259+
})
258260
}
259261
260262
function onUploadCanceled() {

0 commit comments

Comments
 (0)