import { access } from 'node:fs'; import { CheckResult } from '../helpers'; import type { HealthIndicator } from '../types'; export interface FileSystemCheckOptions { /** * Absolute path to file or directory */ path: string; /** * Access mode (see fs.access docs on nodejs website) */ mode?: number; } /** * FileSystemIndicator checks if specified file or directory * exists and is accessible to the application * * TODO: Need to be tested! Especially modes. */ export abstract class FileSystemIndicator implements HealthIndicator { private path: string; private mode: number | undefined; constructor(options: FileSystemCheckOptions) { this.path = options.path; this.mode = options.mode; } /** * Проверяет, существует ли файл и есть ли к нему доступ */ check(): Promise { return new Promise((resolve, reject) => { access(this.path, this.mode, (error) => { if (error) { reject({ error }); return; } resolve(CheckResult.up({ path: this.path })); }); }); } }