linting & show descriptive error for bad addtoWorkspace request body
resolves #5172
This commit is contained in:
parent
bc58939843
commit
dc0bdf112b
@ -131,7 +131,9 @@ class ConfluencePagesLoader {
|
|||||||
/\n{3,}/g,
|
/\n{3,}/g,
|
||||||
"\n\n"
|
"\n\n"
|
||||||
);
|
);
|
||||||
const pageUrl = `${this.baseUrl}${this.cloud ? "/wiki" : ""}/spaces/${this.spaceKey}/pages/${page.id}`;
|
const pageUrl = `${this.baseUrl}${this.cloud ? "/wiki" : ""}/spaces/${
|
||||||
|
this.spaceKey
|
||||||
|
}/pages/${page.id}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageContent: textWithPreservedStructure,
|
pageContent: textWithPreservedStructure,
|
||||||
|
|||||||
@ -20,12 +20,34 @@ const documentsPath =
|
|||||||
? path.resolve(__dirname, "../../../storage/documents")
|
? path.resolve(__dirname, "../../../storage/documents")
|
||||||
: path.resolve(process.env.STORAGE_DIR, `documents`);
|
: path.resolve(process.env.STORAGE_DIR, `documents`);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs a simple validation check on the addToWorkspaces query parameter to ensure it is a string of comma-separated workspace slugs.
|
||||||
|
* @param {*} request
|
||||||
|
* @param {*} response
|
||||||
|
* @param {*} next
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function validateWorkspaceSlugQuery(request, response, next) {
|
||||||
|
const { addToWorkspaces = "" } = reqBody(request);
|
||||||
|
if (!addToWorkspaces) return next();
|
||||||
|
if (typeof addToWorkspaces !== "string") {
|
||||||
|
return response
|
||||||
|
.status(422)
|
||||||
|
.json({
|
||||||
|
success: false,
|
||||||
|
error: `addToWorkspaces must be a string of comma-separated workspace slugs. Got ${typeof addToWorkspaces}`,
|
||||||
|
})
|
||||||
|
.end();
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
function apiDocumentEndpoints(app) {
|
function apiDocumentEndpoints(app) {
|
||||||
if (!app) return;
|
if (!app) return;
|
||||||
|
|
||||||
app.post(
|
app.post(
|
||||||
"/v1/document/upload",
|
"/v1/document/upload",
|
||||||
[validApiKey, handleAPIFileUpload],
|
[validApiKey, handleAPIFileUpload, validateWorkspaceSlugQuery],
|
||||||
async (request, response) => {
|
async (request, response) => {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['Documents']
|
#swagger.tags = ['Documents']
|
||||||
@ -150,7 +172,7 @@ function apiDocumentEndpoints(app) {
|
|||||||
|
|
||||||
app.post(
|
app.post(
|
||||||
"/v1/document/upload/:folderName",
|
"/v1/document/upload/:folderName",
|
||||||
[validApiKey, handleAPIFileUpload],
|
[validApiKey, handleAPIFileUpload, validateWorkspaceSlugQuery],
|
||||||
async (request, response) => {
|
async (request, response) => {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['Documents']
|
#swagger.tags = ['Documents']
|
||||||
@ -331,7 +353,7 @@ function apiDocumentEndpoints(app) {
|
|||||||
|
|
||||||
app.post(
|
app.post(
|
||||||
"/v1/document/upload-link",
|
"/v1/document/upload-link",
|
||||||
[validApiKey],
|
[validApiKey, validateWorkspaceSlugQuery],
|
||||||
async (request, response) => {
|
async (request, response) => {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['Documents']
|
#swagger.tags = ['Documents']
|
||||||
@ -455,7 +477,7 @@ function apiDocumentEndpoints(app) {
|
|||||||
|
|
||||||
app.post(
|
app.post(
|
||||||
"/v1/document/raw-text",
|
"/v1/document/raw-text",
|
||||||
[validApiKey],
|
[validApiKey, validateWorkspaceSlugQuery],
|
||||||
async (request, response) => {
|
async (request, response) => {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['Documents']
|
#swagger.tags = ['Documents']
|
||||||
|
|||||||
@ -890,6 +890,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"422": {
|
||||||
|
"description": "Unprocessable Entity"
|
||||||
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error"
|
"description": "Internal Server Error"
|
||||||
}
|
}
|
||||||
@ -994,6 +997,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"422": {
|
||||||
|
"description": "Unprocessable Entity"
|
||||||
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"content": {
|
"content": {
|
||||||
@ -1099,6 +1105,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"422": {
|
||||||
|
"description": "Unprocessable Entity"
|
||||||
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error"
|
"description": "Internal Server Error"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user