Commit e71c3fda authored by yPhil's avatar yPhil
Browse files

Unique IMG OK (let rules)

parent 0f09cf11
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
PTL.db = {
delete: function(url) {
get: function(url) {
return new Promise((resolve, reject) => {
let dbOpen = indexedDB.open(PTL.DbName, PTL.DbVersion);
......@@ -10,90 +12,89 @@ PTL.db = {
var db = event.target.result;
const txn = db.transaction(PTL.DbStore, 'readwrite');
const txn = db.transaction(PTL.DbStore, 'readonly');
const store = txn.objectStore(PTL.DbStore);
let query = store.delete(url);
query.onsuccess = function (event) {
console.log(event);
console.log('DEL OK: %s (%s)', event);
let query = store.get(url);
query.onsuccess = (event) => {
if (!event.target.result) {
console.log(`Feed ${url} not found`);
resolve(null);
} else {
// console.table(event.target.result);
resolve(event.target.result);
}
};
query.onerror = function (event) {
console.log('DEL NOK: %s (%s)', event.target.errorCode);
query.onerror = (event) => {
console.log('Catched in db.read: [%s]', event.target.errorCode);
reject(event.target.errorCode);
};
txn.oncomplete = function () {
db.close();
};
};
});
},
getFeed: function(url) {
put: function(url, content) {
return new Promise((resolve, reject) => {
let dbOpen = indexedDB.open(PTL.DbName, PTL.DbVersion);
dbOpen.onsuccess = event => {
var db = event.target.result;
const txn = db.transaction(PTL.DbStore, 'readonly');
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
const feed = {url: url, content: content};
let query = store.put(feed);
let query = store.get(url);
query.onsuccess = (event) => {
if (!event.target.result) {
console.log(`Feed ${url} not found`);
resolve(null);
} else {
// console.table(event.target.result);
resolve(event.target.result);
}
query.onsuccess = event => {
resolve();
// console.log(event);
};
query.onerror = (event) => {
console.log('Catched in db.read: [%s]', event.target.errorCode);
reject(event.target.errorCode);
query.onerror = event => {
reject();
// console.log(event.target.errorCode);
};
txn.oncomplete = function () {
txn.oncomplete = () => {
db.close();
};
};
});
},
putFeed: function(url, content) {
},
del: function(url) {
return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
let dbOpen = indexedDB.open(PTL.DbName, PTL.DbVersion);
let dbOpen = indexedDB.open(PTL.DbName, PTL.DbVersion);
dbOpen.onsuccess = event => {
dbOpen.onsuccess = event => {
var db = event.target.result;
var db = event.target.result;
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
const feed = {url: url, content: content};
let query = store.put(feed);
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
let query = store.delete(url);
query.onsuccess = event => {
resolve();
// console.log(event);
};
query.onsuccess = function (event) {
console.log(event);
console.log('DEL OK: %s (%s)', event);
};
query.onerror = event => {
reject();
// console.log(event.target.errorCode);
};
query.onerror = function (event) {
console.log('DEL NOK: %s (%s)', event.target.errorCode);
};
txn.oncomplete = () => {
db.close();
};
txn.oncomplete = function () {
db.close();
};
});
}
};
});
}
};
......@@ -805,7 +805,7 @@ PTL.dialog = {
// localStorage.setItem(thisFeedUrl, '');
try {
PTL.db.delete(thisFeedUrl);
PTL.db.del(thisFeedUrl);
} catch (error) {
console.log('DB Error:: %s (%s)', error);
}
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment