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