Skip to content

Commit 44a0fb9

Browse files
committed
Add configuration settings
1 parent 88f4344 commit 44a0fb9

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

injected/integration-test/duck-ai-data-clearing.spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ test('duck-ai-data-clearing feature handles IndexedDB errors gracefully', async
4949
// Mock IndexedDB to fail
5050
await page.evaluate(() => {
5151
const originalOpen = window.indexedDB.open;
52-
window.indexedDB.open = () => {
52+
window.indexedDB.open = function () {
5353
const request = originalOpen.call(window.indexedDB, 'nonexistent');
54-
// Simulate an error
54+
// Immediately fire the error event
5555
setTimeout(() => {
56-
if (request.onerror) {
57-
request.onerror(new Error('Simulated IndexedDB error'));
56+
if (typeof request.onerror === 'function') {
57+
// Create a fake event object
58+
const event = new Event('error');
59+
request.onerror(event);
5860
}
59-
}, 10);
61+
}, 0);
6062
return request;
6163
};
6264
});
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
2+
"readme": "This config is used to test enabling the Duck.ai data clearing feature.",
23
"features": {
34
"duckAiDataClearing": {
4-
"state": "enabled"
5+
"state": "enabled",
6+
"settings": {
7+
"chatsLocalStorageKey": "savedAIChats",
8+
"chatImagesIndexDbName": "savedAIChatData",
9+
"chatImagesObjectStoreName": "chat-images"
10+
},
11+
"exceptions": []
512
}
613
},
7-
"unprotectedTemporary": [],
8-
"featureToggles": {}
9-
}
14+
"unprotectedTemporary": []
15+
}

injected/src/features/duck-ai-data-clearing.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ export class DuckAiDataClearing extends ContentFeature {
1818
this.clearSavedAIChats();
1919
} catch (error) {
2020
success = false;
21-
this.log.error('Error clearing `savedAIChats`:', error);
21+
this.log.error('Error clearing saved chats:', error);
2222
}
2323

2424
try {
2525
await this.clearChatImagesStore();
2626
} catch (error) {
2727
success = false;
28-
this.log.error('Error clearing `chat-images` object store:', error);
28+
this.log.error('Error clearing saved chat images:', error);
2929
}
3030

3131
if (success) {
@@ -36,16 +36,20 @@ export class DuckAiDataClearing extends ContentFeature {
3636
}
3737

3838
clearSavedAIChats() {
39-
this.log.info('Clearing `savedAIChats`');
39+
const localStorageKey = this.getFeatureSetting('chatsLocalStorageKey');
4040

41-
window.localStorage.removeItem('savedAIChats');
41+
this.log.info(`Clearing '${localStorageKey}'`);
42+
window.localStorage.removeItem(localStorageKey);
4243
}
4344

4445
clearChatImagesStore() {
45-
this.log.info('Clearing `chat-images` object store');
46+
const indexDbName = this.getFeatureSetting('chatImagesIndexDbName');
47+
const objectStoreName = this.getFeatureSetting('chatImagesObjectStoreName');
48+
49+
this.log.info(`Clearing '${indexDbName}' object store`);
4650

4751
return new Promise((resolve, reject) => {
48-
const request = window.indexedDB.open('savedAIChatData');
52+
const request = window.indexedDB.open(indexDbName);
4953
request.onerror = (event) => {
5054
this.log.error('Error opening IndexedDB:', event);
5155
reject(event);
@@ -59,16 +63,16 @@ export class DuckAiDataClearing extends ContentFeature {
5963
}
6064

6165
// Check if the object store exists
62-
if (!db.objectStoreNames.contains('chat-images')) {
63-
this.log.info('chat-images object store does not exist, nothing to clear');
66+
if (!db.objectStoreNames.contains(objectStoreName)) {
67+
this.log.info(`'${objectStoreName}' object store does not exist, nothing to clear`);
6468
db.close();
6569
resolve(null);
6670
return;
6771
}
6872

6973
try {
70-
const transaction = db.transaction(['chat-images'], 'readwrite');
71-
const objectStore = transaction.objectStore('chat-images');
74+
const transaction = db.transaction([objectStoreName], 'readwrite');
75+
const objectStore = transaction.objectStore(objectStoreName);
7276
const clearRequest = objectStore.clear();
7377
clearRequest.onsuccess = () => {
7478
db.close();

0 commit comments

Comments
 (0)