-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { Request, RequestHandler } from 'express'; | ||
import type { ValidationChain } from 'express-validator'; | ||
|
||
import type Crowi from '~/server/crowi'; | ||
import loggerFactory from '~/utils/logger'; | ||
|
||
import { apiV3FormValidator } from '../../../middlewares/apiv3-form-validator'; | ||
import type { ApiV3Response } from '../interfaces/apiv3-response'; | ||
|
||
|
||
const logger = loggerFactory('growi:routes:apiv3:openai:chat'); | ||
|
||
|
||
type ReqParams = { | ||
// | ||
} | ||
|
||
type Req = Request<ReqParams, ApiV3Response> | ||
|
||
type ChatHandlersFactory = (crowi: Crowi) => RequestHandler[]; | ||
|
||
export const chatHandlersFactory: ChatHandlersFactory = (crowi) => { | ||
const accessTokenParser = require('../../../middlewares/access-token-parser')(crowi); | ||
const loginRequiredStrictly = require('../../../middlewares/login-required')(crowi); | ||
|
||
// define validators for req.body | ||
const validator: ValidationChain[] = []; | ||
|
||
return [ | ||
accessTokenParser, loginRequiredStrictly, validator, apiV3FormValidator, | ||
async(req: Req, res: ApiV3Response) => { | ||
|
||
try { | ||
return res.apiv3({}); | ||
} | ||
catch (err) { | ||
logger.error(err); | ||
return res.apiv3Err(err); | ||
} | ||
}, | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import express from 'express'; | ||
|
||
import { chatHandlersFactory } from './chat'; | ||
|
||
const router = express.Router(); | ||
|
||
module.exports = (crowi) => { | ||
router.get('/chat', chatHandlersFactory(crowi)); | ||
return router; | ||
}; |