为什么我调用 Ghash 函数时会收到 [Promise]?

发布于 2025-01-11 18:59:30 字数 3332 浏览 0 评论 0原文

当我调用 Gash 函数时,我得到了一个承诺 我需要接收这个承诺的结果,它是一个哈希值,如果没有这个哈希值,

async function Ghash(name){
    let res = await fetch(`https://account.imperiomc.click/${name}.json?`+new Date().getTime()), json = await res.json(), hash, skin;
    if (json.skins.slim != null){
        hash = await json.skins.slim
        skin = "Alex"
    } else {
        hash = await json.skins.default
        skin = "Steve"
    }
    console.log("Skin model is "+skin)
    return hash
}
function populateAuthAccounts(){
    const authAccounts = ConfigManager.getAuthAccounts()
    const authKeys = Object.keys(authAccounts)
    if(authKeys.length === 0){
        return
    }
    const selectedUUID = ConfigManager.getSelectedAccount().uuid

    let authAccountStr = ''
    authKeys.map((val) => {
        const acc = authAccounts[val]
        const hash = Ghash(acc.displayName)
        const settingsCurrentAccounts = document.getElementById('settingsCurrentAccounts')
            let url = `https://account.imperiomc.click/preview/hash/${hash}?`+new Date().getTime();
            authAccountStr += `<div class="settingsAuthAccount" uuid="${acc.uuid}">
                <div class="settingsAuthAccountLeft">
                    <img class="settingsAuthAccountImage" alt="${acc.displayName}" src="${url}">
                </div>
                <div class="settingsAuthAccountRight">
                    <div class="settingsAuthAccountDetails">
                        <div class="settingsAuthAccountDetailPane">
                            <div class="settingsAuthAccountDetailTitle">Usuario</div>
                            <div class="settingsAuthAccountDetailValue">${acc.displayName}</div>
                        </div>
                        <div class="settingsAuthAccountDetailPane">
                            <div class="settingsAuthAccountDetailTitle">UUID</div>
                            <div class="settingsAuthAccountDetailValue">${acc.uuid}</div>
                        </div>
                    </div>
                    <div class="settingsAuthAccountActions">
                        <button class="settingsAuthAccountSelect" ${selectedUUID === acc.uuid ? 'selected>Selected Account &#10004;' : '>Selecciona una cuenta'}</button>
                        <div class="settingsAuthAccountWrapper">
                            <button class="settingsAuthAccountLogOut">Cerrar sesión</button>
                        </div>
                    </div>
                </div>
            </div>`
            settingsCurrentAccounts.innerHTML = authAccountStr  
    })
}

如果我将 authKeys.map((val) 的所有内容放在 .then 中,对于 示例(点击我) 功能 不适用于按钮,但哈希给了我我正在寻找的

结果将 Ghash 导出到哈希(没有任何 .then 或异步代码) 这与 为什么是[...] 而不是一个值? 如果我这样做,我就会遇到新问题,请参阅“如果我将 [...] 放入 .then...”版主(不要关闭),

如果有人可以的话告诉我我怎样才能修复它...我会非常感激你

When I call the Ghash function, I get a promise
I need to receive the result of this promise which is a hash, without that hash I cannot get the image I am looking for

async function Ghash(name){
    let res = await fetch(`https://account.imperiomc.click/${name}.json?`+new Date().getTime()), json = await res.json(), hash, skin;
    if (json.skins.slim != null){
        hash = await json.skins.slim
        skin = "Alex"
    } else {
        hash = await json.skins.default
        skin = "Steve"
    }
    console.log("Skin model is "+skin)
    return hash
}
function populateAuthAccounts(){
    const authAccounts = ConfigManager.getAuthAccounts()
    const authKeys = Object.keys(authAccounts)
    if(authKeys.length === 0){
        return
    }
    const selectedUUID = ConfigManager.getSelectedAccount().uuid

    let authAccountStr = ''
    authKeys.map((val) => {
        const acc = authAccounts[val]
        const hash = Ghash(acc.displayName)
        const settingsCurrentAccounts = document.getElementById('settingsCurrentAccounts')
            let url = `https://account.imperiomc.click/preview/hash/${hash}?`+new Date().getTime();
            authAccountStr += `<div class="settingsAuthAccount" uuid="${acc.uuid}">
                <div class="settingsAuthAccountLeft">
                    <img class="settingsAuthAccountImage" alt="${acc.displayName}" src="${url}">
                </div>
                <div class="settingsAuthAccountRight">
                    <div class="settingsAuthAccountDetails">
                        <div class="settingsAuthAccountDetailPane">
                            <div class="settingsAuthAccountDetailTitle">Usuario</div>
                            <div class="settingsAuthAccountDetailValue">${acc.displayName}</div>
                        </div>
                        <div class="settingsAuthAccountDetailPane">
                            <div class="settingsAuthAccountDetailTitle">UUID</div>
                            <div class="settingsAuthAccountDetailValue">${acc.uuid}</div>
                        </div>
                    </div>
                    <div class="settingsAuthAccountActions">
                        <button class="settingsAuthAccountSelect" ${selectedUUID === acc.uuid ? 'selected>Selected Account ✔' : '>Selecciona una cuenta'}</button>
                        <div class="settingsAuthAccountWrapper">
                            <button class="settingsAuthAccountLogOut">Cerrar sesión</button>
                        </div>
                    </div>
                </div>
            </div>`
            settingsCurrentAccounts.innerHTML = authAccountStr  
    })
}

if I put all the content of authKeys.map((val) inside .then, for example (click me)
the functions doesnt work with the buttons but the hash gives me the result I am looking for

i need to export the Ghash to hash (without any .then or async the code)
that this is not related to Why is [...] instead of a value? if i do that, i have new issue, see the "if I put [...] inside .then..." moderators (dont close)

if anyone can tellme how i can fix it... I would be very grateful to you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云雾 2025-01-18 18:59:30

也许你应该放置await,因为Gash函数是异步的,你需要等待响应。

const hash = await Ghash(acc.displayName)

Maybe you should put await, because the Gash function is asynchronous, you need to wait for the response.

const hash = await Ghash(acc.displayName)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文