1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-04 09:35:51 +02:00

[API] Better appdata get/set endpoints (BREAKING)

This commit is contained in:
syuilo
2017-03-19 15:21:43 +09:00
parent afc06f255a
commit 31550ce1d9
2 changed files with 35 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
/**
* Module dependencies
*/
import $ from 'cafy';
import Appdata from '../../../models/appdata';
/**
@@ -14,10 +15,8 @@ import Appdata from '../../../models/appdata';
*/
module.exports = (params, user, app, isSecure) => new Promise(async (res, rej) => {
// Get 'key' parameter
let key = params.key;
if (key === undefined) {
key = null;
}
const [key = null, keyError] = $(params.key).optional.nullable.string().match(/[a-z_]+/).$;
if (keyError) return rej('invalid key param');
if (isSecure) {
if (!user.data) {
@@ -38,7 +37,9 @@ module.exports = (params, user, app, isSecure) => new Promise(async (res, rej) =
const appdata = await Appdata.findOne({
app_id: app._id,
user_id: user._id
}, select);
}, {
fields: select
});
if (appdata) {
res(appdata.data);