Download spectrum/api/queries/channel/threadConnection.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 972 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/channel/threadConnection.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/queries/channel/threadConnection.js
-
curl -L -o threadConnection.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/channel/threadConnection.js
972 Bytes
| // @flow | |
| import type { GraphQLContext } from '../../'; | |
| import type { PaginationOptions } from '../../utils/paginate-arrays'; | |
| import { getThreadsByChannel } from '../../models/thread'; | |
| import { encode, decode } from '../../utils/base64'; | |
| import { canViewChannel } from '../../utils/permissions'; | |
| import type { DBChannel } from 'shared/types'; | |
| export default async ( | |
| channel: DBChannel, | |
| { first, after }: PaginationOptions, | |
| ctx: GraphQLContext | |
| ) => { | |
| const { id, isPrivate } = channel; | |
| const { loaders, user: currentUser } = ctx; | |
| if (isPrivate) { | |
| if (!(await canViewChannel(currentUser, id, loaders))) return null; | |
| } | |
| // $FlowFixMe | |
| return getThreadsByChannel(id, { | |
| first, | |
| after: after && parseInt(decode(after), 10), | |
| }).then(threads => ({ | |
| pageInfo: { | |
| hasNextPage: threads.length >= first, | |
| }, | |
| edges: threads.map(thread => ({ | |
| cursor: encode(String(thread.lastActive.getTime())), | |
| node: thread, | |
| })), | |
| })); | |
| }; | |