forked from FoundKeyGang/FoundKey
Optimization
This commit is contained in:
parent
679046f8a2
commit
10cb2a8332
5 changed files with 66 additions and 29 deletions
|
@ -15,7 +15,7 @@ import User from '../../models/user';
|
|||
*/
|
||||
module.exports = async (params, user, _, isSecure) => new Promise(async (res, rej) => {
|
||||
// Get 'home' parameter
|
||||
const [home, homeErr] = $(params.home).array().each(
|
||||
const [home, homeErr] = $(params.home).optional.array().each(
|
||||
$().strict.object()
|
||||
.have('name', $().string())
|
||||
.have('id', $().string())
|
||||
|
@ -23,12 +23,38 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
|||
.have('data', $().object())).$;
|
||||
if (homeErr) return rej('invalid home param');
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'client_settings.home': home
|
||||
}
|
||||
});
|
||||
// Get 'id' parameter
|
||||
const [id, idErr] = $(params.id).optional.string().$;
|
||||
if (idErr) return rej('invalid id param');
|
||||
|
||||
// Send response
|
||||
res();
|
||||
// Get 'data' parameter
|
||||
const [data, dataErr] = $(params.data).optional.object().$;
|
||||
if (dataErr) return rej('invalid data param');
|
||||
|
||||
if (home) {
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'client_settings.home': home
|
||||
}
|
||||
});
|
||||
|
||||
res();
|
||||
} else {
|
||||
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
|
||||
|
||||
const _home = user.client_settings.home;
|
||||
const widget = _home.find(w => w.id == id);
|
||||
|
||||
if (widget == null) return rej('widget not found');
|
||||
|
||||
widget.data = data;
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'client_settings.home': _home
|
||||
}
|
||||
});
|
||||
|
||||
res();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -73,10 +73,13 @@
|
|||
if (this.view == 2) this.view = 0;
|
||||
|
||||
// Save view state
|
||||
this.I.client_settings.home.filter(w => w.id == this.opts.id)[0].data.view = this.view;
|
||||
this.api('i/update_home', {
|
||||
home: this.I.client_settings.home
|
||||
id: this.opts.id,
|
||||
data: {
|
||||
view: this.view
|
||||
}
|
||||
}).then(() => {
|
||||
this.I.client_settings.home.find(w => w.id == this.opts.id).data.view = this.view;
|
||||
this.I.update();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -83,10 +83,13 @@
|
|||
this.zap();
|
||||
|
||||
// Save state
|
||||
this.I.client_settings.home.filter(w => w.id == this.opts.id)[0].data.channel = this.channelId;
|
||||
this.api('i/update_home', {
|
||||
home: this.I.client_settings.home
|
||||
id: this.opts.id,
|
||||
data: {
|
||||
channel: this.channelId
|
||||
}
|
||||
}).then(() => {
|
||||
this.I.client_settings.home.find(w => w.id == this.opts.id).data.channel = this.channelId;
|
||||
this.I.update();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -81,10 +81,13 @@
|
|||
if (this.view == 6) this.view = 0;
|
||||
|
||||
// Save view state
|
||||
this.I.client_settings.home.filter(w => w.id == this.opts.id)[0].data.view = this.view;
|
||||
this.api('i/update_home', {
|
||||
home: this.I.client_settings.home
|
||||
id: this.opts.id,
|
||||
data: {
|
||||
view: this.view
|
||||
}
|
||||
}).then(() => {
|
||||
this.I.client_settings.home.find(w => w.id == this.opts.id).data.view = this.view;
|
||||
this.I.update();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -88,14 +88,7 @@
|
|||
if (this.size == 2) this.size = 0;
|
||||
|
||||
this.applySize();
|
||||
|
||||
// Save state
|
||||
this.I.client_settings.home.filter(w => w.id == this.opts.id)[0].data.size = this.size;
|
||||
this.api('i/update_home', {
|
||||
home: this.I.client_settings.home
|
||||
}).then(() => {
|
||||
this.I.update();
|
||||
});
|
||||
this.save();
|
||||
};
|
||||
|
||||
this.change = () => {
|
||||
|
@ -147,14 +140,23 @@
|
|||
i.one('selected', folder => {
|
||||
this.folder = folder ? folder.id : null;
|
||||
this.fetch();
|
||||
this.save();
|
||||
});
|
||||
};
|
||||
|
||||
// Save state
|
||||
this.I.client_settings.home.filter(w => w.id == this.opts.id)[0].data.folder = this.folder;
|
||||
this.api('i/update_home', {
|
||||
home: this.I.client_settings.home
|
||||
}).then(() => {
|
||||
this.I.update();
|
||||
});
|
||||
this.save = () => {
|
||||
// Save state
|
||||
this.api('i/update_home', {
|
||||
id: this.opts.id,
|
||||
data: {
|
||||
folder: this.folder,
|
||||
size: this.size
|
||||
}
|
||||
}).then(() => {
|
||||
const w = this.I.client_settings.home.find(w => w.id == this.opts.id);
|
||||
w.data.folder = this.folder;
|
||||
w.data.size = this.size;
|
||||
this.I.update();
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue