Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const [, mimetype, charset, , encoding] = matches;
// all types except for svg need to be base64 encoded
const imageTypeIndex = imageTypes.indexOf(matches[1]);
if (imageTypeIndex > 0 && encoding !== 'base64') {
return;
}
return {
mimetype,
encoding,
charset: charset && charset.split('=')[1],
data: !withData ? null : str.split(',')[1],
isImage: imageTypeIndex >= 0,
extension: mime.getExtension(mimetype),
};
}
if (!matches) return;
const [, mimetype, charset, , encoding] = matches;
// all types except for svg need to be base64 encoded
const imageTypeIndex = imageTypes.indexOf(matches[1]);
if (imageTypeIndex > 0 && encoding !== 'base64') return;
return {
mimetype,
encoding,
charset: charset && charset.split('=')[1],
data: !withData ? null : str.split(',')[1],
isImage: imageTypeIndex >= 0,
extension: mime.getExtension(mimetype),
};
}
// Sticker
ctx.tediCross.file = {
type: "sticker",
id: R.ifElse(
R.propEq("is_animated", true),
R.path(["thumb", "file_id"]),
R.prop("file_id")
)(message.sticker),
name: "sticker.webp"
};
} else if (!R.isNil(message.video)) {
// Video
ctx.tediCross.file = {
type: "video",
id: message.video.file_id,
name: "video" + "." + mime.getExtension(message.video.mime_type),
};
} else if (!R.isNil(message.voice)) {
// Voice
ctx.tediCross.file = {
type: "voice",
id: message.voice.file_id,
name: "voice" + "." + mime.getExtension(message.voice.mime_type),
};
}
next();
}
hook.data[field] = null;
return;
// reject(err);
}
// hook.app.debug(`###got answer for: ${hook.data[field]}`);
try {
const mimeType = res.headers['content-type'];
if (mimeType.indexOf('image') !== 0) {
hook.app.error('its not an image');
loading--;
hook.data[field] = null;
return;
// reject(new Error('its not an image'));
}
const ext = mime.getExtension(mimeType);
imgPath += `.${ext}`;
fs.writeFileSync(imgPath, body, {
encoding: 'binary'
});
loading--;
hook.data[field] = uploadsUrl + imgName + `.${ext}`;
if (imgCount > 0 && loading <= 0) {
hook.app.debug('Download(s) finished', urls);
resolve(hook);
} else if (!imgCount) {
resolve(hook);
extension() {
if (!this.manifestObj) {
return null;
}
return this.manifestObj.extension || mime.getExtension(this.manifestObj.mimeType) || '';
},
showCloseButton() {
extension() {
if (!this.manifestObj) {
return null;
}
return this.manifestObj.extension || mime.getExtension(this.manifestObj.mimeType) || '';
},
type() {
accept.forEach(item => {
exts[mime.getExtension(item)] = true;
});