mirror of
https://github.com/misskey-dev/misskey
synced 2024-12-02 16:58:49 +09:00
[API] Check post dupulication
This commit is contained in:
parent
c8479d103f
commit
47269a1782
@ -30,6 +30,7 @@
|
||||
"@types/compression": "0.0.33",
|
||||
"@types/cors": "2.8.1",
|
||||
"@types/debug": "0.0.29",
|
||||
"@types/deep-equal": "1.0.0",
|
||||
"@types/elasticsearch": "5.0.13",
|
||||
"@types/escape-html": "0.0.19",
|
||||
"@types/event-stream": "3.3.31",
|
||||
@ -78,6 +79,7 @@
|
||||
"crypto": "0.0.3",
|
||||
"css-loader": "0.27.3",
|
||||
"debug": "2.6.3",
|
||||
"deep-equal": "1.0.1",
|
||||
"deepcopy": "0.6.3",
|
||||
"download": "5.0.3",
|
||||
"elasticsearch": "12.1.3",
|
||||
|
@ -2,6 +2,7 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import deepEqual = require('deep-equal');
|
||||
import parse from '../../common/text';
|
||||
import Post from '../../models/post';
|
||||
import { isValidText } from '../../models/post';
|
||||
@ -142,6 +143,20 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
return rej('text, media_ids, repost_id or poll is required');
|
||||
}
|
||||
|
||||
// 直近の投稿と重複してたらエラー
|
||||
// TODO: 直近の投稿が一日前くらいなら重複とは見なさない
|
||||
if (user.latest_post) {
|
||||
if (deepEqual({
|
||||
text: user.latest_post.text,
|
||||
media_ids: (user.latest_post.media_ids || []).map(id => id.toString())
|
||||
}, {
|
||||
text: text,
|
||||
media_ids: (files || []).map(file => file._id.toString())
|
||||
})) {
|
||||
return rej('duplicate');
|
||||
}
|
||||
}
|
||||
|
||||
// 投稿を作成
|
||||
const post = await Post.insert({
|
||||
created_at: new Date(),
|
||||
@ -163,6 +178,12 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
//--------------------------------
|
||||
// Post processes
|
||||
|
||||
User.update({ _id: user._id }, {
|
||||
$set: {
|
||||
latest_post: post
|
||||
}
|
||||
});
|
||||
|
||||
let mentions = [];
|
||||
|
||||
function addMention(mentionee, type) {
|
||||
|
@ -65,6 +65,9 @@ export default (
|
||||
_user.id = _user._id;
|
||||
delete _user._id;
|
||||
|
||||
// Remove needless properties
|
||||
delete _user.lates_post;
|
||||
|
||||
// Remove private properties
|
||||
delete _user.password;
|
||||
delete _user.token;
|
||||
|
Loading…
Reference in New Issue
Block a user