mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Migrate createLinkedFile to zod
GitOrigin-RevId: 68175ddc002f1e968cd7155aa2327686772b3cc8
This commit is contained in:
@@ -37,6 +37,7 @@ import {
|
||||
} from '../Errors/Errors.js'
|
||||
import Modules from '../../infrastructure/Modules.js'
|
||||
import { plainTextResponse } from '../../infrastructure/Response.js'
|
||||
import { z, zz, validateReq } from '../../infrastructure/Validation.js'
|
||||
import ReferencesHandler from '../References/ReferencesHandler.mjs'
|
||||
import EditorRealTimeController from '../Editor/EditorRealTimeController.js'
|
||||
import { expressify } from '@overleaf/promise-utils'
|
||||
@@ -46,9 +47,22 @@ import UrlAgent from './UrlAgent.mjs'
|
||||
|
||||
let LinkedFilesController
|
||||
|
||||
const createLinkedFileSchema = z.object({
|
||||
params: z.object({
|
||||
project_id: zz.objectId(),
|
||||
}),
|
||||
body: z.object({
|
||||
name: z.string(),
|
||||
provider: z.string(),
|
||||
data: z.object({}).passthrough(),
|
||||
parent_folder_id: zz.objectId(),
|
||||
}),
|
||||
})
|
||||
|
||||
async function createLinkedFile(req, res, next) {
|
||||
const { project_id: projectId } = req.params
|
||||
const { name, provider, data, parent_folder_id: parentFolderId } = req.body
|
||||
const { params, body } = validateReq(req, createLinkedFileSchema)
|
||||
const { project_id: projectId } = params
|
||||
const { name, provider, data, parent_folder_id: parentFolderId } = body
|
||||
const userId = SessionManager.getLoggedInUserId(req.session)
|
||||
|
||||
const Agent = await LinkedFilesController._getAgent(provider)
|
||||
|
||||
@@ -3,7 +3,6 @@ import AuthenticationController from '../Authentication/AuthenticationController
|
||||
import { RateLimiter } from '../../infrastructure/RateLimiter.js'
|
||||
import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
|
||||
import LinkedFilesController from './LinkedFilesController.mjs'
|
||||
import { validate, Joi } from '../../infrastructure/Validation.js'
|
||||
|
||||
const rateLimiters = {
|
||||
createLinkedFile: new RateLimiter('create-linked-file', {
|
||||
@@ -25,12 +24,6 @@ export default {
|
||||
RateLimiterMiddleware.rateLimit(rateLimiters.createLinkedFile, {
|
||||
params: ['project_id'],
|
||||
}),
|
||||
validate({
|
||||
body: {
|
||||
name: Joi.string().required(),
|
||||
// TODO: validate the remaining properties
|
||||
},
|
||||
}),
|
||||
LinkedFilesController.createLinkedFile
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user