pangea-server 3.3.141 → 3.3.142
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.
|
@@ -3,5 +3,8 @@ type File = {
|
|
|
3
3
|
mimetype: string;
|
|
4
4
|
};
|
|
5
5
|
type Part = string | File;
|
|
6
|
-
export declare
|
|
6
|
+
export declare abstract class Gemini {
|
|
7
|
+
static GenerateText(content: string | Part[]): Promise<string | undefined>;
|
|
8
|
+
private static __GetAi;
|
|
9
|
+
}
|
|
7
10
|
export {};
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Gemini = void 0;
|
|
4
4
|
// helpers
|
|
5
5
|
const helpers_1 = require("../helpers");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const MODEL = 'gemini-2.5-flash-lite';
|
|
7
|
+
class Gemini {
|
|
8
|
+
static async GenerateText(content) {
|
|
9
|
+
const ai = await this.__GetAi();
|
|
10
|
+
const contents = typeof content === 'string'
|
|
11
|
+
? content
|
|
12
|
+
: await Promise.all(content.map(async (part) => {
|
|
13
|
+
if (typeof part === 'string')
|
|
14
|
+
return { text: part };
|
|
15
|
+
const blob = new Blob([new Uint8Array(part.buffer)], { type: part.mimetype });
|
|
16
|
+
const uploadedFile = await ai.files.upload({ file: blob });
|
|
17
|
+
return { fileData: { fileUri: uploadedFile.uri, mimeType: part.mimetype } };
|
|
18
|
+
}));
|
|
19
|
+
const response = await ai.models.generateContent({ model: MODEL, contents });
|
|
20
|
+
return response.text;
|
|
21
|
+
}
|
|
22
|
+
static async __GetAi() {
|
|
23
|
+
const { GoogleGenAI } = await import('@google/genai');
|
|
24
|
+
return new GoogleGenAI({ apiKey: (0, helpers_1.getEnvStr)('GEMINI_API_KEY') });
|
|
25
|
+
}
|
|
20
26
|
}
|
|
27
|
+
exports.Gemini = Gemini;
|
|
@@ -10,16 +10,16 @@ const env_helpers_1 = require("./env.helpers");
|
|
|
10
10
|
const COST = 12;
|
|
11
11
|
class Pass {
|
|
12
12
|
static Hash(password) {
|
|
13
|
-
return bcrypt_1.default.hash(
|
|
13
|
+
return bcrypt_1.default.hash(sign(password), COST);
|
|
14
14
|
}
|
|
15
15
|
static async Compare(password, hash) {
|
|
16
|
-
if (await bcrypt_1.default.compare(
|
|
16
|
+
if (await bcrypt_1.default.compare(sign(password), hash))
|
|
17
17
|
return true;
|
|
18
18
|
return bcrypt_1.default.compare(password, hash);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.Pass = Pass;
|
|
22
22
|
// internal functions
|
|
23
|
-
function
|
|
23
|
+
function sign(password) {
|
|
24
24
|
return crypto_1.default.createHmac('sha256', (0, env_helpers_1.getEnvStr)('PASSWORD_SECRET')).update(password).digest('hex');
|
|
25
25
|
}
|