mirror of
https://github.com/PretendoNetwork/miiverse-api.git
synced 2026-04-26 00:27:20 -05:00
Fixed paintings from the 3DS not being parsed correctly
This commit is contained in:
parent
2d450403e8
commit
5bfdcaae16
15
package-lock.json
generated
15
package-lock.json
generated
|
|
@ -10,7 +10,9 @@
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pretendonetwork/grpc": "^1.0.3",
|
"@pretendonetwork/grpc": "^1.0.3",
|
||||||
|
"@types/bmp-js": "^0.1.2",
|
||||||
"aws-sdk": "^2.1204.0",
|
"aws-sdk": "^2.1204.0",
|
||||||
|
"bmp-js": "^0.1.0",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"crc": "^4.3.2",
|
"crc": "^4.3.2",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
|
|
@ -1562,6 +1564,14 @@
|
||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/bmp-js": {
|
||||||
|
"version": "0.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/bmp-js/-/bmp-js-0.1.2.tgz",
|
||||||
|
"integrity": "sha512-BF6u+M+KySDBKfr1DQOT3+z42n4/tq62uf9ong4i2SLLpa7mJqPwEmKbNgMzlVliT/jtE6elxyD/0X1mja8jLg==",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/body-parser": {
|
"node_modules/@types/body-parser": {
|
||||||
"version": "1.19.2",
|
"version": "1.19.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
|
||||||
|
|
@ -2300,6 +2310,11 @@
|
||||||
"integrity": "sha512-UfFSr22dmHPQqPP9XWHRhq+gWnHCYguQGkXQlbyPtW5qTnhFWA8/iXg765tH0cAjy7l/zPJ1aBTO0g5XgA7kvQ==",
|
"integrity": "sha512-UfFSr22dmHPQqPP9XWHRhq+gWnHCYguQGkXQlbyPtW5qTnhFWA8/iXg765tH0cAjy7l/zPJ1aBTO0g5XgA7kvQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/bmp-js": {
|
||||||
|
"version": "0.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/bmp-js/-/bmp-js-0.1.0.tgz",
|
||||||
|
"integrity": "sha512-vHdS19CnY3hwiNdkaqk93DvjVLfbEcI8mys4UjuWrlX1haDmroo8o4xCzh4wD6DGV6HxRCyauwhHRqMTfERtjw=="
|
||||||
|
},
|
||||||
"node_modules/body-parser": {
|
"node_modules/body-parser": {
|
||||||
"version": "1.20.1",
|
"version": "1.20.1",
|
||||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,9 @@
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pretendonetwork/grpc": "^1.0.3",
|
"@pretendonetwork/grpc": "^1.0.3",
|
||||||
|
"@types/bmp-js": "^0.1.2",
|
||||||
"aws-sdk": "^2.1204.0",
|
"aws-sdk": "^2.1204.0",
|
||||||
|
"bmp-js": "^0.1.0",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"crc": "^4.3.2",
|
"crc": "^4.3.2",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
|
|
|
||||||
32
src/util.ts
32
src/util.ts
|
|
@ -1,6 +1,7 @@
|
||||||
import crypto from 'node:crypto';
|
import crypto from 'node:crypto';
|
||||||
import { IncomingHttpHeaders } from 'node:http';
|
import { IncomingHttpHeaders } from 'node:http';
|
||||||
import TGA from 'tga';
|
import TGA from 'tga';
|
||||||
|
import BMP from 'bmp-js';
|
||||||
import pako from 'pako';
|
import pako from 'pako';
|
||||||
import { PNG } from 'pngjs';
|
import { PNG } from 'pngjs';
|
||||||
import aws from 'aws-sdk';
|
import aws from 'aws-sdk';
|
||||||
|
|
@ -104,15 +105,32 @@ export function processPainting(painting: string): Buffer | null {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tga = new TGA(Buffer.from(output));
|
// 3DS is a BMP, Wii U is a TGA. God isn't real so we need to edit the
|
||||||
const png = new PNG({
|
// alpha layer of the BMP to covert it to a PNG for the web app
|
||||||
width: tga.width,
|
if (output[0] === 66) {
|
||||||
height: tga.height
|
const bitmap = BMP.decode(Buffer.from(output));
|
||||||
});
|
const png = new PNG({
|
||||||
|
width: bitmap.width,
|
||||||
|
height: bitmap.height
|
||||||
|
});
|
||||||
|
|
||||||
png.data = Buffer.from(tga.pixels);
|
const bpmBuffer = bitmap.getData();
|
||||||
|
bpmBuffer.swap32();
|
||||||
|
png.data = bpmBuffer;
|
||||||
|
for (let i = 3; i < bpmBuffer.length; i += 4) {
|
||||||
|
bpmBuffer[i] = 255;
|
||||||
|
}
|
||||||
|
return PNG.sync.write(png);
|
||||||
|
} else {
|
||||||
|
const tga = new TGA(Buffer.from(output));
|
||||||
|
const png = new PNG({
|
||||||
|
width: tga.width,
|
||||||
|
height: tga.height
|
||||||
|
});
|
||||||
|
|
||||||
return PNG.sync.write(png);
|
png.data = Buffer.from(tga.pixels);
|
||||||
|
return PNG.sync.write(png);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uploadCDNAsset(bucket: string, key: string, data: Buffer, acl: string): Promise<void> {
|
export async function uploadCDNAsset(bucket: string, key: string, data: Buffer, acl: string): Promise<void> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user