utils.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // document.cookie
  2. function cookieToJSON (cookieString) {
  3. // 分割多个cookie
  4. const cookies = cookieString.split(';')
  5. const cookieArray = []
  6. cookies.forEach(cookie => {
  7. // 处理每个cookie
  8. const parts = cookie.trim().split('=')
  9. if (parts.length >= 2) {
  10. const name = parts[0].trim()
  11. // 使用parts.slice(1).join('=')来处理value中可能包含=的情况
  12. const value = parts.slice(1).join('=').trim()
  13. // 创建cookie对象
  14. const cookieObj = {
  15. name: name,
  16. value: value,
  17. domain: 'bitget.com',
  18. path: '/',
  19. expires: Math.floor(Date.now() / 1000) + 86400, // 默认24小时后过期
  20. size: (name + value).length,
  21. httpOnly: name.toLowerCase().includes('token') || name.toLowerCase().includes('bmsc'),
  22. secure: name.toLowerCase().includes('token') || name.toLowerCase().includes('bmsc'),
  23. session: false,
  24. sameSite: 'Lax',
  25. priority: 'Medium',
  26. sameParty: false,
  27. sourceScheme: 'Secure',
  28. sourcePort: 443,
  29. partitionKey: '',
  30. partitionKeyOpaque: false,
  31. }
  32. cookieArray.push(cookieObj)
  33. }
  34. })
  35. return cookieArray
  36. }
  37. module.exports = {
  38. cookieToJSON,
  39. }