summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-11-08 23:43:47 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-11-08 23:43:47 +0900
commit68b1721ecf65484c1b679404246edc3627346c1b (patch)
treea5a6258518f3bb6a2bd53b8683abc2a602f4e46c /src/api
parent:v: (diff)
downloadmisskey-68b1721ecf65484c1b679404246edc3627346c1b.tar.gz
misskey-68b1721ecf65484c1b679404246edc3627346c1b.tar.bz2
misskey-68b1721ecf65484c1b679404246edc3627346c1b.zip
なんかもうめっちゃやった
Diffstat (limited to 'src/api')
-rw-r--r--src/api/endpoints.ts5
-rw-r--r--src/api/endpoints/i/appdata/get.ts45
-rw-r--r--src/api/endpoints/i/appdata/set.ts41
-rw-r--r--src/api/endpoints/i/update.ts8
-rw-r--r--src/api/endpoints/i/update_home.ts34
-rw-r--r--src/api/private/signup.ts50
-rw-r--r--src/api/serializers/user.ts9
7 files changed, 131 insertions, 61 deletions
diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts
index afefce39e5..2783c92027 100644
--- a/src/api/endpoints.ts
+++ b/src/api/endpoints.ts
@@ -160,6 +160,11 @@ const endpoints: Endpoint[] = [
kind: 'account-write'
},
{
+ name: 'i/update_home',
+ withCredential: true,
+ kind: 'account-write'
+ },
+ {
name: 'i/change_password',
withCredential: true
},
diff --git a/src/api/endpoints/i/appdata/get.ts b/src/api/endpoints/i/appdata/get.ts
index a1a57fa13a..571208d46c 100644
--- a/src/api/endpoints/i/appdata/get.ts
+++ b/src/api/endpoints/i/appdata/get.ts
@@ -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();
}
});
diff --git a/src/api/endpoints/i/appdata/set.ts b/src/api/endpoints/i/appdata/set.ts
index 9c3dbe185b..2804a14cb3 100644
--- a/src/api/endpoints/i/appdata/set.ts
+++ b/src/api/endpoints/i/appdata/set.ts
@@ -3,9 +3,6 @@
*/
import $ from 'cafy';
import Appdata from '../../../models/appdata';
-import User from '../../../models/user';
-import serialize from '../../../serializers/user';
-import event from '../../../event';
/**
* Set app data
@@ -16,7 +13,9 @@ import event from '../../../event';
* @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 'data' parameter
const [data, dataError] = $(params.data).optional.object()
.pipe(obj => {
@@ -43,31 +42,17 @@ module.exports = (params, user, app, isSecure) => new Promise(async (res, rej) =
set[`data.${key}`] = value;
}
- if (isSecure) {
- const _user = await User.findOneAndUpdate(user._id, {
+ await Appdata.update({
+ app_id: app._id,
+ user_id: user._id
+ }, Object.assign({
+ app_id: app._id,
+ user_id: user._id
+ }, {
$set: set
+ }), {
+ upsert: true
});
- res(204);
-
- // Publish i updated event
- event(user._id, 'i_updated', await serialize(_user, user, {
- detail: true,
- includeSecrets: true
- }));
- } else {
- await Appdata.update({
- app_id: app._id,
- user_id: user._id
- }, Object.assign({
- app_id: app._id,
- user_id: user._id
- }, {
- $set: set
- }), {
- upsert: true
- });
-
- res(204);
- }
+ res(204);
});
diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts
index 111a4b1909..c484c51a96 100644
--- a/src/api/endpoints/i/update.ts
+++ b/src/api/endpoints/i/update.ts
@@ -48,13 +48,19 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
if (bannerIdErr) return rej('invalid banner_id param');
if (bannerId) user.banner_id = bannerId;
+ // Get 'show_donation' parameter
+ const [showDonation, showDonationErr] = $(params.show_donation).optional.boolean().$;
+ if (showDonationErr) return rej('invalid show_donation param');
+ if (showDonation) user.client_settings.show_donation = showDonation;
+
await User.update(user._id, {
$set: {
name: user.name,
description: user.description,
avatar_id: user.avatar_id,
banner_id: user.banner_id,
- profile: user.profile
+ profile: user.profile,
+ 'client_settings.show_donation': user.client_settings.show_donation
}
});
diff --git a/src/api/endpoints/i/update_home.ts b/src/api/endpoints/i/update_home.ts
new file mode 100644
index 0000000000..b9a7642b8e
--- /dev/null
+++ b/src/api/endpoints/i/update_home.ts
@@ -0,0 +1,34 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import User from '../../models/user';
+
+/**
+ * Update myself
+ *
+ * @param {any} params
+ * @param {any} user
+ * @param {any} _
+ * @param {boolean} isSecure
+ * @return {Promise<any>}
+ */
+module.exports = async (params, user, _, isSecure) => new Promise(async (res, rej) => {
+ // Get 'home' parameter
+ const [home, homeErr] = $(params.home).array().each(
+ $().strict.object()
+ .have('name', $().string())
+ .have('id', $().string())
+ .have('place', $().string())
+ .have('data', $().object())).$;
+ if (homeErr) return rej('invalid home param');
+
+ await User.update(user._id, {
+ $set: {
+ 'client_settings.home': home
+ }
+ });
+
+ // Send response
+ res();
+});
diff --git a/src/api/private/signup.ts b/src/api/private/signup.ts
index 7a6b9c098e..e24734f80c 100644
--- a/src/api/private/signup.ts
+++ b/src/api/private/signup.ts
@@ -1,3 +1,4 @@
+import * as uuid from 'uuid';
import * as express from 'express';
import * as bcrypt from 'bcryptjs';
import recaptcha = require('recaptcha-promise');
@@ -11,6 +12,28 @@ recaptcha.init({
secret_key: config.recaptcha.secretKey
});
+const home = {
+ left: [
+ 'profile',
+ 'calendar',
+ 'activity',
+ 'rss-reader',
+ 'trends',
+ 'photo-stream',
+ 'version'
+ ],
+ right: [
+ 'broadcast',
+ 'notifications',
+ 'user-recommendation',
+ 'recommended-polls',
+ 'server',
+ 'donation',
+ 'nav',
+ 'tips'
+ ]
+};
+
export default async (req: express.Request, res: express.Response) => {
// Verify recaptcha
// ただしテスト時はこの機構は障害となるため無効にする
@@ -60,6 +83,28 @@ export default async (req: express.Request, res: express.Response) => {
// Generate secret
const secret = generateUserToken();
+ //#region Construct home data
+ const homeData = [];
+
+ home.left.forEach(widget => {
+ homeData.push({
+ name: widget,
+ id: uuid(),
+ place: 'left',
+ data: {}
+ });
+ });
+
+ home.right.forEach(widget => {
+ homeData.push({
+ name: widget,
+ id: uuid(),
+ place: 'right',
+ data: {}
+ });
+ });
+ //#endregion
+
// Create account
const account: IUser = await User.insert({
token: secret,
@@ -88,6 +133,11 @@ export default async (req: express.Request, res: express.Response) => {
height: null,
location: null,
weight: null
+ },
+ settings: {},
+ client_settings: {
+ home: homeData,
+ show_donation: false
}
});
diff --git a/src/api/serializers/user.ts b/src/api/serializers/user.ts
index 0d24d6cc04..3d84156606 100644
--- a/src/api/serializers/user.ts
+++ b/src/api/serializers/user.ts
@@ -35,9 +35,10 @@ export default (
let _user: any;
const fields = opts.detail ? {
- data: false
+ settings: false
} : {
- data: false,
+ settings: false,
+ client_settings: false,
profile: false,
keywords: false,
domains: false
@@ -72,7 +73,7 @@ export default (
delete _user._id;
// Remove needless properties
- delete _user.lates_post;
+ delete _user.latest_post;
// Remove private properties
delete _user.password;
@@ -86,8 +87,8 @@ export default (
// Visible via only the official client
if (!opts.includeSecrets) {
- delete _user.data;
delete _user.email;
+ delete _user.client_settings;
}
_user.avatar_url = _user.avatar_id != null