forked from kstost/aicodehelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storageManager.js
43 lines (41 loc) · 1.28 KB
/
storageManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const vscode = require('vscode');
const keytar = require('keytar');
async function removeAllPassword() {
const serviceName = 'aicodehelper';
try {
const accounts = await keytar.findCredentials(serviceName);
for (const account of accounts) await keytar.deletePassword(serviceName, account.account);
} catch { }
}
function removeAllConfigs() {
const config = vscode.workspace.getConfiguration('aicodehelper');
let keys = [
'temperature',
'debugprompt',
'namingprompt',
'codereviewprompt',
'refactoringprompt',
'commmentingprompt',
'generatingprompt',
'gptkey',
'APIKey',
'language',
]
for (const key of keys) config.update(key, undefined, vscode.ConfigurationTarget.Global);
}
async function resetAll(context) {
await removeAllPassword();
removeAllConfigs();
await resetPromptsHistory(context)
try { data = await context.secrets.store('gptkey', undefined); } catch (e) { }
}
async function resetPromptsHistory(context) {
await context.secrets.store('recentprompt', JSON.stringify([]));
await context.secrets.store('recentcodeprompt', JSON.stringify([]));
}
module.exports = {
removeAllPassword,
removeAllConfigs,
resetAll,
resetPromptsHistory
};