Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onMessage(chat) {
if (this.awaiting.dec(chat.fingerprint)) {
// This is a message we proxied, drop it!
return
} else {
// This is a message we didn't send, do the final necessary conversions and send it on!
const converted = {
fingerprint: chat.fingerprint,
message: chat.message,
media: {},
created: chat.created,
key: chat.key,
}
// decode the webm
const decoded = uriToBuffer(chat.media)
this.lastMessageTime = converted.created
frameConverter(decoded, this.ffmpegRunner, (err, filmstrip) => {
if (err) {
console.error('Error converting meatspace chat to filmstrip: ' + err)
return
}
converted.media['image/jpeg'] = filmstrip
this.emit('chat', converted)
})
}
}
}
function requestSourceMap(
sourceMapUrl: string,
options: request.CoreOptions,
callback: (error: any, response: Partial, body: any) => void
) {
if (sourceMapUrl.startsWith('data:')) {
const body = dataUriToBuffer(sourceMapUrl);
// mock response object; pretend we made a http request
callback(
null,
{
statusCode: 200
},
body.toString()
);
} else {
request(sourceMapUrl, options, callback as request.RequestCallback);
}
}
export async function getUri(uri: string): Promise {
if (uri.startsWith('data:')) {
return dataUriToBuffer(uri).toString();
}
if (uri.startsWith('file:')) {
return await fs.readFile(fileUriToPath(uri), 'utf8');
}
if (!uri.startsWith('http:') && !uri.startsWith('https:')) {
throw new Error(`Fetching ${uri} not supported`);
}
return await new Promise((resolve, reject) => {
const parsedUrl = url.parse(uri);
const get = (parsedUrl.protocol === 'https:') ? https.get : http.get;
const options = Object.assign({ rejectUnauthorized: false }, parsedUrl) as https.RequestOptions;
get(options, response => {
return new Promise(res => {
return new Jimp(dataUriToBuffer(dataUri), (err, img) => {
if (err) {
throw err;
}
res(img);
});
});
}