(media, metadata)
| 125 | } |
| 126 | |
| 127 | async function writeExif (media, metadata) { |
| 128 | let wMedia = /webp/.test(media.mimetype) ? media.data : /image/.test(media.mimetype) ? await imageToWebp(media.data) : /video/.test(media.mimetype) ? await videoToWebp(media.data) : "" |
| 129 | const tmpFileIn = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`) |
| 130 | const tmpFileOut = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`) |
| 131 | fs.writeFileSync(tmpFileIn, wMedia) |
| 132 | |
| 133 | if (metadata.packname || metadata.author) { |
| 134 | const img = new webp.Image() |
| 135 | const json = { "sticker-pack-id": `https://github.com/mruniquehacker/Knightbot`, "sticker-pack-name": metadata.packname, "sticker-pack-publisher": metadata.author, "emojis": metadata.categories ? metadata.categories : [""] } |
| 136 | const exifAttr = Buffer.from([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00]) |
| 137 | const jsonBuff = Buffer.from(JSON.stringify(json), "utf-8") |
| 138 | const exif = Buffer.concat([exifAttr, jsonBuff]) |
| 139 | exif.writeUIntLE(jsonBuff.length, 14, 4) |
| 140 | await img.load(tmpFileIn) |
| 141 | fs.unlinkSync(tmpFileIn) |
| 142 | img.exif = exif |
| 143 | await img.save(tmpFileOut) |
| 144 | return tmpFileOut |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | module.exports = { imageToWebp, videoToWebp, writeExifImg, writeExifVid, writeExif } |
nothing calls this directly
no test coverage detected