utils.js 1.5 KB

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