add mimetype and size of files
This commit is contained in:
parent
dcb7052a32
commit
b6f1e11f53
@ -48,7 +48,7 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.49",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.50",
|
||||
"module-alias": "^2.2.2",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"next": "^13.1.5",
|
||||
|
@ -57,8 +57,7 @@ export default class FilesController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const type = fileInfo.file.file_name.split(".").pop();
|
||||
if (type?.toLowerCase() === "pdf") response.setHeader("Content-Type", "application/pdf");
|
||||
response.setHeader("Content-Type", fileInfo.file.mimetype);
|
||||
response.setHeader("Content-Disposition", `inline; filename=${encodeURIComponent(fileInfo.file.file_name)}`);
|
||||
|
||||
this.httpSuccess(response, fileInfo.buffer);
|
||||
|
@ -204,6 +204,8 @@ model Files {
|
||||
document_uid String @db.VarChar(255)
|
||||
file_path String @unique @db.VarChar(255)
|
||||
file_name String @db.VarChar(255)
|
||||
mimetype String @db.VarChar(255)
|
||||
size Int
|
||||
archived_at DateTime?
|
||||
key String? @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
|
@ -37,6 +37,8 @@ export default class FilesRepository extends BaseRepository {
|
||||
},
|
||||
file_name: file.file_name,
|
||||
file_path: file.file_path,
|
||||
mimetype: file.mimetype,
|
||||
size: file.size,
|
||||
key: key
|
||||
},
|
||||
include: { document: true }
|
||||
|
@ -6,8 +6,12 @@ import CryptoService from "../CryptoService/CryptoService";
|
||||
import IpfsService from "../IpfsService/IpfsService";
|
||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||
import { Readable } from "stream";
|
||||
<<<<<<< HEAD
|
||||
import { v4 } from "uuid";
|
||||
import { Files } from "@prisma/client";
|
||||
=======
|
||||
import uuid from "uuid";
|
||||
>>>>>>> 14db92d (add mimetype and size of files)
|
||||
|
||||
@Service()
|
||||
export default class FilesService extends BaseService {
|
||||
@ -45,24 +49,32 @@ export default class FilesService extends BaseService {
|
||||
console.log(file, uid);
|
||||
if (!file?.key) return null;
|
||||
const fileResult = await fetch(file.file_path);
|
||||
const fileContent = await fileResult.arrayBuffer();
|
||||
return {file: file, buffer: await this.cryptoService.decrypt(Buffer.from(fileContent), file.key)};
|
||||
const fileArrayBuffer = await fileResult.arrayBuffer();
|
||||
return {file: file, buffer: await this.cryptoService.decrypt(Buffer.from(fileArrayBuffer), file.key)};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new file
|
||||
* @throws {Error} If file cannot be created
|
||||
*/
|
||||
<<<<<<< HEAD
|
||||
public async create(file: File, fileData: Express.Multer.File): Promise<Files> {
|
||||
const key = v4();
|
||||
fileData.mimetype;
|
||||
fileData.size;
|
||||
=======
|
||||
public async create(file: File, fileData: Express.Multer.File) {
|
||||
const key = uuid.v4();
|
||||
>>>>>>> 14db92d (add mimetype and size of files)
|
||||
const encryptedFile = await this.cryptoService.encrypt(fileData.buffer, key);
|
||||
const upload = await this.ipfsService.pinFile(Readable.from(encryptedFile), fileData.originalname);
|
||||
file.file_name = fileData.originalname; //encryptedFileName.toString('utf-8')
|
||||
file.file_path = this.variables.PINATA_GATEWAY.concat(upload.IpfsHash);
|
||||
const fileToCreate: File = file;
|
||||
fileToCreate.file_name = fileData.originalname;
|
||||
fileToCreate.file_path = this.variables.PINATA_GATEWAY.concat(upload.IpfsHash);
|
||||
fileToCreate.mimetype = fileData.mimetype;
|
||||
fileToCreate.size = fileData.size;
|
||||
|
||||
return this.filesRepository.create(file, key);
|
||||
return this.filesRepository.create(fileToCreate, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user