Merge branch 'develop'
This commit is contained in:
commit
e8a13c498a
@ -57,12 +57,19 @@ async function withTaskRecord<T>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function urlToBase64(url: string): Promise<string> {
|
async function urlToBase64(url: string, retries = 3, delay = 1000): Promise<string> {
|
||||||
|
for (let attempt = 1; attempt <= retries; attempt++) {
|
||||||
|
try {
|
||||||
const res = await axios.get(url, { responseType: "arraybuffer" });
|
const res = await axios.get(url, { responseType: "arraybuffer" });
|
||||||
const base64 = Buffer.from(res.data).toString("base64");
|
const base64 = Buffer.from(res.data).toString("base64");
|
||||||
return `${base64}`;
|
return `${base64}`;
|
||||||
|
} catch (e) {
|
||||||
|
if (attempt === retries) throw e;
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delay * attempt));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("urlToBase64 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
class AiText {
|
class AiText {
|
||||||
private AiType: AiType | `${string}:${string}`;
|
private AiType: AiType | `${string}:${string}`;
|
||||||
constructor(AiType: AiType | `${string}:${string}`) {
|
constructor(AiType: AiType | `${string}:${string}`) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user