@ccci/micro-server 1.0.142 → 1.0.143
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +26 -0
- package/dist/utils/uploader-s3.d.ts +8 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -281726,6 +281726,32 @@ class UploaderS3 {
|
|
|
281726
281726
|
throw error;
|
|
281727
281727
|
}
|
|
281728
281728
|
}
|
|
281729
|
+
static async uploadFile(bucketName, key, fileContent, contentType) {
|
|
281730
|
+
if (!UploaderS3.client) {
|
|
281731
|
+
throw new Error("S3 client is not initialized. Call `UploaderS3.init()` first.");
|
|
281732
|
+
}
|
|
281733
|
+
try {
|
|
281734
|
+
Logger.info("Uploading file directly to S3:", { bucketName, key });
|
|
281735
|
+
const response4 = await UploaderS3.client.send(new client_s3.PutObjectCommand({
|
|
281736
|
+
Bucket: bucketName,
|
|
281737
|
+
Key: key,
|
|
281738
|
+
Body: fileContent,
|
|
281739
|
+
ContentType: contentType
|
|
281740
|
+
}));
|
|
281741
|
+
Logger.info("File uploaded successfully:", { key, response: response4 });
|
|
281742
|
+
const metadata = {
|
|
281743
|
+
Bucket: "chizmis-attachments",
|
|
281744
|
+
Key: key,
|
|
281745
|
+
Etag: response4.ETag,
|
|
281746
|
+
Location: `https://chizmis-attachments.${process.env.S3_REGION_CODE}.cdn.${process.env.S3_DOMAIN}.com/${key}`,
|
|
281747
|
+
MimeType: contentType
|
|
281748
|
+
};
|
|
281749
|
+
return metadata;
|
|
281750
|
+
} catch (error) {
|
|
281751
|
+
Logger.error(error);
|
|
281752
|
+
throw error;
|
|
281753
|
+
}
|
|
281754
|
+
}
|
|
281729
281755
|
static async deleteIncompleteUploads(bucketName) {
|
|
281730
281756
|
if (!UploaderS3.client) {
|
|
281731
281757
|
throw new Error("S3 client is not initialized. Call `UploaderS3.init()` first.");
|
|
@@ -50,6 +50,14 @@ export default class UploaderS3 {
|
|
|
50
50
|
* @param uploadId Multipart upload session ID
|
|
51
51
|
*/
|
|
52
52
|
static abortMultipartUpload(bucketName: string, key: string, uploadId: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Directly uploads a file to S3 without chunking
|
|
55
|
+
* @param bucketName S3 bucket name
|
|
56
|
+
* @param key Key for the object in S3
|
|
57
|
+
* @param fileContent The content of the file to upload
|
|
58
|
+
* @param contentType The MIME type of the file
|
|
59
|
+
*/
|
|
60
|
+
static uploadFile(bucketName: string, key: string, fileContent: Buffer | Uint8Array | Blob | string, contentType: string): Promise<AttachmentMetadataType>;
|
|
53
61
|
/**
|
|
54
62
|
* Deletes all incomplete multipart uploads in the specified bucket
|
|
55
63
|
* @param bucketName S3 bucket name
|