forked from YMFE/yapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.js
More file actions
28 lines (27 loc) · 773 Bytes
/
storage.js
File metadata and controls
28 lines (27 loc) · 773 Bytes
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
module.exports = function storageCreator(id) {
const storageModel = require('../models/storage.js');
const yapi = require('../yapi.js');
const defaultData = {}
return {
getItem: async (name = '') => {
let inst = yapi.getInst(storageModel);
let data = await inst.get(id);
data = data || defaultData;
if (name) return data[name];
return data;
},
setItem: async (name, value) => {
let inst = yapi.getInst(storageModel);
let curData = await inst.get(id);
let data = curData || defaultData;
let result;
data[name] = value;
if(!curData){
result = await inst.save(id, data, true)
}else{
result = await inst.save(id, data, false)
}
return result;
}
}
}