Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Jan 15, 2025
1 parent 87c10a8 commit 16607eb
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import path from 'path';
export class LogFile {
private basePath;
private fileName;
private operation;

constructor(
operation: string,
operation: 'Restore' | 'Backup',
basePath: string = process.cwd()
) {
this.basePath = basePath;
this.operation = operation;

this.fileName = `${Date.now()}-${operation}.jsonl`;
this.fileName = `${operation}-${Date.now()}.jsonl`;
}

private async write(data: string) {
Expand All @@ -20,17 +22,24 @@ export class LogFile {
data + '\n'
);
}
get isRestored() {
return String(this.operation).toLowerCase() === 'restore';
}

async append(data: {
target: string,
source: string,
type: 'file' | 'directory',
status: 'success' | 'error' | 'skip',
}) {
await this.write(JSON.stringify({
const obj = {
...data,
target: path.relative(this.basePath, data.target),
// timestamp: Date.now(),
}));
...(
this.isRestored
? { source: path.relative(this.basePath, data.source) }
: { target: path.relative(this.basePath, data.target) }
)
}
return this.write(JSON.stringify(obj));
}
}

0 comments on commit 16607eb

Please sign in to comment.