draft
This commit is contained in:
Родитель
5466150b2f
Коммит
8f62e2a8c8
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -49,7 +49,6 @@
|
|||
"npm": "8.19.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.358.0",
|
||||
"@fluent/bundle": "^0.17.1",
|
||||
"@fluent/langneg": "^0.6.2",
|
||||
"@fluent/react": "^0.15.0",
|
||||
|
@ -60,6 +59,7 @@
|
|||
"@types/node": "^20.1.1",
|
||||
"@types/react": "^18.2.6",
|
||||
"@types/react-dom": "^18.2.4",
|
||||
"aws-sdk": "^2.1404.0",
|
||||
"client-oauth2": "^4.3.3",
|
||||
"csrf-csrf": "^2.2.2",
|
||||
"dotenv": "^16.0.3",
|
||||
|
|
|
@ -16,13 +16,38 @@ import { resolve as pathResolve } from "node:path";
|
|||
import { finished } from 'stream/promises';
|
||||
import fs from "fs";
|
||||
import { Readable } from 'stream';
|
||||
import aws from 'aws-sdk';
|
||||
import { Upload } from "@aws-sdk/lib-storage";
|
||||
|
||||
let logoMap;
|
||||
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
||||
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
||||
const region = process.env.AWS_REGION;
|
||||
const Bucket = process.env.S3_BUCKET;
|
||||
|
||||
const s3 = new aws.S3({
|
||||
region,
|
||||
credentials: {
|
||||
accessKeyId,
|
||||
secretAccessKey,
|
||||
},
|
||||
});
|
||||
|
||||
async function uploadToS3(fileName, fileStream) {
|
||||
const uploadParams = {
|
||||
Bucket,
|
||||
Key: fileName,
|
||||
Body: fileStream
|
||||
}
|
||||
try {
|
||||
await s3.upload(uploadParams).promise()
|
||||
console.log('Successfully uploaded data to ' + Bucket + '/' + fileName)
|
||||
} catch (err) {
|
||||
console.error(err, err.stack)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getBreachIcons(breaches) {
|
||||
if (logoMap) {
|
||||
return logoMap;
|
||||
}
|
||||
let logoMap;
|
||||
async function fetchBreachIcons() {
|
||||
const breachDomains = breaches
|
||||
.map((breach) => breach.Domain)
|
||||
|
@ -49,7 +74,9 @@ export async function getBreachIcons(breaches) {
|
|||
const res = await fetch(
|
||||
`https://icons.duckduckgo.com/ip3/${breachDomain}.ico`);
|
||||
const fileStream = fs.createWriteStream(logoPath, { flags: 'wx' });
|
||||
await finished(Readable.fromWeb(res.body).pipe(fileStream));
|
||||
const bodyReadable = Readable.fromWeb(res.body)
|
||||
await finished(bodyReadable.pipe(fileStream));
|
||||
await uploadToS3(logoFilename, res.fileStream)
|
||||
})
|
||||
));
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче