blob: 8c3a6b5f2b61956b5c2c16ae31a4963586a57244 (
plain)
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
|
function fetchDB(cb) {
let raw_db;
fetch('/db.json', {
method: 'GET'
}).then(res => {
if (res.status !== 200) {
return null
}
return res.json()
}).then(json => {
if (json) {
raw_db = parse(json)
}
cb(raw_db)
}).catch((err) => {
console.warn(err)
})
}
function parse(db) {
Object.keys(db).forEach(key => {
db[key] = db[key]
.filter((el) => ! el.disabled)
.sort((a,b) => a.__index<b.__index?-1:a.__index===b.__index?0:1)
})
return db
}
const backupDB = {
painting: [],
}
export default { fetch: fetchDB, backupDB }
|