Metamigo -> Bridge

This commit is contained in:
Darren Clarke 2024-04-21 09:44:30 +02:00
parent 242f3cf6b8
commit a445762a37
145 changed files with 396 additions and 16668 deletions

View file

@ -0,0 +1,84 @@
import { Readable } from "stream";
import ffmpeg from "fluent-ffmpeg";
import * as R from "remeda";
const requiredCodecs = ["mp3", "webm", "wav"];
export interface AudioConvertOpts {
bitrate?: string;
audioCodec?: string;
format?: string;
}
const defaultAudioConvertOpts = {
bitrate: "32k",
audioCodec: "libmp3lame",
format: "mp3",
};
/**
* Converts an audio file to a different format. defaults to converting to mp3 with a 32k bitrate using the libmp3lame codec
*
* @param input the buffer containing the binary data of the input file
* @param opts options to control how the audio file is converted
* @return resolves to a buffer containing the binary data of the converted file
**/
export const convert = (
input: Buffer,
opts?: AudioConvertOpts
): Promise<Buffer> => {
const settings = { ...defaultAudioConvertOpts, ...opts };
return new Promise((resolve, reject) => {
const stream = Readable.from(input);
let out = Buffer.alloc(0);
const cmd = ffmpeg(stream)
.audioCodec(settings.audioCodec)
.audioBitrate(settings.bitrate)
.toFormat(settings.format)
.on("error", (err, stdout, stderr) => {
console.error(err.message);
console.log("FFMPEG OUTPUT");
console.log(stdout);
console.log("FFMPEG ERROR");
console.log(stderr);
reject(err);
})
.on("end", () => {
resolve(out);
});
const outstream = cmd.pipe();
outstream.on("data", (chunk: Buffer) => {
out = Buffer.concat([out, chunk]);
});
});
};
/**
* Check if ffmpeg is installed and usable. Checks for required codecs and a working ffmpeg installation.
*
* @return resolves to true if ffmpeg is installed and usable
* */
export const selfCheck = (): Promise<boolean> => {
return new Promise((resolve) => {
ffmpeg.getAvailableFormats((err, codecs) => {
if (err) {
console.error("FFMPEG error:", err);
resolve(false);
}
const preds = R.map(requiredCodecs, (codec) => (available: any) =>
available[codec] && available[codec].canDemux && available[codec].canMux
);
resolve(R.allPass(codecs, preds));
});
});
};
export const assertFfmpegAvailable = async (): Promise<void> => {
const r = await selfCheck();
if (!r)
throw new Error(
`ffmpeg is not installed, could not be located, or does not support the required codecs: ${requiredCodecs}`
);
};

View file

@ -0,0 +1,69 @@
export const tagMap = {
AccountImpersonation: [
{ field: "incidentType tag", value: "account-impersonation" },
],
AppleID: [{ field: "incidentType tag", value: "malfunction-failure" }],
Blocked: [{ field: "incidentType tag", value: "account-deactivation" }],
CyberBullying: [{ field: "incidentType tag", value: "cyber-bullying" }],
DeviceSuspiciousBehavior: [
{ field: "incidentType tag", value: "compromise-device" },
],
Doxxing: [{ field: "incidentType tag", value: "doxxing" }],
DSTips: [{ field: "incidentType tag", value: "informational" }],
HackedLaptop: [
{ field: "incidentType tag", value: "compromised-device" },
{ field: "device tag", value: "laptop" },
],
"Hacked/StolenAccount": [
{ field: "incidentType tag", value: "compromised-account" },
],
HateSpeech: [{ field: "incidentType tag", value: "hate-speech" }],
InfectedPhone: [
{ field: "incidentType tag", value: "malware" },
{ field: "device tag", value: "smartphone" },
],
Kidnapping: [{ field: "incidentType tag", value: "kidnapping" }],
LaptopGiveaway: [{ field: "incidentType tag", value: "other" }],
ForensicAnalysis: [{ field: "incidentType tag", value: "malware" }],
ISF: [{ field: "incidentType tag", value: "other" }],
NumberBanned: [
{ field: "incidentType tag", value: "disruption" },
{ field: "device tag", value: "smartphone" },
],
OnlineHarassment: [{ field: "incidentType tag", value: "online-harassment" }],
PhoneHarassment: [{ field: "incidentType tag", value: "phone-harassment" }],
PoliticalAds: [{ field: "incidentType tag", value: "spam" }],
SeizedPhone: [
{ field: "incidentType tag", value: "confiscation" },
{ field: "device tag", value: "smartphone" },
],
SexED: [{ field: "incidentType tag", value: "informational" }],
Sextortion: [{ field: "incidentType tag", value: "sextortion" }],
Spam: [{ field: "incidentType tag", value: "spam" }],
SuspendedAccount: [
{ field: "incidentType tag", value: "account-suspension" },
],
SuspendedActivities: [
{ field: "incidentType tag", value: "content-moderation" },
],
SuspendedGroup: [{ field: "incidentType tag", value: "account-suspension" }],
SuspendedPage: [{ field: "incidentType tag", value: "account-suspension" }],
"Stolen/LostPhone": [
{ field: "incidentType tag", value: "loss" },
{ field: "device tag", value: "smartphone" },
],
Facebook: [{ field: "platform tag", value: "facebook" }],
Google: [{ field: "platform tag", value: "google" }],
Instagram: [{ field: "platform tag", value: "instagram" }],
SMS: [{ field: "service tag", value: "sms" }],
Twitter: [{ field: "platform tag", value: "twitter" }],
Website: [{ field: "service tag", value: "website" }],
WhatsApp: [{ field: "platform tag", value: "whatsapp" }],
YouTube: [{ field: "platform tag", value: "youtube" }],
Linkedin: [{ field: "platform tag", value: "linkedin" }],
PoliticalActivist: [{ field: "targetedGroup tag", value: "policy-politics" }],
ElectoralCandidate: [
{ field: "targetedGroup tag", value: "policy-politics" },
],
PhishingLink: [{ field: "incidentType tag", value: "phishing" }],
};