Files
pedwfrontend/pages/api/file/getbloblist.js
T

96 lines
2.5 KiB
JavaScript

/**
* @swagger
* /api/file/getbloblist:
* get:
* tags: [Azure Storage]
* summary: Phase 2
* description: Basic search documents details
* parameters:
* - name: container
* in: query
* required: true
* example: cl761h97h0008h11ycmu2qyfo
* schema:
* type: string
* - name: casefolderID
* in: query
* required: true
* example: TMP-AYJHX-SNW1H5
* schema:
* type: string
* - name: hash
* in: query
* required: true
* example: 372c59f86d62b57cc2a7981eeee7737c944d407c6a7f2ea9d85797bbfe9852c5
* schema:
* type: string
* responses:
* 200:
* description: Success
*/
import { hashAPIPath } from "../../../actions/core/hash";
import { getBlobs, getRepsFilesBlobs } from "../../../actions/azurestorage";
import { respondError, respondSuccess } from "../middleware/apiResponse";
import nextConnect from "next-connect";
import middleware from "../middleware/middleware";
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var casefolderID = req.query.casefolderID;
var checkHash = req.query.hash;
if (
typeof containerName === "undefined" ||
containerName.length === 0 ||
typeof casefolderID === "undefined" ||
casefolderID.length === 0 ||
typeof checkHash === "undefined" ||
checkHash.length === 0
) {
return respondError(res, {
status: 400,
code: "MISSING_REQUIRED_QUERY",
message: "container, casefolderID and hash are required"
});
}
var checkquerypath =
"/api/file/getbloblist?container=" +
containerName +
"&casefolderID=" +
casefolderID;
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
return respondError(res, {
status: 400,
code: "INVALID_HASH",
message: "Invalid hash"
});
}
const data =
casefolderID.split("/").length > 1
? await getRepsFilesBlobs(
containerName,
casefolderID.split("/")[0],
casefolderID.split("/")[1]
)
: await getBlobs(containerName, casefolderID);
return respondSuccess(res, { "value": [data] });
});
export const config = {
api: {
bodyParser: false
}
};
export default ApiProxy;