我有一个正在运行的应用程序,但在升级包后停止工作。节点持久问题。需要升级,所以请不要建议降级。:)
获取物品的原始工作版本:
function getAccounts (masterPassword) {
// use getItemSync to fetch accounts
var encryptedAccount = storage.getItemSync('accounts')
var accounts = []
// decrypt
if (typeof encryptedAccount !== 'undefined') {
var bytes = crypto.AES.decrypt(encryptedAccount, masterPassword)
accounts = JSON.parse(bytes.toString(crypto.enc.Utf8))
}
// return accounts array
return accounts
}
function saveAccounts (accounts, masterPassword) {
// encrypt accounts
var encryptedAccounts = crypto.AES.encrypt(JSON.stringify(accounts), masterPassword)
// setItemSync
storage.setItemSync('accounts', encryptedAccounts.toString())
return accounts
}
我遵循了这个问题:node-persist - NodeJS 和 MDN:https ://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage以及 GitHub 中的文档:https:// github.com/simonlast/node-persist但仍然无法正常工作。
错误。主要调用:
var createdAccount = createAccount({
username: argv.username,
password: argv.password
}, argv.masterPassword)
console.log('Account created!')
console.log(createdAccount)
} catch (e) {
console.log('Unable to create account.')
console.error(e)
}
使用函数 createAccount:
function createAccount (account, masterPassword) {
var accounts = getAccounts(masterPassword)
accounts.push(account)
saveAccounts(accounts, masterPassword)
return account
}
失败:
SyntaxError: Unexpected end of JSON input
在这一行:
accounts = JSON.parse(bytes.toString(crypto.enc.Utf8))
你能提供新版本吗storage.getItem()
?storage.setItem()