48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
import { getToken } from "../../../actions/core/token";
|
|
import { azureHeaders } from "../../../actions/core/headers";
|
|
import { consoleLogger } from "../../../actions/core/logger";
|
|
import { hashAPIPath } from "../../../actions/core/hash";
|
|
import axios from "axios";
|
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
|
|
|
const BASE_URL = process.env.API_ROOT || `http://localhost:${port}`;
|
|
|
|
const hasValue = (value) =>
|
|
typeof value === "string" && value.trim().length > 0;
|
|
|
|
export default async function ApiProxy(req, res) {
|
|
const containerName = req.query.container;
|
|
const casefolderID = req.query.casefolderID;
|
|
|
|
if (!hasValue(containerName) || !hasValue(casefolderID)) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "MISSING_REQUIRED_QUERY",
|
|
message: "container and casefolderID are required"
|
|
});
|
|
}
|
|
|
|
const token = await getToken();
|
|
|
|
const queryUrl =
|
|
"/api/file/getbloblist?container=" +
|
|
encodeURIComponent(containerName) +
|
|
"&casefolderID=" +
|
|
encodeURIComponent(casefolderID);
|
|
|
|
try {
|
|
const { data } = await axios.get(
|
|
BASE_URL + queryUrl + hashAPIPath(queryUrl),
|
|
azureHeaders(token.access_token)
|
|
);
|
|
return respondSuccess(res, data);
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "GET_BLOB_LIST_PROXY_FAILED",
|
|
message: "Failed to fetch blob list"
|
|
});
|
|
}
|
|
}
|