θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server/endpoints/api/document/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,11 @@ function apiDocumentEndpoints(app) {
try {
const { folderName } = request.params;
const result = await getDocumentsByFolder(folderName);
response.status(200).json(result);
response.status(result.code).json({
folder: result.folder,
documents: result.documents,
error: result.error,
});
} catch (e) {
console.error(e.message, e);
response.sendStatus(500).end();
Expand Down
4 changes: 2 additions & 2 deletions server/swagger/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,6 @@
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -1315,7 +1314,8 @@
}
}
}
}
},
"description": "OK"
},
"403": {
"description": "Forbidden",
Expand Down
27 changes: 23 additions & 4 deletions server/utils/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,34 @@ async function viewLocalFiles() {
return directory;
}

/**
* Gets the documents by folder name.
* @param {string} folderName - The name of the folder to get the documents from.
* @returns {Promise<{folder: string, documents: any[], code: number, error: string}>} - The documents by folder name.
*/
async function getDocumentsByFolder(folderName = "") {
if (!folderName) throw new Error("Folder name must be provided.");
if (!folderName) {
return {
folder: folderName,
documents: [],
code: 400,
error: "Folder name must be provided.",
};
}

const folderPath = path.resolve(documentsPath, normalizePath(folderName));
if (
!isWithin(documentsPath, folderPath) ||
!fs.existsSync(folderPath) ||
!fs.lstatSync(folderPath).isDirectory()
)
throw new Error(`Folder "${folderName}" does not exist.`);
) {
return {
folder: folderName,
documents: [],
code: 404,
error: `Folder "${folderName}" does not exist.`,
};
}

const documents = [];
const filenames = {};
Expand Down Expand Up @@ -136,7 +155,7 @@ async function getDocumentsByFolder(folderName = "") {
);
}

return { folder: folderName, documents };
return { folder: folderName, documents, code: 200, error: null };
}

/**
Expand Down