Skip to content

Commit

Permalink
refactor remove functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ETLaurent committed Apr 11, 2024
1 parent 24704ef commit 86df216
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
9 changes: 0 additions & 9 deletions lib/methods/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,6 @@ module.exports = self => {
}
},

async remove(filepath) {
console.info(`[export] removing ${filepath}`);
try {
await fsp.unlink(filepath);
} catch (error) {
self.apos.util.error(error);
}
},

// Report is available for 10 minutes by default
removeFromUploadFs(downloadPath, expiration) {
const ms = expiration || 1000 * 60 * 10;
Expand Down
24 changes: 2 additions & 22 deletions lib/methods/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module.exports = self => {
.dismiss(req, notificationId, 2000)
.catch(self.apos.util.error);

await self.removeExport(exportPath);
await self.remove(exportPath);
return;
}

Expand Down Expand Up @@ -531,27 +531,7 @@ module.exports = self => {
self.apos.notification.dismiss(req, notificationId, 2000).catch(self.apos.util.error);
}

await self.removeExport(exportPath);
},

async removeExport(filepath) {
try {
const stat = await fsp.lstat(filepath);
if (stat.isDirectory()) {
await fsp.rm(filepath, {
recursive: true,
force: true
});
} else {
await fsp.unlink(filepath);
}
console.info(`[import] export path ${filepath} has been removed`);
} catch (err) {
console.trace();
self.apos.util.error(
`Error while trying to remove the file or folder: ${filepath}. You might want to remove it yourself.`
);
}
await self.remove(exportPath);
}
};
};
22 changes: 22 additions & 0 deletions lib/methods/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fsp = require('node:fs/promises');
const importMethods = require('./import');
const exportMethods = require('./export');

Expand Down Expand Up @@ -34,6 +35,27 @@ module.exports = self => {

return true;
},

async remove(filepath) {
try {
const stat = await fsp.lstat(filepath);
if (stat.isDirectory()) {
await fsp.rm(filepath, {
recursive: true,
force: true
});
} else {
await fsp.unlink(filepath);
}
console.info(`removed: ${filepath}`);
} catch (err) {
console.trace();
self.apos.util.error(
`Error while trying to remove the file or folder: ${filepath}. You might want to remove it yourself.`
);
}
},

...importMethods(self),
...exportMethods(self)
};
Expand Down

0 comments on commit 86df216

Please sign in to comment.