aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-02-04 23:23:49 +0100
committer0neGal <mail@0negal.com>2024-02-04 23:23:49 +0100
commitc60d4d7aec2985fbf9bddff15c0cc379af6ef226 (patch)
treede6ee6079613e257bb9ebb6c2fae0c69f5d0e803
parent04ce533ced37d3a7a938ebbcb02062b27aca1789 (diff)
downloadViper-c60d4d7aec2985fbf9bddff15c0cc379af6ef226.tar.gz
Viper-c60d4d7aec2985fbf9bddff15c0cc379af6ef226.zip
deleting request cache now deletes old cache file
We previously had a requests cache file just named `viper-requests.json` in the system's cache folder, we now also delete that alongside the current file, simply cleaning up a user's cache folder, as that file will not be used anymore. We also technically had a file named `requests.json`, however the name is too vague and could potentially (unlikely, but oh well) delete something that isn't actually Viper's older requests cache file.
-rw-r--r--src/modules/requests.js22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/modules/requests.js b/src/modules/requests.js
index 60e0760..dac3a4f 100644
--- a/src/modules/requests.js
+++ b/src/modules/requests.js
@@ -145,16 +145,18 @@ requests.cache.delete = (cache_key) => {
// deletes all cached keys
requests.cache.delete.all = () => {
- // if the file already exists, and actually is a file, we will
- // simply empty it by writing an empty Object to it
- if (fs.existsSync(cache_file)
- && fs.statSync(cache_file).isFile()) {
-
- fs.writeFileSync(cache_file, "{}");
- } else if (fs.existsSync(cache_file)) {
- // if `cache_file` does exist, but its not a file, we'll delete
- // it completely
- fs.rmSync(cache_file, {recursive: true});
+ // paths to files we'll be deleting
+ let files = [
+ cache_file,
+ path.join(app.getPath("cache"), "viper-requests.json")
+ ]
+
+ // run through list of files, and attempt to delete each of them
+ for (let i = 0; i < files.length; i++) {
+ // if the file actually exists, delete it!
+ if (fs.existsSync(files[i])) {
+ fs.rmSync(files[i], {recursive: true});
+ }
}
}