pangea-server 3.3.5 → 3.3.7
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare function uploadImage(image: UploadableImage
|
|
2
|
-
export declare function uploadImages(images: UploadableImage[]
|
|
3
|
-
export declare function uploadVideo(file: MulterFile
|
|
4
|
-
export declare function uploadVideos(files: MulterFile[]
|
|
5
|
-
export declare function deleteFile(fileName: string
|
|
1
|
+
export declare function uploadImage(image: UploadableImage, previousImage: string | undefined, ...folders: string[]): Promise<string>;
|
|
2
|
+
export declare function uploadImages(images: UploadableImage[], ...folders: string[]): Promise<string[]>;
|
|
3
|
+
export declare function uploadVideo(file: MulterFile, previousVideo: string | undefined, ...folders: string[]): Promise<string>;
|
|
4
|
+
export declare function uploadVideos(files: MulterFile[], ...folders: string[]): Promise<string[]>;
|
|
5
|
+
export declare function deleteFile(fileName: string): Promise<void>;
|
|
6
6
|
export declare function deleteFiles(fileNames: string[]): Promise<void[]>;
|
|
@@ -24,11 +24,12 @@ const s3 = new aws_sdk_1.default.S3({
|
|
|
24
24
|
async function uploadImage(image, previousImage, ...folders) {
|
|
25
25
|
if (!image)
|
|
26
26
|
error_helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'IMAGE_NOT_SENT' });
|
|
27
|
-
|
|
27
|
+
if (previousImage)
|
|
28
|
+
await deleteFile(previousImage);
|
|
28
29
|
const imageBuffer = typeof image === 'string' ? await promises_1.default.readFile(path_1.default.join(process.cwd(), image)) : image.buffer;
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const qualityRatio = imageBuffer.length >
|
|
30
|
+
const maxSizeKb = 200;
|
|
31
|
+
const maxSizeBytes = maxSizeKb * 1024;
|
|
32
|
+
const qualityRatio = imageBuffer.length > maxSizeBytes ? maxSizeBytes / imageBuffer.length : 1;
|
|
32
33
|
const qualityMultiplier = 2;
|
|
33
34
|
const targetQuality = Math.floor(qualityRatio * 100 * qualityMultiplier);
|
|
34
35
|
const quality = Math.max(10, Math.min(100, targetQuality));
|
|
@@ -45,7 +46,8 @@ exports.uploadImages = uploadImages;
|
|
|
45
46
|
async function uploadVideo(file, previousVideo, ...folders) {
|
|
46
47
|
if (!file)
|
|
47
48
|
error_helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'VIDEO_NOT_SENT' });
|
|
48
|
-
|
|
49
|
+
if (previousVideo)
|
|
50
|
+
await deleteFile(previousVideo);
|
|
49
51
|
const stream = fs_1.default.createReadStream(file.path);
|
|
50
52
|
try {
|
|
51
53
|
return await uploadFile(stream, file.mimetype, ...folders);
|
|
@@ -62,8 +64,6 @@ function uploadVideos(files, ...folders) {
|
|
|
62
64
|
}
|
|
63
65
|
exports.uploadVideos = uploadVideos;
|
|
64
66
|
async function deleteFile(fileName) {
|
|
65
|
-
if (!fileName)
|
|
66
|
-
return;
|
|
67
67
|
await s3.deleteObject({ Bucket: bucketName, Key: fileName }).promise();
|
|
68
68
|
(0, print_helpers_1.printInfo)('file', `file deleted from ${fileName}`);
|
|
69
69
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
type File = {
|
|
3
|
+
buffer: Buffer;
|
|
4
|
+
mimetype: string;
|
|
4
5
|
};
|
|
6
|
+
type Part = string | File;
|
|
5
7
|
export declare function generateIaText(content: string | Part[]): Promise<string | undefined>;
|
|
6
8
|
export {};
|
|
@@ -8,11 +8,13 @@ async function generateIaText(content) {
|
|
|
8
8
|
const ai = new GoogleGenAI({ apiKey: (0, helpers_1.getEnvStr)('GEMINI_API_KEY') });
|
|
9
9
|
const contents = typeof content === 'string'
|
|
10
10
|
? content
|
|
11
|
-
: content.map((part) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
: await Promise.all(content.map(async (part) => {
|
|
12
|
+
if (typeof part === 'string')
|
|
13
|
+
return { text: part };
|
|
14
|
+
const blob = new Blob([new Uint8Array(part.buffer)], { type: part.mimetype });
|
|
15
|
+
const uploadedFile = await ai.files.upload({ file: blob });
|
|
16
|
+
return { fileData: { fileUri: uploadedFile.uri, mimeType: part.mimetype } };
|
|
17
|
+
}));
|
|
16
18
|
const response = await ai.models.generateContent({ model: 'gemini-2.5-flash-lite', contents });
|
|
17
19
|
return response.text;
|
|
18
20
|
}
|