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

なんかもうめっちゃやった

This commit is contained in:
syuilo
2017-11-08 23:43:47 +09:00
parent 1c60dfe2d9
commit 68b1721ecf
21 changed files with 431 additions and 184 deletions

View File

@@ -13,38 +13,27 @@ import Appdata from '../../../models/appdata';
* @param {Boolean} isSecure
* @return {Promise<any>}
*/
module.exports = (params, user, app, isSecure) => new Promise(async (res, rej) => {
module.exports = (params, user, app) => new Promise(async (res, rej) => {
if (app == null) return rej('このAPIはサードパーティAppからのみ利用できます');
// Get 'key' parameter
const [key = null, keyError] = $(params.key).optional.nullable.string().match(/[a-z_]+/).$;
if (keyError) return rej('invalid key param');
if (isSecure) {
if (!user.data) {
return res();
}
if (key !== null) {
const data = {};
data[key] = user.data[key];
res(data);
} else {
res(user.data);
}
} else {
const select = {};
if (key !== null) {
select[`data.${key}`] = true;
}
const appdata = await Appdata.findOne({
app_id: app._id,
user_id: user._id
}, {
fields: select
});
const select = {};
if (key !== null) {
select[`data.${key}`] = true;
}
const appdata = await Appdata.findOne({
app_id: app._id,
user_id: user._id
}, {
fields: select
});
if (appdata) {
res(appdata.data);
} else {
res();
}
if (appdata) {
res(appdata.data);
} else {
res();
}
});