diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-02-26 00:39:05 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-02-26 00:39:05 +0900 |
| commit | 3ae824c3542b0e232b9847ae702956e631acb276 (patch) | |
| tree | fe6183d41238471019539c4e4c14ccde995d8222 /src/api/endpoints/posts/create.ts | |
| parent | v3886 (diff) | |
| download | sharkey-3ae824c3542b0e232b9847ae702956e631acb276.tar.gz sharkey-3ae824c3542b0e232b9847ae702956e631acb276.tar.bz2 sharkey-3ae824c3542b0e232b9847ae702956e631acb276.zip | |
:v:
Diffstat (limited to 'src/api/endpoints/posts/create.ts')
| -rw-r--r-- | src/api/endpoints/posts/create.ts | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index 0fa52221f9..075e1ac9f0 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -31,6 +31,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$; if (textErr) return rej('invalid text'); + // Get 'tags' parameter + const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$; + if (tagsErr) return rej('invalid tags'); + // Get 'media_ids' parameter const [mediaIds, mediaIdsErr] = $(params.media_ids).optional.array('id').unique().range(1, 4).$; if (mediaIdsErr) return rej('invalid media_ids'); @@ -205,6 +209,23 @@ module.exports = (params, user: IUser, 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); + } + }); + } + // 投稿を作成 const post = await Post.insert({ created_at: new Date(), @@ -215,6 +236,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { repost_id: repost ? repost._id : undefined, poll: poll, text: text, + tags: tags, user_id: user._id, app_id: app ? app._id : null, @@ -423,8 +445,6 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // If has text content if (text) { - // Analyze - const tokens = parse(text); /* // Extract a hashtags const hashtags = tokens |