File size: 4,589 Bytes
c09f67c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | import fs from "node:fs";
import path from "node:path";
import { getLogoURL } from "@/utils/logo";
const PRIORITY_INSTITUTIONS = [
// US
"chase", // Chase
"wells_fargo", // Wells Fargo
"bank_of_america", // Bank Of America
"pnc", // PNC
"credit_one", // CreditOne
"capital_one", // CapitalOne
"us_bank", // US Bank
"usaa", // USAA
"mercury", // Mercury
"citibank", // Citibank
"silicon_valley_bank", // Silicon Valley Bank
"first_republic", // First Republic
"brex", // Brex
"amex", // American Express
"ins_133680", // Angel List
"morgan_stanley", // Morgan Stanley
"truist", // Truist
"td_bank", // TD Bank
"ins_29", // KeyBank
"ins_19", // Regions Bank
"fifth_third", // Fifth Third Bank
"ins_111098", // Citizens Bank
"ins_100103", // Comerica Bank
"ins_21", // Huntington Bank
];
export function getPopularity(id: string) {
if (PRIORITY_INSTITUTIONS.includes(id)) {
return 100 - PRIORITY_INSTITUTIONS.indexOf(id);
}
return 0;
}
export function matchLogoURL(id: string) {
switch (id) {
case "ins_56":
return getLogoURL("chase");
case "ins_127991":
return getLogoURL("wells_fargo");
case "ins_116236":
return getLogoURL("ins_116236");
case "ins_133019":
return getLogoURL("wise");
case "ins_126265":
case "ins_126523":
case "ins_115575":
case "ins_117163":
return getLogoURL("vancity");
case "ins_133354":
return getLogoURL("ins_133354");
case "ins_118853":
return getLogoURL("walmart");
case "ins_126283":
return getLogoURL("rocky");
case "ins_115771":
return getLogoURL("revelstoke");
case "ins_133347":
return getLogoURL("ins_133347");
case "ins_117642":
return getLogoURL("ins_117642");
case "ins_116219":
return getLogoURL("ins_116219");
case "ins_119478":
return getLogoURL("ins_119478");
case "ins_117634":
return getLogoURL("ins_117634");
case "ins_117635":
return getLogoURL("ins_117635");
case "ins_117600":
return getLogoURL("ins_117600");
case "ins_118849":
case "ins_129638":
return getLogoURL("ins_118849");
case "ins_116229":
return getLogoURL("ins_116229");
case "ins_117643":
return getLogoURL("ins_117643");
case "ins_118897":
return getLogoURL("ins_118897");
case "ins_119483":
return getLogoURL("ins_119483");
case "ins_119481":
return getLogoURL("ins_119481");
case "ins_117542":
return getLogoURL("ins_117542");
case "ins_116216":
return getLogoURL("ins_116216");
case "ins_118903":
return getLogoURL("ins_118903");
default:
return null;
}
}
export function saveImageFromString(base64String: string, filePath: string) {
const buffer = Buffer.from(base64String, "base64");
try {
fs.writeFileSync(filePath, buffer);
console.log(`Image saved successfully to ${filePath}`);
} catch (err) {
console.error(`Error saving image: ${err}`);
}
}
export async function saveImageFromURL(
url: string,
fileName: string,
): Promise<void> {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to fetch image: ${response.statusText}`);
}
const buffer = await response.arrayBuffer();
const fullPath = path.resolve(path.join("tasks", "logos", fileName));
// @ts-expect-error
fs.writeFile(fullPath, buffer, (err) => {
if (err) {
throw new Error(`Failed to save image: ${err.message}`);
}
console.log(`Image saved to ${fullPath}`);
});
} catch (error) {
console.error(`Error: ${error}`);
}
}
export function saveFile(filePath: string, content: string) {
try {
fs.writeFileSync(filePath, content);
console.log(`File saved successfully to ${filePath}`);
} catch (err) {
console.error(`Error saving file: ${err}`);
}
}
const TELLER_ENDPOINT = "https://api.teller.io/institutions";
type TellerResponse = {
id: string;
name: string;
capabilities: string[];
};
export async function getTellerData() {
const response = await fetch(TELLER_ENDPOINT);
const data = (await response.json()) as TellerResponse[];
return data;
}
export async function batchPromises<T>(promises: Promise<T>[]): Promise<T[]> {
const batchSize = 10;
const results: T[] = [];
for (let i = 0; i < promises.length; i += batchSize) {
const batch = promises.slice(i, i + batchSize);
const batchResults = await Promise.all(batch);
results.push(...batchResults);
}
return results;
}
|