Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getReplaysByMd5(MD5).then(replaysMD5 => {
if (replaysMD5.length > 0) {
resolve({
error: 'Duplicate',
replayInfo: replaysMD5,
file: filename,
});
} else {
// find LevelIndex
const replayCRC = readChunk.sync(
`.${config.publicFolder}/temp/${uuid}-${filename}`,
16,
4,
);
let replayLevel = readChunk.sync(
`.${config.publicFolder}/temp/${uuid}-${filename}`,
20,
12,
);
replayLevel = replayLevel.toString('utf-8').split('.')[0];
getLevelsFromName(replayLevel).then(levels => {
let LevelIndex = 0;
levels.forEach(level => {
if (level.LevelData && replayCRC) {
if (
level.LevelData.toString('hex').substring(14, 22) ===
replayCRC.toString('hex')
) {
LevelIndex = level.LevelIndex;
}
}
function validateImage(path, config) {
if (fs.existsSync(path) === false) {
validationError(`Image \"${path}\"' was not found at ${path}.`);
} else {
// Read first 12 bytes (enough for '%PNG', etc)
const buffer = readChunk.sync(path, 0, 12);
const type = imageType(buffer).mime;
if (type !== config.type) {
validationError(`Incorrect format of image (${type} != ${config.type})`);
}
let dimensions = sizeOf(path);
for (const sizeIndex in config.sizes) {
const size = config.sizes[sizeIndex];
if (dimensions.width === size.width && dimensions.height === size.height) {
return;
}
}
// Build our error message
function generateThumbnail (orig, thumb, w, callback) {
log('Generate Thumbnail', orig)
const buffer = readChunk.sync(orig, 0, 262)
const extInfo = fileType(buffer)
const ext = extInfo ? extInfo.ext : null
if (!ext) {
return callback(new Error('Unknown file type'), null)
}
if (ext === 'gif') {
execFile(gifsicle, ['--resize', `${w / 2}x_`, orig, '-o', thumb], (err) => {
callback(err, thumb)
})
} else { // jpeg, png
jimp.read(orig)
.then((img) => {
log('jimp resize', w, thumb)
img.resize(w, jimp.AUTO).getBuffer(jimp.MIME_JPEG, (err, buf) => {
log('jimp resize done', err)
fs.writeFileSync(thumb, buf)
.map(file => {
var buffer = readChunk.sync(file, 0, 4);
t.true(isBpg(buffer));
}).then(() => t.end());
});
help();
return;
}
if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) {
console.log(pkg.version);
return;
}
if (process.stdin.isTTY) {
if (!input) {
help();
return;
}
init(readChunk.sync(input, 0, 12));
} else {
process.stdin.once('data', function (data) {
init(data);
});
}
async _fileInfo(file) {
const bufferExt = readChunk.sync(file.path, 0, fileType.minimumBytes);
let fileExt = fileType(bufferExt);
if (fileExt) {
fileExt = fileExt.ext;
}
else {
const ext = path.extname(file.name).split('.');
fileExt = ext[ext.length - 1];
}
const checksum = await this._checkSum(file.path);
const fileSize = fse.statSync(file.path).size;
return { fileExt, checksum, fileSize };
}
function isBinaryPlist (filename) {
return readChunk.sync(filename, 0, 6).toString() === 'bplist';
}
.then(({ files }) => {
if (!('image' in files)) {
result.msg = '参数错误';
return;
}
const imageFile = files.image[0];
const buffer = readChunk.sync(imageFile.path, 0, 262);
const resultType = fileType(buffer);
if (!resultType || !['image/jpeg', 'image/png'].includes(resultType.mime)) {
result.msg = '仅jpg/png格式';
return;
}
const srcpath = imageFile.path
const imgKey = `${Date.now()}-${shortid.generate()}.${resultType.ext}`
const params = {
Bucket: config.cosFileBucket,
Region: config.cosRegion,
Key: imgKey,
Body: srcpath,
ContentLength: imageFile.size
}
function checkMimeType(path) {
let supportedMimTypes = config.get("mime_types");
let buffer = readChunk.sync(path, 0, 4100);
let type = fileType(buffer);
if (!supportedMimTypes.includes(type.mime)) {
throw boom.badRequest(
`Uploaded image has unsupported mime type "${type.mime}". Supported mime types are "${supportedMimTypes.join('","')}".`
);
}
return;
}
validateImage(path) {
let buffer = readChunk.sync(path, 0, 12);
let type = imageType(buffer);
return new Promise((resolve, reject) => {
if (this.validExtensions.indexOf(type.ext) === -1) {
return reject(new Error(this.errors.url_image_invalid));
}
resolve(type.ext);
});
}