Skip to content

Commit

Permalink
Fix the issue that the modifying responde body's rule cannot be added.
Browse files Browse the repository at this point in the history
当存在旧规则数据库时添加 receiveBody 字段报错,升级数据库版本号,触发 onupgradeneeded 事件后添加。
  • Loading branch information
Inaru committed Nov 11, 2019
1 parent 5276e18 commit c51080a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/core/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ function init() {
if (cache.receiveHeader === null) {
queue.push(updateCache('receiveHeader'));
}
if (cache.receiveBody === null) {
queue.push(updateCache('receiveBody'));
}
Promise.all(queue).then(() => {
if (cache.request === null || cache.sendHeader === null || cache.receiveHeader === null) {
if (cache.request === null || cache.sendHeader === null || cache.receiveHeader === null || cache.receiveBody === null) {
init();
}
});
Expand Down
6 changes: 5 additions & 1 deletion src/core/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import notify from './notify';

function getDatabase() {
return new Promise((resolve, reject) => {
const dbOpenRequest = window.indexedDB.open("headereditor", 3);
const dbOpenRequest = window.indexedDB.open("headereditor", 4);
dbOpenRequest.onsuccess = function(e) {
resolve(e.target.result);
};
Expand All @@ -23,6 +23,10 @@ function getDatabase() {
} else {
utils.TABLE_NAMES.forEach(k => {
const tx = event.target.transaction;
if(!tx.objectStoreNames.contains(k)){
event.target.result.createObjectStore(k, {keyPath: 'id', autoIncrement: true});
return;
}
const os = tx.objectStore(k);
os.openCursor().onsuccess = function(e) {
const cursor = e.target.result;
Expand Down
5 changes: 4 additions & 1 deletion src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
IS_CHROME: IS_CHROME,
CHROME_VERSION: CHROME_VERSION,
FIREFOX_VERSION: FIREFOX_VERSION,
TABLE_NAMES: ['request', 'sendHeader', 'receiveHeader'],
TABLE_NAMES: ['request', 'sendHeader', 'receiveHeader', 'receiveBody'],
getExportName(additional) {
return 'HE_' + dateFormat(new Date(), 'isoUtcDateTime').replace(/\:/g, '-') + (additional ? "_" + additional : "") + '.json';
},
Expand Down Expand Up @@ -93,6 +93,9 @@ export default {
if (ruleType === 'modifyReceiveHeader') {
return 'receiveHeader';
}
if (ruleType === 'modifyReceiveBody') {
return 'receiveBody';
}
},
upgradeRuleFormat(s) {
if (typeof(s.matchType) === "undefined") {
Expand Down

0 comments on commit c51080a

Please sign in to comment.