Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const base = require('base-x');
- const baser62 = base("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
- const min = 0x00000000;
- const max = 0xffffffff;
- function getRandomInt() {
- return Math.floor(Math.random() * (max - min)) + min;
- }
- class BufferOffset {
- constructor() {
- this.size = 0;
- this.data = [];
- }
- write(length, data) {
- this.data.push({length, data});
- this.size += length;
- }
- make() {
- let offset = 0;
- const buffer = Buffer.allocUnsafe(this.size);
- for (let {data, length} of this.data) {
- buffer.writeUIntBE(data, offset, length);
- offset += length;
- }
- return buffer;
- }
- }
- // b.write(4, getRandomInt()); // Random
- // b.write(4, Date.now() / 1000); // Creation timestamp
- // b.write(1, 0x55); // Object type
- // b.write(1, 0x44); // Object localization
- // b.write(3, 0x333333); // Application Id
- // b.write(2, 0x1111); // Image width
- // b.write(2, 0x2222); // Image height
- // b.write(2, 0x6666); // Provider Id
- // b.write(4, 0x77777777); // Product creation timestamp
- // b.write(5, 0x8888888888); // Product random
- // b.write(3, 0x999999); // Product counter
- // b.write(4, getRandomInt()); // Original image random
- // b.write(4, Date.now() / 1000); // original image timestamp
- // b.write(2, 0x2222); // Original image width
- // b.write(2, 0x6666); // Original image height
- // b.write(1, 0x11); // Object type
- // b.write(1, 0x22); // Object localization
- //
- // b.write(4, Date.now() / 1000); // Creation timestamp
- // b.write(4, getRandomInt()); // Random
- // b.write(4, getRandomInt()); // Couter
- //
- // b.write(2, 0x2222); // Original image width
- // b.write(2, 0x6666); // Original image height
- //
- // b.write(1, 0x11); // Object type
- // b.write(1, 0x22); // Object localization
- //
- // b.write(4, Date.now() / 1000); // Creation timestamp
- // b.write(4, getRandomInt()); // Random
- // b.write(4, getRandomInt()); // Couter
- //
- // b.write(3, 0x333333); // Application Id
- // b.write(2, 0x4444); // Provider Id
- // b.write(2, 0x5555); // Image width
- // b.write(2, 0x6666); // Image height
- //
- // b.write(4, 0x77777777); // Product creation timestamp
- // b.write(4, 0x88888888); // Product random
- // b.write(4, 0x99999999); // Product counter
- // const b = new BufferOffset();
- // b.write(2, 0x1111); // Object type
- // b.write(2, 0x2222); // Object localization
- // b.write(2, 0x4444); // Wholesaler Id
- // b.write(2, 0x5555); // Image width
- // b.write(2, 0x6666); // Image height
- // b.write(4, 0x21232f29); // Image checksum
- // b.write(4, 0x7a57a5a7); // Image checksum
- // b.write(4, 0x43894a0e); // Image checksum
- // b.write(4, 0x4a801fc3); // Image checksum
- // const buffer = b.make();
- const b = new BufferOffset();
- b.write(1, 0x11); // Object type
- // b.write(2, 0x5555); // Thumb image width
- // b.write(2, 0x6666); // Thumb image height
- b.write(2, 0x2222); // Object localization
- b.write(2, 0x4444); // Wholesaler Id
- b.write(2, 0x5555); // Image width
- b.write(2, 0x6666); // Image height
- b.write(4, 0x21232f29); // Image checksum
- b.write(4, 0x7a57a5a7); // Image checksum
- b.write(4, 0x43894a0e); // Image checksum
- b.write(4, 0x4a801fc3); // Image checksum
- b.write(1, 0x11); // File extension
- const buffer = b.make();
- // 21232f29 7a57a5a7 43894a0e 4a801fc3
- // d033e22ae348aeb5660fc2140aec35850c4da997
- console.log(b.size);
- console.log(buffer);
- const result = baser62.encode(buffer);
- console.log(result.length);
- console.log(result);
- const wholesale_yns_products = {
- images: [
- {
- _id: "4a801fc343894a0e7a57a5a7",
- }
- ]
- };
- const app_products = {
- images: [
- {
- _id: "4a801fc343894a0e7a57a5a7",
- }
- ]
- };
- const app_images = {
- _id: "4a801fc343894a0e7a57a5a7",
- kind: "storage",
- primary: {
- bucket: "bsB2dbx82Ao8e128eKcSF6CPPitiPXZF",
- },
- thumbs: [
- {
- bucket: "eM5mjMfPXL8nJFkgNgdVj7uaijFrL8YcxQKHVeZt",
- },
- {
- bucket: "eM5mjMfPXL8nJFkgNgdVj7uaijFrL8YcxQKHVeZt",
- },
- ],
- source: {
- id: 101,
- kind: "wholesaler",
- url: "https://yns.pl/id.jpg"
- },
- };
- const deserialized = {
- type: 0x00,
- kind: "wholesaler-product-image",
- storage: {
- localization: "waw1",
- auth: "d40b57d4f91d4d1fb3722913c1d03c9b"
- },
- source: {
- id: 101,
- type: "wholesaler",
- },
- url: "https://storage.waw1.cloud.ovh.net/v1//ws0064/wpi/eM5mjMfPXL8nJFkgNgdVj7uaijFrL8YcxQKHVeZt.png",
- bucket: "eM5mjMfPXL8nJFkgNgdVj7uaijFrL8YcxQKHVeZt",
- width: 1600,
- height: 1200,
- checksum: "21232f297a57a5a743894a0e4a801fc3"
- };
- const deserialized_thumb = {
- type: 0x00,
- kind: "wholesaler-product-image-thumb",
- storage: {
- localization: "waw1",
- auth: "d40b57d4f91d4d1fb3722913c1d03c9b"
- },
- source: {
- id: 101,
- type: "wholesaler",
- },
- url: "https://storage.waw1.cloud.ovh.net/v1//ws0064/wpi/eM5mjMfPXL8nJFkgNgdVj7uaijFrL8YcxQKHVeZt.png",
- bucket: "eM5mjMfPXL8nJFkgNgdVj7uaijFrL8YcxQKHVeZt",
- width: 1600,
- height: 1200,
- checksum: "21232f297a57a5a743894a0e4a801fc3"
- };
- // 0x00 = null
- // 0x10 = null
- // 0x01 = static images created by developers
- // 0x11 = static images thumbs created by developers
- // 0x02 = static images created by client
- // 0x12 = static images thumbs by client
- // 0x03 = example products images
- // 0x13 = example products thumbs
- // 0x04 = products images
- // 0x14 = products thumbs
- // 0x15 = integrations images
- // 0x15 = integrations thumbs
- // 0x16 = integrations images
- // 0x16 = integrations thumbs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement