if image cannot be downloaded, fall back to oringinal url

This commit is contained in:
2025-04-16 08:44:18 -06:00
parent 0bd55d3f67
commit a9bc8ef390
6 changed files with 17 additions and 12 deletions

View File

@@ -39,7 +39,7 @@ export async function paginatedRequest<T extends any[]>(request: {
var requestCount = 1;
const url = new URL(request.url);
url.searchParams.set("per_page", "100");
const { data: firstData, headers: firstHeaders } = await axiosClient.get<T>(
url.toString()
);
@@ -64,5 +64,3 @@ export async function paginatedRequest<T extends any[]>(request: {
return returnData as T;
}

View File

@@ -7,7 +7,7 @@ import FormData from "form-data";
export const downloadUrlToTempDirectory = async (
sourceUrl: string
): Promise<string> => {
): Promise<{fileName: string, success: boolean}> => {
try {
const fileName =
path.basename(new URL(sourceUrl).pathname) || `tempfile-${Date.now()}`;
@@ -16,10 +16,10 @@ export const downloadUrlToTempDirectory = async (
responseType: "arraybuffer",
});
await fs.writeFile(tempFilePath, response.data);
return tempFilePath;
return {fileName: tempFilePath, success: true};
} catch (error) {
console.error("Error downloading or saving the file:", error);
throw error;
console.log("Error downloading or saving the file:", sourceUrl, error);
return {fileName: sourceUrl, success: false};
}
};
@@ -93,6 +93,7 @@ export const uploadToCanvasPart2 = async ({
const redirectResponse = await axiosClient.get(redirectUrl);
console.log("redirect response", redirectResponse.data);
}
// console.log("returning from part 2", JSON.stringify(response.data));
return response.data.url;
} catch (error) {
console.error("Error uploading file to Canvas part 2:", error);