mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-03 04:50:14 +08:00
bugfix (indexedDB): flushing a non existing db would throw a critical error ... #97
This commit is contained in:
@ -7,9 +7,11 @@ function Data(){
|
|||||||
this._init();
|
this._init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DB_VERSION = 2;
|
||||||
|
|
||||||
Data.prototype._init = function(){
|
Data.prototype._init = function(){
|
||||||
const request = indexedDB.open('nuage', 2);
|
const request = indexedDB.open('nuage', DB_VERSION);
|
||||||
request.onupgradeneeded = (e) => this._setup(e.target.result);
|
request.onupgradeneeded = (e) => this._setup(e);
|
||||||
|
|
||||||
this.db = new Promise((done, err) => {
|
this.db = new Promise((done, err) => {
|
||||||
request.onsuccess = (e) => {
|
request.onsuccess = (e) => {
|
||||||
@ -21,10 +23,16 @@ Data.prototype._init = function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Data.prototype._setup = function(db){
|
Data.prototype._setup = function(e){
|
||||||
let store;
|
let store;
|
||||||
db.deleteObjectStore(this.FILE_PATH);
|
let db = e.target.result;
|
||||||
db.deleteObjectStore(this.FILE_CONTENT);
|
|
||||||
|
if(e.oldVersion == 1){
|
||||||
|
// we've change the schema on v2 adding an index, let's flush
|
||||||
|
// to make sure everything will be fine
|
||||||
|
db.deleteObjectStore(this.FILE_PATH);
|
||||||
|
db.deleteObjectStore(this.FILE_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
store = db.createObjectStore(this.FILE_PATH, {keyPath: "path"});
|
store = db.createObjectStore(this.FILE_PATH, {keyPath: "path"});
|
||||||
store.createIndex("idx_path", "path", { unique: true });
|
store.createIndex("idx_path", "path", { unique: true });
|
||||||
|
|||||||
@ -124,7 +124,7 @@ export class FilesPage extends React.Component {
|
|||||||
this.observers.push(observer);
|
this.observers.push(observer);
|
||||||
this.setState({error: null});
|
this.setState({error: null});
|
||||||
if(path === "/"){
|
if(path === "/"){
|
||||||
Files.frequents().then((s) => console.log(s) && this.setState({frequents: s}));
|
Files.frequents().then((s) => this.setState({frequents: s}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user