Advertisement
lignite0

SP24 - image object name.js

Jul 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const base = require('base-x');
  2.  
  3. const baser62 = base("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  4.  
  5. const min = 0x000000;
  6. const max = 0xffffff;
  7.  
  8. function getRandomInt() {
  9.     return Math.floor(Math.random() * (max - min)) + min;
  10. }
  11.  
  12. class BufferOffset {
  13.     constructor(buffer) {
  14.         this.buffer = buffer;
  15.         this.offset = 0;
  16.     }
  17.  
  18.     write(length, data) {
  19.         this.buffer.writeUIntBE(data, this.offset, length);
  20.         this.offset += length;
  21.     }
  22. }
  23.  
  24. const buffer = Buffer.alloc(43);
  25. const b = new BufferOffset(buffer);
  26.  
  27. // b.write(4, getRandomInt()); // Random
  28. // b.write(4, Date.now() / 1000); // Creation timestamp
  29. // b.write(1, 0x55); // Object type
  30. // b.write(1, 0x44); // Object localization
  31. // b.write(3, 0x333333); // Application Id
  32. // b.write(2, 0x1111); // Image width
  33. // b.write(2, 0x2222); // Image height
  34. // b.write(2, 0x6666); // Provider Id
  35. // b.write(4, 0x77777777); // Product creation timestamp
  36. // b.write(5, 0x8888888888); // Product random
  37. // b.write(3, 0x999999); // Product counter
  38. // b.write(4, getRandomInt()); // Original image random
  39. // b.write(4, Date.now() / 1000); // original image timestamp
  40. // b.write(2, 0x2222); // Original image width
  41. // b.write(2, 0x6666); // Original image height
  42.  
  43. b.write(4, getRandomInt()); // Random
  44. b.write(4, Date.now() / 1000); // Creation timestamp
  45. b.write(1, 0x55); // Object type
  46. b.write(1, 0x44); // Object localization
  47. b.write(3, 0x333333); // Application Id
  48. b.write(2, 0x1111); // Image width
  49. b.write(2, 0x2222); // Image height
  50. b.write(2, 0x6666); // Provider Id
  51. b.write(4, 0x77777777); // Product creation timestamp
  52. b.write(5, 0x8888888888); // Product random
  53. b.write(3, 0x999999); // Product counter
  54. b.write(4, getRandomInt()); // Original image random
  55. b.write(4, Date.now() / 1000); // original image timestamp
  56. b.write(2, 0x2222); // Original image width
  57. b.write(2, 0x6666); // Original image height
  58.  
  59. console.log(b.offset);
  60. console.log(buffer);
  61. const result = baser62.encode(buffer)
  62. console.log(result.length);
  63. console.log(result);
  64.  
  65. // 4; Random number
  66. // 6; Millisecond timestamp
  67. // 2; Object type
  68. // 2; Object localization
  69. // 3; Application Id
  70. // 2; Image width
  71. // 2; Image height
  72.  
  73. // 4; Random number
  74. // 6; Millisecond timestamp
  75. // 2; Object type
  76. // 2; Object localization
  77. // 3; Application Id
  78. // 2; Image width
  79. // 2; Image height
  80. // 2; Provider Id
  81. // 4; Product creation timestamp
  82. // 5; Product random
  83. // 3; Product couter
  84.  
  85. // 4; Random number
  86. // 6; Millisecond timestamp
  87. // 2; Object type
  88. // 2; Object localization
  89. // 3; Application Id
  90. // 2; Image width
  91. // 2; Image height
  92. // 2; Provider Id
  93. // 4; Product creation timestamp
  94. // 5; Product random
  95. // 3; Product couter
  96. // 4; Random number
  97. // 6; Millisecond timestamp
  98. // 2; Original Image width
  99. // 2; Original Image height
  100.  
  101.  
  102.  
  103.  
  104. // 0x00 = null
  105. // 0x10 = null
  106. // 0x01 = static images created by developers
  107. // 0x11 = static images thumbs created by developers
  108. // 0x02 = static images created by client
  109. // 0x12 = static images thumbs by client
  110. // 0x03 = example products images
  111. // 0x13 = example products thumbs
  112. // 0x04 = products images
  113. // 0x14 = products thumbs
  114. // 0x15 = integrations images
  115. // 0x15 = integrations thumbs
  116. // 0x16 = integrations images
  117. // 0x16 = integrations thumbs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement