型エラーを修正
This commit is contained in:
parent
27a1986569
commit
8356562e7a
@ -10,23 +10,23 @@
|
||||
*/
|
||||
// Requirements
|
||||
const ConfigManager = require('./configmanager')
|
||||
const LoggerUtil = require('./loggerutil')
|
||||
const Mojang = require('./mojang')
|
||||
const Microsoft = require('./microsoft')
|
||||
const logger = LoggerUtil('%c[AuthManager]', 'color: #a02d2a; font-weight: bold')
|
||||
const LoggerUtil = require('./loggerutil')
|
||||
const Mojang = require('./mojang')
|
||||
const Microsoft = require('./microsoft')
|
||||
const logger = LoggerUtil('%c[AuthManager]', 'color: #a02d2a; font-weight: bold')
|
||||
const loggerSuccess = LoggerUtil('%c[AuthManager]', 'color: #209b07; font-weight: bold')
|
||||
|
||||
async function validateSelectedMojang() {
|
||||
const current = ConfigManager.getSelectedAccount()
|
||||
const isValid = await Mojang.validate(current.accessToken, ConfigManager.getClientToken())
|
||||
if(!isValid){
|
||||
if (!isValid) {
|
||||
try {
|
||||
const session = await Mojang.refresh(current.accessToken, ConfigManager.getClientToken())
|
||||
ConfigManager.updateAuthAccount(current.uuid, session.accessToken)
|
||||
ConfigManager.save()
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
logger.debug('Error while validating selected profile:', err)
|
||||
if(err && err.error === 'ForbiddenOperationException'){
|
||||
if (err && err.error === 'ForbiddenOperationException') {
|
||||
// What do we do?
|
||||
}
|
||||
logger.log('Account access token is invalid.')
|
||||
@ -47,7 +47,7 @@ async function validateSelectedMicrosoft() {
|
||||
const MCExpiresAt = Date.parse(current.expiresAt)
|
||||
const MCExpired = now > MCExpiresAt
|
||||
|
||||
if(MCExpired) {
|
||||
if (MCExpired) {
|
||||
const MSExpiresAt = Date.parse(current.microsoft.expires_at)
|
||||
const MSExpired = now > MSExpiresAt
|
||||
|
||||
@ -83,12 +83,12 @@ async function validateSelectedMicrosoft() {
|
||||
* @param {string} password The account password.
|
||||
* @returns {Promise.<Object>} Promise which resolves the resolved authenticated account object.
|
||||
*/
|
||||
exports.addAccount = async function(username, password){
|
||||
exports.addAccount = async function (username, password) {
|
||||
try {
|
||||
const session = await Mojang.authenticate(username, password, ConfigManager.getClientToken())
|
||||
if(session.selectedProfile != null){
|
||||
if (session.selectedProfile != null) {
|
||||
const ret = ConfigManager.addAuthAccount(session.selectedProfile.id, session.accessToken, username, session.selectedProfile.name)
|
||||
if(ConfigManager.getClientToken() == null){
|
||||
if (ConfigManager.getClientToken() == null) {
|
||||
ConfigManager.setClientToken(session.clientToken)
|
||||
}
|
||||
ConfigManager.save()
|
||||
@ -97,7 +97,7 @@ exports.addAccount = async function(username, password){
|
||||
throw new Error('NotPaidAccount')
|
||||
}
|
||||
|
||||
} catch (err){
|
||||
} catch (err) {
|
||||
return Promise.reject(err)
|
||||
}
|
||||
}
|
||||
@ -109,10 +109,10 @@ exports.addAccount = async function(username, password){
|
||||
* @param {string} uuid The UUID of the account to be removed.
|
||||
* @returns {Promise.<void>} Promise which resolves to void when the action is complete.
|
||||
*/
|
||||
exports.removeAccount = async function(uuid){
|
||||
exports.removeAccount = async function (uuid) {
|
||||
try {
|
||||
const authAcc = ConfigManager.getAuthAccount(uuid)
|
||||
if(authAcc.type === 'microsoft'){
|
||||
if (authAcc.type === 'microsoft') {
|
||||
ConfigManager.removeAuthAccount(uuid)
|
||||
ConfigManager.save()
|
||||
return Promise.resolve()
|
||||
@ -121,7 +121,7 @@ exports.removeAccount = async function(uuid){
|
||||
ConfigManager.removeAuthAccount(uuid)
|
||||
ConfigManager.save()
|
||||
return Promise.resolve()
|
||||
} catch (err){
|
||||
} catch (err) {
|
||||
return Promise.reject(err)
|
||||
}
|
||||
}
|
||||
@ -136,14 +136,13 @@ exports.removeAccount = async function(uuid){
|
||||
* @returns {Promise.<boolean>} Promise which resolves to true if the access token is valid,
|
||||
* otherwise false.
|
||||
*/
|
||||
exports.validateSelected = async function(){
|
||||
exports.validateSelected = async function () {
|
||||
try {
|
||||
if (ConfigManager.getSelectedAccount() === 'microsoft') {
|
||||
const validate = await validateSelectedMicrosoft()
|
||||
return validate
|
||||
const account = ConfigManager.getSelectedAccount()
|
||||
if (account.type === 'microsoft') {
|
||||
return await validateSelectedMicrosoft()
|
||||
} else {
|
||||
const validate = await validateSelectedMojang()
|
||||
return validate
|
||||
return await validateSelectedMojang()
|
||||
}
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
@ -155,7 +154,7 @@ exports.addMSAccount = async authCode => {
|
||||
const accessToken = await Microsoft.getAccessToken(authCode)
|
||||
const MCAccessToken = await Microsoft.authMinecraft(accessToken.access_token)
|
||||
const minecraftBuyed = await Microsoft.checkMCStore(MCAccessToken.access_token)
|
||||
if(!minecraftBuyed)
|
||||
if (!minecraftBuyed)
|
||||
return Promise.reject({
|
||||
message: 'You didn\'t buy Minecraft! Please use another Microsoft account or buy Minecraft.'
|
||||
})
|
||||
@ -164,7 +163,7 @@ exports.addMSAccount = async authCode => {
|
||||
ConfigManager.save()
|
||||
|
||||
return ret
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
2605
package-lock.json
generated
2605
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user