@opengis/fastify-table
Version:
core-plugins
27 lines (26 loc) • 968 B
JavaScript
import { HeadObjectCommand } from "@aws-sdk/client-s3";
import s3Client from "../client.js";
import config from "../../../../../../config.js";
import getPath from "../../../utils/getPath.js";
import getS3FilePath from "./utils/getS3FilePath.js";
// if not found on s3 => fs
import isFileExists from "../../../utils/isFileExists.js";
const getFileMetadata = (s3Settings) => async (fp, options = {}) => {
const filepath = getS3FilePath(fp, s3Settings);
const bucketParams = {
Bucket: s3Settings?.containerName || config.s3?.containerName || "work",
Key: filepath[0] === "/" ? filepath?.slice(1) : filepath,
};
try {
const data = await s3Client.send(new HeadObjectCommand(bucketParams));
return data;
}
catch (err) {
if (options.fallback === false) {
return false;
}
const filepath1 = getPath(fp);
return isFileExists(filepath1);
}
};
export default getFileMetadata;