- update to AdonisJS 6

This commit is contained in:
Kaimbacher 2024-03-14 20:25:27 +01:00
parent f828ca4491
commit cb51a4136f
167 changed files with 21485 additions and 21212 deletions

View file

@ -1,8 +1,9 @@
import { BaseCommand } from '@adonisjs/core/build/standalone';
import crypto from 'crypto';
import fs from 'fs';
// import Config from '@ioc:Adonis/Core/Config';
import Logger from '@ioc:Adonis/Core/Logger';
import logger from '@adonisjs/core/services/logger';
import { BaseCommand } from "@adonisjs/core/ace";
import { CommandOptions } from "@adonisjs/core/types/ace";
export default class ValidateChecksum extends BaseCommand {
/**
@ -14,26 +15,14 @@ export default class ValidateChecksum extends BaseCommand {
* Command description is displayed in the "help" output
*/
public static description = '';
public static settings = {
/**
* Set the following value to true, if you want to load the application
* before running the command. Don't forget to call `node ace generate:manifest`
* afterwards.
*/
loadApp: true,
/**
* Set the following value to true, if you want this command to keep running until
* you manually decide to exit the process. Don't forget to call
* `node ace generate:manifest` afterwards.
*/
stayAlive: false,
};
static options: CommandOptions = {
loadApp: true,
staysAlive: false,
};
public async run() {
// this.logger.info('Hello world!')
const { default: File } = await import('App/Models/File');
const { default: File } = await import('#app/Models/File');
// const { default: HashValue } = await (await (import ('App/Models/HashValue')));
// query all published files from database:
@ -55,21 +44,21 @@ export default class ValidateChecksum extends BaseCommand {
calculatedMd5FileHash = await this.checksumFile(filePath, 'md5');
} catch (exception) {
// this.logger.error(exception.message);
Logger.error(exception.message);
logger.error(exception.message);
continue;
}
if (hashValue['md5'] === calculatedMd5FileHash) {
Logger.info(`File id ${file.id} OK: stored md5 checksum: ${calculatedMd5FileHash}, same control md5 checksum: ${hashValue['md5']}`);
logger.info(`File id ${file.id} OK: stored md5 checksum: ${calculatedMd5FileHash}, same control md5 checksum: ${hashValue['md5']}`);
} else {
Logger.error(
logger.error(
`File id ${file.id}: stored md5 checksum: ${calculatedMd5FileHash}, control md5 checksum: ${hashValue['md5']}`,
);
}
}
}
private async checksumFile(path, hashName = 'md5'): Promise<string> {
private async checksumFile(path: string, hashName = 'md5'): Promise<string> {
return new Promise((resolve, reject) => {
const hash = crypto.createHash(hashName);
const stream = fs.createReadStream(path);