- addes @adonisjs/redis fo saving session into redis with redis.ts contract and config
Some checks failed
CI Pipeline / japa-tests (push) Failing after 52s
Some checks failed
CI Pipeline / japa-tests (push) Failing after 52s
- 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:
parent
d8bdce1369
commit
b6fdfbff41
29 changed files with 496 additions and 201 deletions
|
@ -203,7 +203,7 @@ export default class Dataset extends DatasetExtension {
|
|||
pivotForeignKey: 'document_id',
|
||||
pivotRelatedForeignKey: 'person_id',
|
||||
pivotTable: 'link_documents_persons',
|
||||
pivotColumns: ['role', 'sort_order', 'allow_email_contact'],
|
||||
pivotColumns: ['role', 'sort_order', 'allow_email_contact', 'contributor_type'],
|
||||
onQuery(query) {
|
||||
query.wherePivot('role', 'contributor');
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -69,6 +69,12 @@ export default class Person extends BaseModel {
|
|||
return stock;
|
||||
}
|
||||
|
||||
@computed()
|
||||
public get pivot_contributor_type() {
|
||||
const contributor_type = this.$extras.pivot_contributor_type; //my pivot column name was "stock"
|
||||
return contributor_type;
|
||||
}
|
||||
|
||||
@manyToMany(() => Dataset, {
|
||||
pivotForeignKey: 'person_id',
|
||||
pivotRelatedForeignKey: 'document_id',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { column, SnakeCaseNamingStrategy, manyToMany, ManyToMany, beforeCreate, beforeUpdate } from '@ioc:Adonis/Lucid/Orm';
|
||||
import { column, SnakeCaseNamingStrategy, manyToMany, ManyToMany, computed} from '@ioc:Adonis/Lucid/Orm';
|
||||
import BaseModel from './BaseModel';
|
||||
|
||||
import { DateTime } from 'luxon';
|
||||
|
@ -44,28 +44,33 @@ export default class Subject extends BaseModel {
|
|||
})
|
||||
public updated_at: DateTime;
|
||||
|
||||
@beforeCreate()
|
||||
@beforeUpdate()
|
||||
public static async resetDate(role) {
|
||||
role.created_at = this.formatDateTime(role.created_at);
|
||||
role.updated_at = this.formatDateTime(role.updated_at);
|
||||
}
|
||||
// @beforeCreate()
|
||||
// @beforeUpdate()
|
||||
// public static async resetDate(role) {
|
||||
// role.created_at = this.formatDateTime(role.created_at);
|
||||
// role.updated_at = this.formatDateTime(role.updated_at);
|
||||
// }
|
||||
|
||||
private static formatDateTime(datetime) {
|
||||
let value = new Date(datetime);
|
||||
return datetime
|
||||
? value.getFullYear() +
|
||||
'-' +
|
||||
(value.getMonth() + 1) +
|
||||
'-' +
|
||||
value.getDate() +
|
||||
' ' +
|
||||
value.getHours() +
|
||||
':' +
|
||||
value.getMinutes() +
|
||||
':' +
|
||||
value.getSeconds()
|
||||
: datetime;
|
||||
// private static formatDateTime(datetime) {
|
||||
// let value = new Date(datetime);
|
||||
// return datetime
|
||||
// ? value.getFullYear() +
|
||||
// '-' +
|
||||
// (value.getMonth() + 1) +
|
||||
// '-' +
|
||||
// value.getDate() +
|
||||
// ' ' +
|
||||
// value.getHours() +
|
||||
// ':' +
|
||||
// value.getMinutes() +
|
||||
// ':' +
|
||||
// value.getSeconds()
|
||||
// : datetime;
|
||||
// }
|
||||
@computed()
|
||||
public get dataset_count() : number{
|
||||
const count = this.$extras.datasets_count; //my pivot column name was "stock"
|
||||
return count;
|
||||
}
|
||||
|
||||
@manyToMany(() => Dataset, {
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue