'use strict';
import { S3Client, ListObjectsCommand, PutObjectCommand } from '@aws-sdk/client-s3';
import { getStringEnvSetting } from '../../../../fd-toolbox/infra/env-functions.js';
import { envSettingKeys } from '../../../common/infra/env-setting-keys.js';
import { responseMessages } from '../../../../fd-toolbox/server/web/response-messages.js';
import { getNow } from '../../../../fd-toolbox/time/date-time.js';
import { apiInternalServerError } from '../../../../fd-toolbox/server/web/errors.js';
import { remoteBlobConstants } from '../../../../base-repo/constants/remote-blob-constants.js';
import { combineEndpointPath } from '../../../../fd-toolbox/http/url/urls.js';

var __defProp=Object['defineProperty'],__name=(_0x517bbc,_0x1f3027)=>__defProp(_0x517bbc,'name',{'value':_0x1f3027,'configurable':!![]});const bucketName=getStringEnvSetting(envSettingKeys['s3CompatibleBucketName']),endpointDev=getStringEnvSetting(envSettingKeys['s3CompatibleEndpointDev']),endpoint=getStringEnvSetting(envSettingKeys['s3CompatibleEndpoint']),accessKey=getStringEnvSetting(envSettingKeys['s3CompatibleAccessKey']),secretAccessKey=getStringEnvSetting(envSettingKeys['s3CompatibleSecretAccessKey']),blobClient=new S3Client({'region':remoteBlobConstants['blobClientRegion'],...endpoint&&{'endpoint':endpoint},...accessKey&&secretAccessKey&&{'credentials':{'accessKeyId':accessKey,'secretAccessKey':secretAccessKey}}});async function getBlobs(_0x552b6c){try{const _0x56abda={'Bucket':bucketName},_0x3641b0=await blobClient['send'](new ListObjectsCommand(_0x56abda));if(!_0x3641b0['Contents'])return [];if(!endpointDev)throw apiInternalServerError('Environment\x20setting\x20'+envSettingKeys['s3CompatibleEndpointDev']+'\x20is\x20not\x20configured');let _0x6685cd=_0x3641b0['Contents']['map'](_0x2d1f15=>({'key':_0x2d1f15['Key'],'url':combineEndpointPath(endpointDev,_0x2d1f15['Key'])}));return _0x552b6c&&(_0x6685cd=_0x6685cd['filter'](_0x56f138=>_0x56f138['key']['includes'](_0x552b6c))),_0x6685cd;}catch{throw apiInternalServerError(responseMessages['internalServerError']);}}__name(getBlobs,'getBlobs');async function uploadBlob(_0x4fa0fe,_0x42a315,_0x5771c7){try{const _0x1aed98={'Bucket':bucketName,'Key':getNow()+'_'+_0x4fa0fe,'Body':Buffer['from'](_0x5771c7),'ContentType':_0x42a315};await blobClient['send'](new PutObjectCommand(_0x1aed98));const _0x45d90e=endpointDev+'/'+_0x1aed98['Key'];return _0x45d90e;}catch{throw apiInternalServerError(responseMessages['internalServerError']);}}__name(uploadBlob,'uploadBlob');

export { getBlobs, uploadBlob };
