webamp/packages/skin-database/tasks/screenshotSkin.ts
Jordan Eldredge 1da77a640a
Consolidate ESLint configs into root (#1324)
Move general-purpose lint rules from packages/webamp/.eslintrc to the root
.eslintrc so they apply to all packages consistently. This includes:

- Core JavaScript best practices (no-var, prefer-const, eqeqeq, etc.)
- TypeScript-specific rules (@typescript-eslint/no-unused-vars with patterns)
- Prettier integration

Package-specific configs now only contain rules unique to their needs:
- webamp: React, import, and react-hooks plugin rules
- skin-database: Extends @typescript-eslint/recommended, disables rules that
  conflict with existing code style
- webamp-modern: Unchanged (has root: true for isolation)

Also fixes lint errors in skin-database:
- Consolidate duplicate imports in App.js and Feedback.js
- Add radix parameter to parseInt
- Prefix unused function parameters with underscore
- Convert var to let/const
- Fix type import for Shooter
2025-11-27 21:32:10 -08:00

49 lines
1.5 KiB
TypeScript

// eslint-disable-next-line
import temp from "temp";
import fs from "fs";
import md5Buffer from "md5";
import * as S3 from "../s3";
import * as Skins from "../data/skins";
import * as CloudFlare from "../CloudFlare";
import SkinModel from "../data/SkinModel";
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-require-imports
const Shooter = require("../shooter");
export async function screenshot(skin: SkinModel, shooter: typeof Shooter) {
let buffer: Buffer;
try {
buffer = await skin.getBuffer();
} catch {
await Skins.recordScreenshotUpdate(
skin.getMd5(),
`Failed to get skin buffer.`
);
throw new Error("Failed to get skin buffer");
}
const actualMd5 = md5Buffer(buffer);
if (skin.getMd5() !== actualMd5) {
throw new Error("Downloaded skin had a different md5.");
}
const tempFile = temp.path({ suffix: ".wsz" });
const tempScreenshotPath = temp.path({ suffix: ".png" });
fs.writeFileSync(tempFile, new Uint8Array(buffer));
const success = await shooter.takeScreenshot(tempFile, tempScreenshotPath, {
minify: true,
md5: skin.getMd5(),
});
if (!success) {
fs.unlinkSync(tempFile);
fs.unlinkSync(tempScreenshotPath);
temp.cleanupSync();
throw new Error("Screenshot failed.");
}
await S3.putScreenshot(skin.getMd5(), fs.readFileSync(tempScreenshotPath));
await CloudFlare.purgeFiles([Skins.getScreenshotUrl(actualMd5)]);
fs.unlinkSync(tempFile);
fs.unlinkSync(tempScreenshotPath);
}