diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
| commit | 0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch) | |
| tree | 40874799472fa07416f17b50a398ac33b7771905 /src/server/api/endpoints/channels | |
| parent | update deps (diff) | |
| download | sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2 sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip | |
refactoring
Resolve #7779
Diffstat (limited to 'src/server/api/endpoints/channels')
| -rw-r--r-- | src/server/api/endpoints/channels/create.ts | 68 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/featured.ts | 28 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/follow.ts | 48 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/followed.ts | 49 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/owned.ts | 49 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/pin-note.ts | 0 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/show.ts | 43 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/timeline.ts | 85 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/unfollow.ts | 45 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/update.ts | 94 |
10 files changed, 0 insertions, 509 deletions
diff --git a/src/server/api/endpoints/channels/create.ts b/src/server/api/endpoints/channels/create.ts deleted file mode 100644 index 0cedfd6c6a..0000000000 --- a/src/server/api/endpoints/channels/create.ts +++ /dev/null @@ -1,68 +0,0 @@ -import $ from 'cafy'; -import define from '../../define'; -import { ApiError } from '../../error'; -import { Channels, DriveFiles } from '@/models/index'; -import { Channel } from '@/models/entities/channel'; -import { genId } from '@/misc/gen-id'; -import { ID } from '@/misc/cafy-id'; - -export const meta = { - tags: ['channels'], - - requireCredential: true as const, - - kind: 'write:channels', - - params: { - name: { - validator: $.str.range(1, 128) - }, - - description: { - validator: $.nullable.optional.str.range(1, 2048) - }, - - bannerId: { - validator: $.nullable.optional.type(ID), - } - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Channel', - }, - - errors: { - noSuchFile: { - message: 'No such file.', - code: 'NO_SUCH_FILE', - id: 'cd1e9f3e-5a12-4ab4-96f6-5d0a2cc32050' - }, - } -}; - -export default define(meta, async (ps, user) => { - let banner = null; - if (ps.bannerId != null) { - banner = await DriveFiles.findOne({ - id: ps.bannerId, - userId: user.id - }); - - if (banner == null) { - throw new ApiError(meta.errors.noSuchFile); - } - } - - const channel = await Channels.save({ - id: genId(), - createdAt: new Date(), - userId: user.id, - name: ps.name, - description: ps.description || null, - bannerId: banner ? banner.id : null, - } as Channel); - - return await Channels.pack(channel, user); -}); diff --git a/src/server/api/endpoints/channels/featured.ts b/src/server/api/endpoints/channels/featured.ts deleted file mode 100644 index dc1f49f960..0000000000 --- a/src/server/api/endpoints/channels/featured.ts +++ /dev/null @@ -1,28 +0,0 @@ -import define from '../../define'; -import { Channels } from '@/models/index'; - -export const meta = { - tags: ['channels'], - - requireCredential: false as const, - - res: { - type: 'array' as const, - optional: false as const, nullable: false as const, - items: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Channel', - } - }, -}; - -export default define(meta, async (ps, me) => { - const query = Channels.createQueryBuilder('channel') - .where('channel.lastNotedAt IS NOT NULL') - .orderBy('channel.lastNotedAt', 'DESC'); - - const channels = await query.take(10).getMany(); - - return await Promise.all(channels.map(x => Channels.pack(x, me))); -}); diff --git a/src/server/api/endpoints/channels/follow.ts b/src/server/api/endpoints/channels/follow.ts deleted file mode 100644 index d4664e6996..0000000000 --- a/src/server/api/endpoints/channels/follow.ts +++ /dev/null @@ -1,48 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ApiError } from '../../error'; -import { Channels, ChannelFollowings } from '@/models/index'; -import { genId } from '@/misc/gen-id'; -import { publishUserEvent } from '@/services/stream'; - -export const meta = { - tags: ['channels'], - - requireCredential: true as const, - - kind: 'write:channels', - - params: { - channelId: { - validator: $.type(ID), - }, - }, - - errors: { - noSuchChannel: { - message: 'No such channel.', - code: 'NO_SUCH_CHANNEL', - id: 'c0031718-d573-4e85-928e-10039f1fbb68' - }, - } -}; - -export default define(meta, async (ps, user) => { - const channel = await Channels.findOne({ - id: ps.channelId, - }); - - if (channel == null) { - throw new ApiError(meta.errors.noSuchChannel); - } - - await ChannelFollowings.insert({ - id: genId(), - createdAt: new Date(), - followerId: user.id, - followeeId: channel.id, - }); - - publishUserEvent(user.id, 'followChannel', channel); -}); diff --git a/src/server/api/endpoints/channels/followed.ts b/src/server/api/endpoints/channels/followed.ts deleted file mode 100644 index be239a01d6..0000000000 --- a/src/server/api/endpoints/channels/followed.ts +++ /dev/null @@ -1,49 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { Channels, ChannelFollowings } from '@/models/index'; -import { makePaginationQuery } from '../../common/make-pagination-query'; - -export const meta = { - tags: ['channels', 'account'], - - requireCredential: true as const, - - kind: 'read:channels', - - params: { - sinceId: { - validator: $.optional.type(ID), - }, - - untilId: { - validator: $.optional.type(ID), - }, - - limit: { - validator: $.optional.num.range(1, 100), - default: 5 - }, - }, - - res: { - type: 'array' as const, - optional: false as const, nullable: false as const, - items: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Channel', - } - }, -}; - -export default define(meta, async (ps, me) => { - const query = makePaginationQuery(ChannelFollowings.createQueryBuilder(), ps.sinceId, ps.untilId) - .andWhere({ followerId: me.id }); - - const followings = await query - .take(ps.limit!) - .getMany(); - - return await Promise.all(followings.map(x => Channels.pack(x.followeeId, me))); -}); diff --git a/src/server/api/endpoints/channels/owned.ts b/src/server/api/endpoints/channels/owned.ts deleted file mode 100644 index 4a2e9db17b..0000000000 --- a/src/server/api/endpoints/channels/owned.ts +++ /dev/null @@ -1,49 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { Channels } from '@/models/index'; -import { makePaginationQuery } from '../../common/make-pagination-query'; - -export const meta = { - tags: ['channels', 'account'], - - requireCredential: true as const, - - kind: 'read:channels', - - params: { - sinceId: { - validator: $.optional.type(ID), - }, - - untilId: { - validator: $.optional.type(ID), - }, - - limit: { - validator: $.optional.num.range(1, 100), - default: 5 - }, - }, - - res: { - type: 'array' as const, - optional: false as const, nullable: false as const, - items: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Channel', - } - }, -}; - -export default define(meta, async (ps, me) => { - const query = makePaginationQuery(Channels.createQueryBuilder(), ps.sinceId, ps.untilId) - .andWhere({ userId: me.id }); - - const channels = await query - .take(ps.limit!) - .getMany(); - - return await Promise.all(channels.map(x => Channels.pack(x, me))); -}); diff --git a/src/server/api/endpoints/channels/pin-note.ts b/src/server/api/endpoints/channels/pin-note.ts deleted file mode 100644 index e69de29bb2..0000000000 --- a/src/server/api/endpoints/channels/pin-note.ts +++ /dev/null diff --git a/src/server/api/endpoints/channels/show.ts b/src/server/api/endpoints/channels/show.ts deleted file mode 100644 index 803ce6363d..0000000000 --- a/src/server/api/endpoints/channels/show.ts +++ /dev/null @@ -1,43 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ApiError } from '../../error'; -import { Channels } from '@/models/index'; - -export const meta = { - tags: ['channels'], - - requireCredential: false as const, - - params: { - channelId: { - validator: $.type(ID), - }, - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Channel', - }, - - errors: { - noSuchChannel: { - message: 'No such channel.', - code: 'NO_SUCH_CHANNEL', - id: '6f6c314b-7486-4897-8966-c04a66a02923' - }, - } -}; - -export default define(meta, async (ps, me) => { - const channel = await Channels.findOne({ - id: ps.channelId, - }); - - if (channel == null) { - throw new ApiError(meta.errors.noSuchChannel); - } - - return await Channels.pack(channel, me); -}); diff --git a/src/server/api/endpoints/channels/timeline.ts b/src/server/api/endpoints/channels/timeline.ts deleted file mode 100644 index 0ed057a11e..0000000000 --- a/src/server/api/endpoints/channels/timeline.ts +++ /dev/null @@ -1,85 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ApiError } from '../../error'; -import { Notes, Channels } from '@/models/index'; -import { makePaginationQuery } from '../../common/make-pagination-query'; -import { activeUsersChart } from '@/services/chart/index'; - -export const meta = { - tags: ['notes', 'channels'], - - requireCredential: false as const, - - params: { - channelId: { - validator: $.type(ID), - }, - - limit: { - validator: $.optional.num.range(1, 100), - default: 10, - }, - - sinceId: { - validator: $.optional.type(ID), - }, - - untilId: { - validator: $.optional.type(ID), - }, - - sinceDate: { - validator: $.optional.num, - }, - - untilDate: { - validator: $.optional.num, - }, - }, - - res: { - type: 'array' as const, - optional: false as const, nullable: false as const, - items: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Note', - } - }, - - errors: { - noSuchChannel: { - message: 'No such channel.', - code: 'NO_SUCH_CHANNEL', - id: '4d0eeeba-a02c-4c3c-9966-ef60d38d2e7f' - } - } -}; - -export default define(meta, async (ps, user) => { - const channel = await Channels.findOne({ - id: ps.channelId, - }); - - if (channel == null) { - throw new ApiError(meta.errors.noSuchChannel); - } - - //#region Construct query - const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate) - .andWhere('note.channelId = :channelId', { channelId: channel.id }) - .innerJoinAndSelect('note.user', 'user') - .leftJoinAndSelect('note.reply', 'reply') - .leftJoinAndSelect('note.renote', 'renote') - .leftJoinAndSelect('reply.user', 'replyUser') - .leftJoinAndSelect('renote.user', 'renoteUser') - .leftJoinAndSelect('note.channel', 'channel'); - //#endregion - - const timeline = await query.take(ps.limit!).getMany(); - - if (user) activeUsersChart.update(user); - - return await Notes.packMany(timeline, user); -}); diff --git a/src/server/api/endpoints/channels/unfollow.ts b/src/server/api/endpoints/channels/unfollow.ts deleted file mode 100644 index 700f8e93ba..0000000000 --- a/src/server/api/endpoints/channels/unfollow.ts +++ /dev/null @@ -1,45 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ApiError } from '../../error'; -import { Channels, ChannelFollowings } from '@/models/index'; -import { publishUserEvent } from '@/services/stream'; - -export const meta = { - tags: ['channels'], - - requireCredential: true as const, - - kind: 'write:channels', - - params: { - channelId: { - validator: $.type(ID), - }, - }, - - errors: { - noSuchChannel: { - message: 'No such channel.', - code: 'NO_SUCH_CHANNEL', - id: '19959ee9-0153-4c51-bbd9-a98c49dc59d6' - }, - } -}; - -export default define(meta, async (ps, user) => { - const channel = await Channels.findOne({ - id: ps.channelId, - }); - - if (channel == null) { - throw new ApiError(meta.errors.noSuchChannel); - } - - await ChannelFollowings.delete({ - followerId: user.id, - followeeId: channel.id, - }); - - publishUserEvent(user.id, 'unfollowChannel', channel); -}); diff --git a/src/server/api/endpoints/channels/update.ts b/src/server/api/endpoints/channels/update.ts deleted file mode 100644 index 9b447bd04b..0000000000 --- a/src/server/api/endpoints/channels/update.ts +++ /dev/null @@ -1,94 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ApiError } from '../../error'; -import { Channels, DriveFiles } from '@/models/index'; - -export const meta = { - tags: ['channels'], - - requireCredential: true as const, - - kind: 'write:channels', - - params: { - channelId: { - validator: $.type(ID), - }, - - name: { - validator: $.optional.str.range(1, 128) - }, - - description: { - validator: $.nullable.optional.str.range(1, 2048) - }, - - bannerId: { - validator: $.nullable.optional.type(ID), - } - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Channel', - }, - - errors: { - noSuchChannel: { - message: 'No such channel.', - code: 'NO_SUCH_CHANNEL', - id: 'f9c5467f-d492-4c3c-9a8d-a70dacc86512' - }, - - accessDenied: { - message: 'You do not have edit privilege of the channel.', - code: 'ACCESS_DENIED', - id: '1fb7cb09-d46a-4fdf-b8df-057788cce513' - }, - - noSuchFile: { - message: 'No such file.', - code: 'NO_SUCH_FILE', - id: 'e86c14a4-0da2-4032-8df3-e737a04c7f3b' - }, - } -}; - -export default define(meta, async (ps, me) => { - const channel = await Channels.findOne({ - id: ps.channelId, - }); - - if (channel == null) { - throw new ApiError(meta.errors.noSuchChannel); - } - - if (channel.userId !== me.id) { - throw new ApiError(meta.errors.accessDenied); - } - - // tslint:disable-next-line:no-unnecessary-initializer - let banner = undefined; - if (ps.bannerId != null) { - banner = await DriveFiles.findOne({ - id: ps.bannerId, - userId: me.id - }); - - if (banner == null) { - throw new ApiError(meta.errors.noSuchFile); - } - } else if (ps.bannerId === null) { - banner = null; - } - - await Channels.update(channel.id, { - ...(ps.name !== undefined ? { name: ps.name } : {}), - ...(ps.description !== undefined ? { description: ps.description } : {}), - ...(banner ? { bannerId: banner.id } : {}), - }); - - return await Channels.pack(channel.id, me); -}); |