summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-04-07 16:26:50 +0900
committerGitHub <noreply@github.com>2018-04-07 16:26:50 +0900
commit2547891f940a2872fcfb2b33cd33d4f7a42ca7bc (patch)
tree5cba4ae9cdfd63e7e1ef74a002a7b742183e8d3c /src/server/api/endpoints
parentMerge pull request #1410 from akihikodaki/objec (diff)
parentRefactor (diff)
downloadsharkey-2547891f940a2872fcfb2b33cd33d4f7a42ca7bc.tar.gz
sharkey-2547891f940a2872fcfb2b33cd33d4f7a42ca7bc.tar.bz2
sharkey-2547891f940a2872fcfb2b33cd33d4f7a42ca7bc.zip
Merge pull request #1397 from syuilo/refactor
Refactor
Diffstat (limited to 'src/server/api/endpoints')
-rw-r--r--src/server/api/endpoints/following/create.ts11
-rw-r--r--src/server/api/endpoints/posts/create.ts88
-rw-r--r--src/server/api/endpoints/users/show.ts3
3 files changed, 16 insertions, 86 deletions
diff --git a/src/server/api/endpoints/following/create.ts b/src/server/api/endpoints/following/create.ts
index 9ccbe20171..0ccac8d83d 100644
--- a/src/server/api/endpoints/following/create.ts
+++ b/src/server/api/endpoints/following/create.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../../../models/user';
import Following from '../../../../models/following';
-import { createHttp } from '../../../../queue';
+import create from '../../../../services/following/create';
/**
* Follow a user
@@ -50,15 +50,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Create following
- const { _id } = await Following.insert({
- createdAt: new Date(),
- followerId: follower._id,
- followeeId: followee._id
- });
-
- createHttp({ type: 'follow', following: _id }).save();
+ create(follower, followee);
// Send response
res();
-
});
diff --git a/src/server/api/endpoints/posts/create.ts b/src/server/api/endpoints/posts/create.ts
index 47897626f1..003a892bc0 100644
--- a/src/server/api/endpoints/posts/create.ts
+++ b/src/server/api/endpoints/posts/create.ts
@@ -3,17 +3,12 @@
*/
import $ from 'cafy';
import deepEqual = require('deep-equal');
-import parseAcct from '../../../../acct/parse';
-import renderAcct from '../../../../acct/render';
-import config from '../../../../config';
-import html from '../../../../text/html';
-import parse from '../../../../text/parse';
-import Post, { IPost, isValidText, isValidCw } from '../../../../models/post';
-import User, { ILocalUser } from '../../../../models/user';
+import Post, { IPost, isValidText, isValidCw, pack } from '../../../../models/post';
+import { ILocalUser } from '../../../../models/user';
import Channel, { IChannel } from '../../../../models/channel';
import DriveFile from '../../../../models/drive-file';
-import create from '../../../../post/create';
-import distribute from '../../../../post/distribute';
+import create from '../../../../services/post/create';
+import { IApp } from '../../../../models/app';
/**
* Create a post
@@ -23,7 +18,7 @@ import distribute from '../../../../post/distribute';
* @param {any} app
* @return {Promise<any>}
*/
-module.exports = (params, user: ILocalUser, app) => new Promise(async (res, rej) => {
+module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
// Get 'visibility' parameter
const [visibility = 'public', visibilityErr] = $(params.visibility).optional.string().or(['public', 'unlisted', 'private', 'direct']).$;
if (visibilityErr) return rej('invalid visibility');
@@ -231,85 +226,26 @@ module.exports = (params, user: ILocalUser, app) => new Promise(async (res, rej)
}
}
- let tokens = null;
- if (text) {
- // Analyze
- tokens = parse(text);
-
- // Extract hashtags
- const hashtags = tokens
- .filter(t => t.type == 'hashtag')
- .map(t => t.hashtag);
-
- hashtags.forEach(tag => {
- if (tags.indexOf(tag) == -1) {
- tags.push(tag);
- }
- });
- }
-
- let atMentions = [];
-
- // If has text content
- if (text) {
- /*
- // Extract a hashtags
- const hashtags = tokens
- .filter(t => t.type == 'hashtag')
- .map(t => t.hashtag)
- // Drop dupulicates
- .filter((v, i, s) => s.indexOf(v) == i);
-
- // ハッシュタグをデータベースに登録
- registerHashtags(user, hashtags);
- */
- // Extract an '@' mentions
- atMentions = tokens
- .filter(t => t.type == 'mention')
- .map(renderAcct)
- // Drop dupulicates
- .filter((v, i, s) => s.indexOf(v) == i)
- // Fetch mentioned user
- // SELECT _id
- .map(mention => User.findOne(parseAcct(mention), { _id: true }));
- }
-
// 投稿を作成
- const post = await create({
+ const post = await create(user, {
createdAt: new Date(),
- channelId: channel ? channel._id : undefined,
- index: channel ? channel.index + 1 : undefined,
- mediaIds: files ? files.map(file => file._id) : [],
+ media: files,
poll: poll,
text: text,
- textHtml: tokens === null ? null : html(tokens),
+ reply,
+ repost,
cw: cw,
tags: tags,
- userId: user._id,
- appId: app ? app._id : null,
+ app: app,
viaMobile: viaMobile,
visibility,
geo
- }, reply, repost, await Promise.all(atMentions));
+ });
- const postObj = await distribute(user, post.mentions, post);
+ const postObj = await pack(post, user);
// Reponse
res({
createdPost: postObj
});
-
- // Register to search database
- if (post.text && config.elasticsearch.enable) {
- const es = require('../../../db/elasticsearch');
-
- es.index({
- index: 'misskey',
- type: 'post',
- id: post._id.toString(),
- body: {
- text: post.text
- }
- });
- }
});
diff --git a/src/server/api/endpoints/users/show.ts b/src/server/api/endpoints/users/show.ts
index 2b02799378..d272ce4639 100644
--- a/src/server/api/endpoints/users/show.ts
+++ b/src/server/api/endpoints/users/show.ts
@@ -37,7 +37,8 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
if (typeof host === 'string') {
try {
user = await resolveRemoteUser(username, host, cursorOption);
- } catch (exception) {
+ } catch (e) {
+ console.warn(`failed to resolve remote user: ${e}`);
return rej('failed to resolve remote user');
}
} else {