Skip to content

Commit

Permalink
stop modifying file if no change
Browse files Browse the repository at this point in the history
  • Loading branch information
Neolex-Security committed Dec 3, 2023
1 parent 369e6d6 commit 6199d4a
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,6 @@ export default class H1ObsidianPlugin extends Plugin {

}

async overwriteFiles(reportNotes: Array<ReportNote>) {
try {
const folderPath = normalizePath(`${this.settings.directory}/Bugs`);
let existingReportFiles = this.app.vault.getMarkdownFiles()
existingReportFiles = existingReportFiles.filter(file => file.path.startsWith(folderPath));
for (const reportNote of reportNotes) {
const foundExistingReport = existingReportFiles.find((reportFile: TFile) => reportFile.basename.split("-").pop() === reportNote.id);
if(foundExistingReport){
await this.app.vault.modify(foundExistingReport, reportNote["content"]);

}else{
console.log("report "+reportNote["id"]+" not found create "+reportNote["filename"])
await this.app.vault.create(reportNote["filename"],reportNote["content"])
}
}
} catch (err) {
new Notice('Error: Unable to overwrite the file:'+err);
console.log('Error overwriting file:', err);
}
}

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
Expand Down Expand Up @@ -249,7 +228,7 @@ export default class H1ObsidianPlugin extends Plugin {
const newReportNote: ReportNote = {
id: item.id,
content: noteContent,
filename: fileName
filename: fileName,
};
reportNotes.push(newReportNote);

Expand All @@ -258,6 +237,30 @@ export default class H1ObsidianPlugin extends Plugin {

}

async overwriteFiles(reportNotes: Array<ReportNote>) {
try {
const folderPath = normalizePath(`${this.settings.directory}/Bugs`);
let existingReportFiles = this.app.vault.getMarkdownFiles()
existingReportFiles = existingReportFiles.filter(file => file.path.startsWith(folderPath));
for (const reportNote of reportNotes) {
const foundExistingReport = existingReportFiles.find((reportFile: TFile) => reportFile.basename.split("-").pop() === reportNote.id);
if(foundExistingReport){
let currentContent = await this.app.vault.cachedRead(foundExistingReport);
if(currentContent!=reportNote["content"]){
await this.app.vault.modify(foundExistingReport, reportNote["content"]);
}

}else{
console.log("report "+reportNote["id"]+" not found create "+reportNote["filename"])
await this.app.vault.create(reportNote["filename"],reportNote["content"])
}
}
} catch (err) {
new Notice('Error: Unable to overwrite the file:'+err);
console.log('Error overwriting file:', err);
}
}

async getBountyReport(reportId: number, earnings: any[]) {
let ret = 0;
for (const earning of earnings) {
Expand Down

0 comments on commit 6199d4a

Please sign in to comment.