cr
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { existsSync, createWriteStream, mkdirSync } from 'fs';
|
||||
import { dirname } from 'path';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { existsSync, createWriteStream, mkdirSync } from "fs";
|
||||
import { dirname } from "path";
|
||||
import axios from "axios";
|
||||
import { Logger } from "@nestjs/common";
|
||||
|
||||
export class ImageUtils {
|
||||
private static readonly logger = new Logger('ImageUtils');
|
||||
private static readonly logger = new Logger("ImageUtils");
|
||||
|
||||
/**
|
||||
* Downloads an image from a URL and saves it to a local path.
|
||||
@@ -26,8 +26,8 @@ export class ImageUtils {
|
||||
// Download
|
||||
const response = await axios({
|
||||
url,
|
||||
method: 'GET',
|
||||
responseType: 'stream',
|
||||
method: "GET",
|
||||
responseType: "stream",
|
||||
timeout: 5000,
|
||||
validateStatus: (status) => status === 200, // Only save if 200 OK
|
||||
});
|
||||
@@ -37,8 +37,8 @@ export class ImageUtils {
|
||||
response.data.pipe(writer);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
writer.on('finish', () => resolve(true));
|
||||
writer.on('error', (err) => {
|
||||
writer.on("finish", () => resolve(true));
|
||||
writer.on("error", (err) => {
|
||||
this.logger.warn(
|
||||
`Failed to write image to ${localPath}: ${err.message}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user