hotfix fetch

This commit is contained in:
Vincent Alamelle 2023-05-15 16:08:10 +02:00
parent 2e4ca63d9d
commit 3403b563d8
4 changed files with 80 additions and 3 deletions

64
package-lock.json generated
View File

@ -22,6 +22,7 @@
"multer": "^1.4.5-lts.1",
"next": "^13.1.5",
"node-cache": "^5.1.2",
"node-fetch": "^2.6.11",
"node-schedule": "^2.1.1",
"prisma-query": "^2.0.0",
"reflect-metadata": "^0.1.13",
@ -39,6 +40,7 @@
"@types/jsonwebtoken": "^9.0.1",
"@types/multer": "^1.4.7",
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.3",
"@types/node-schedule": "^2.1.0",
"@types/uuid": "^9.0.0",
"dotenv": "^16.0.3",
@ -1442,6 +1444,30 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.9.tgz",
"integrity": "sha512-IeB32oIV4oGArLrd7znD2rkHQ6EDCM+2Sr76dJnrHwv9OHBTTM6nuDLK9bmikXzPa0ZlWMWtRGo/Uw4mrzQedA=="
},
"node_modules/@types/node-fetch": {
"version": "2.6.3",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.3.tgz",
"integrity": "sha512-ETTL1mOEdq/sxUtgtOhKjyB2Irra4cjxksvcMUR5Zr4n+PxVhsCD9WS46oPbHL3et9Zde7CNRr+WUNlcHvsX+w==",
"dev": true,
"dependencies": {
"@types/node": "*",
"form-data": "^3.0.0"
}
},
"node_modules/@types/node-fetch/node_modules/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"dev": true,
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/@types/node-schedule": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@types/node-schedule/-/node-schedule-2.1.0.tgz",
@ -4351,6 +4377,25 @@
"node": ">= 8.0.0"
}
},
"node_modules/node-fetch": {
"version": "2.6.11",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz",
"integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/node-int64": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
@ -5423,6 +5468,11 @@
"nodetouch": "bin/nodetouch.js"
}
},
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
},
"node_modules/ts-jest": {
"version": "29.1.0",
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.0.tgz",
@ -5756,6 +5806,20 @@
"makeerror": "1.0.12"
}
},
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
},
"node_modules/whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"dependencies": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",

View File

@ -53,6 +53,7 @@
"multer": "^1.4.5-lts.1",
"next": "^13.1.5",
"node-cache": "^5.1.2",
"node-fetch": "^2.6.11",
"node-schedule": "^2.1.1",
"prisma-query": "^2.0.0",
"reflect-metadata": "^0.1.13",
@ -70,6 +71,7 @@
"@types/jsonwebtoken": "^9.0.1",
"@types/multer": "^1.4.7",
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.3",
"@types/node-schedule": "^2.1.0",
"@types/uuid": "^9.0.0",
"dotenv": "^16.0.3",

View File

@ -0,0 +1,10 @@
/*
Warnings:
- Added the required column `mimetype` to the `files` table without a default value. This is not possible if the table is not empty.
- Added the required column `size` to the `files` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "files" ADD COLUMN "mimetype" VARCHAR(255) NOT NULL,
ADD COLUMN "size" INTEGER NOT NULL;

View File

@ -6,8 +6,10 @@ import CryptoService from "../CryptoService/CryptoService";
import IpfsService from "../IpfsService/IpfsService";
import { BackendVariables } from "@Common/config/variables/Variables";
import { Readable } from "stream";
import uuid from "uuid";
import {v4} from "uuid";
import { Files } from "@prisma/client";
import fetch from "node-fetch";
@Service()
export default class FilesService extends BaseService {
@ -42,7 +44,6 @@ export default class FilesService extends BaseService {
*/
public async download(uid: string) {
const file = await this.filesRepository.findOneByUid(uid);
console.log(file, uid);
if (!file?.key) return null;
const fileResult = await fetch(file.file_path);
const fileArrayBuffer = await fileResult.arrayBuffer();
@ -54,7 +55,7 @@ export default class FilesService extends BaseService {
* @throws {Error} If file cannot be created
*/
public async create(file: File, fileData: Express.Multer.File) {
const key = uuid.v4();
const key = v4();
const encryptedFile = await this.cryptoService.encrypt(fileData.buffer, key);
const upload = await this.ipfsService.pinFile(Readable.from(encryptedFile), fileData.originalname);
const fileToCreate: File = file;