- addes @adonisjs/redis fo saving session into redis with redis.ts contract and config

- npm updated
- added createHashValues and dlete inside File.ts
- added dataset_count property inside Subject.ts
- corrected rotes.ts with correct permissions
This commit is contained in:
Kaimbacher 2023-11-27 17:17:22 +01:00
parent d8bdce1369
commit b6fdfbff41
29 changed files with 496 additions and 201 deletions

View file

@ -7,6 +7,7 @@ import BaseModel from './BaseModel';
import * as fs from 'fs';
import crypto from 'crypto';
import { TransactionClientContract } from '@ioc:Adonis/Lucid/Database';
import Drive from '@ioc:Adonis/Core/Drive';
export default class File extends BaseModel {
// private readonly _data: Uint8Array;
@ -116,21 +117,20 @@ export default class File extends BaseModel {
serializeAs: 'fileData',
})
public get fileData(): string {
// return this.fileData;
// const fileData = fs.readFileSync(path.resolve(__dirname, this.filePath));
// const fileData = fs.readFileSync(this.filePath);
const fileContent: Buffer = fs.readFileSync(this.filePath);
// Create a Blob from the file content
// const blob = new Blob([fileContent], { type: this.type }); // Adjust
// let fileSrc = URL.createObjectURL(blob);
// return fileSrc;
try {
const fileContent: Buffer = fs.readFileSync(this.filePath);
// Create a Blob from the file content
// const blob = new Blob([fileContent], { type: this.type }); // Adjust
// let fileSrc = URL.createObjectURL(blob);
// return fileSrc;
// return Buffer.from(fileContent);
// get the buffer from somewhere
// const buff = fs.readFileSync('./test.bin');
// create a JSON string that contains the data in the property "blob"
const json = JSON.stringify({ blob: fileContent.toString('base64') });
return json;
// create a JSON string that contains the data in the property "blob"
const json = JSON.stringify({ blob: fileContent.toString('base64') });
return json;
} catch (err) {
// console.error(`Error reading file: ${err}`);
return '';
}
}
public async createHashValues(trx?: TransactionClientContract) {
@ -139,7 +139,7 @@ export default class File extends BaseModel {
for (const type of hashtypes) {
const hash = new HashValue();
hash.type = type;
const hashString = await this.checksumFile(this.filePath, type); // Assuming getRealHash is a method in the same model
const hashString = await this._checksumFile(this.filePath, type); // Assuming getRealHash is a method in the same model
hash.value = hashString;
// https://github.com/adonisjs/core/discussions/1872#discussioncomment-132289
@ -152,7 +152,17 @@ export default class File extends BaseModel {
}
}
private async checksumFile(path, hashName = 'md5'): Promise<string> {
public async delete() {
if (this.pathName) {
// Delete file from additional storage
await Drive.delete(this.pathName);
}
// Call the original delete method of the BaseModel to remove the record from the database
await super.delete();
}
private async _checksumFile(path, hashName = 'md5'): Promise<string> {
return new Promise((resolve, reject) => {
const hash = crypto.createHash(hashName);
const stream = fs.createReadStream(path);