<commit_before>import {encrypt, decrypt} from './aes'
import {SYNC_PLATFORMS} from '../helpers/const'
import {detectLoginStatus} from '../../electron/ipc_render'

const SPLIT_FLAG = '\n'

// 获取帐号配置信息
export function getAccountMap() {
  let accountMap = {}
  SYNC_PLATFORMS.forEach((platform) => {
    let pair = localStorage.getItem(platform) || ''
    pair = pair && decrypt(pair).split(SPLIT_FLAG)
    accountMap[platform] = {
      username: pair && pair[0],
      password: pair && pair[1],
      repo: pair && pair[2]
    }
  })

  return accountMap
}

export function updateAccount(platform, userName, password = '', repo = '') {
  if (!userName) {
    return
  }

  localStorage.setItem(platform, encrypt(`${userName}${SPLIT_FLAG}${password}${SPLIT_FLAG}${repo}`))
}

export function removeAccountByPlatform(platform) {
  localStorage.removeItem(platform)
}

export function getCookiesByPlatform(platform = 'zhihu') {
  if (platform) {
    return localStorage.getItem(`${platform}_cookie`)
  }

  return null
}

export function setCookiesByPlatform(platform, cookie) {
  if (platform && cookie) {
    localStorage.setItem(`${platform}_cookie`, cookie)
  } else {
    localStorage.removeItem(`${platform}_cookie`)
  }
}

export function getLoginDetails(accountMap) {
  let req = {}
  // zhihu只需要cookie即可
  if (accountMap.zhihu) {
    let cookie = getCookiesByPlatform('zhihu')
    req.zhihu = {
      cookie
    }
  }

  if (accountMap.github) {
    if (accountMap.github.username && accountMap.github.password) {
      req.github = accountMap.github
    }
  }

  if (Object.keys(req).length === 0) {
    return Promise.resolve(false)
  }

  return detectLoginStatus(req)
}<commit_msg>FIX避免调用错误<commit_after>import {encrypt, decrypt} from './aes'
import {SYNC_PLATFORMS} from '../helpers/const'
import {detectLoginStatus} from '../../electron/ipc_render'

const SPLIT_FLAG = '\n'

// 获取帐号配置信息
export function getAccountMap() {
  let accountMap = {}
  SYNC_PLATFORMS.forEach((platform) => {
    let pair = localStorage.getItem(platform) || ''
    pair = pair && decrypt(pair).split(SPLIT_FLAG)
    accountMap[platform] = {
      username: pair && pair[0],
      password: <PASSWORD> && <PASSWORD>[1],
      repo: pair && pair[2]
    }
  })

  return accountMap
}

export function updateAccount(platform, userName, password = '', repo = '') {
  if (!userName) {
    return
  }

  localStorage.setItem(platform, encrypt(`${userName}${SPLIT_FLAG}${password}${SPLIT_FLAG}${repo}`))
}

export function removeAccountByPlatform(platform) {
  localStorage.removeItem(platform)
}

export function getCookiesByPlatform(platform = 'zhihu') {
  if (platform) {
    return localStorage.getItem(`${platform}_cookie`)
  }

  return null
}

export function setCookiesByPlatform(platform, cookie) {
  if (platform && cookie) {
    localStorage.setItem(`${platform}_cookie`, cookie)
  } else {
    localStorage.removeItem(`${platform}_cookie`)
  }
}

export function getLoginDetails(accountMap) {
  let req = {}
  // zhihu只需要cookie即可
  if (accountMap.zhihu) {
    let cookie = getCookiesByPlatform('zhihu')
    req.zhihu = {
      cookie
    }
  }

  if (accountMap.github) {
    req.github = accountMap.github
  }

  if (Object.keys(req).length === 0) {
    return Promise.resolve(false)
  }

  return detectLoginStatus(req)
}
{'fraction_non_alphanumeric': 0.14484007242003621, 'fraction_numerical': 0.0024140012070006035, 'mean_word_length': 3.896602658788774, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2819840', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1119, 'n_words': 205}