third part
This commit is contained in:
11
gemini.js
11
gemini.js
@@ -63,11 +63,11 @@ async function pepe(){
|
||||
console.log(response.text)
|
||||
}
|
||||
|
||||
async function shneine(){
|
||||
async function shneine(fileName, mimeType){
|
||||
const myfile = await ai.files.upload({
|
||||
file:'./pedik.ogg',
|
||||
file:`./uploads/${fileName}`,
|
||||
config:{
|
||||
mimeType:'audio/ogg',
|
||||
mimeType:mimeType,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -80,7 +80,8 @@ async function shneine(){
|
||||
})
|
||||
console.log(response.text)
|
||||
}
|
||||
//await shneine();
|
||||
|
||||
|
||||
|
||||
|
||||
async function fawatafa() {
|
||||
@@ -103,5 +104,3 @@ async function fawatafa() {
|
||||
const fileName = 'outMarat5.wav';
|
||||
await saveWaveFile(fileName, audioBuffer);
|
||||
}
|
||||
|
||||
await fawatafa();
|
||||
@@ -3,9 +3,9 @@
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon src/server.js",
|
||||
"start": "node src/server.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"dev": "nodemon src/server.js",
|
||||
"start": "node src/server.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
@@ -14,9 +14,11 @@
|
||||
"dependencies": {
|
||||
"@google/genai": "^1.38.0",
|
||||
"axios": "^1.13.2",
|
||||
"cors": "^2.8.6",
|
||||
"dotenv": "^17.2.3",
|
||||
"express": "^5.2.1",
|
||||
"jsonwebtoken": "^9.0.3",
|
||||
"multer": "^2.0.2",
|
||||
"node-telegram-bot-api": "^0.67.0",
|
||||
"pg": "^8.17.2",
|
||||
"wav": "^1.0.2"
|
||||
|
||||
86
src/routes/upload.js
Normal file
86
src/routes/upload.js
Normal file
@@ -0,0 +1,86 @@
|
||||
import { Router } from "express";
|
||||
import multer from "multer";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { authMiddleware } from "../middleware/auth.js";
|
||||
|
||||
import { GoogleGenAI, createUserContent, createPartFromUri } from "@google/genai";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
import wav from 'wav';
|
||||
import { text } from "stream/consumers";
|
||||
|
||||
async function shneine(fileName, mimeType){
|
||||
const myfile = await ai.files.upload({
|
||||
file:`./uploads/${fileName}`,
|
||||
config:{
|
||||
mimeType:mimeType,
|
||||
}
|
||||
});
|
||||
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-3-flash-preview",
|
||||
contents: createUserContent([
|
||||
createPartFromUri(myfile.uri, myfile.mimeType),
|
||||
'Нужно сделать анализ аудиофайла, краткую выжимку самого важного, вывести тезисы.'
|
||||
])
|
||||
})
|
||||
return response.text;
|
||||
}
|
||||
|
||||
|
||||
// The client gets the API key from the environment variable `GEMINI_API_KEY`.
|
||||
const ai = new GoogleGenAI({apiKey: process.env.GEMINI_KEY});
|
||||
|
||||
const router = Router();
|
||||
|
||||
// создаём папку uploads, если её нет
|
||||
const uploadDir = "uploads";
|
||||
if (!fs.existsSync(uploadDir)) {
|
||||
fs.mkdirSync(uploadDir);
|
||||
}
|
||||
|
||||
// настройка хранилища
|
||||
const storage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
cb(null, uploadDir);
|
||||
},
|
||||
filename: (req, file, cb) => {
|
||||
const uniqueName =
|
||||
Date.now() + "-" + Math.round(Math.random() * 1e9);
|
||||
|
||||
const ext = path.extname(file.originalname);
|
||||
cb(null, uniqueName + ext);
|
||||
},
|
||||
});
|
||||
|
||||
const upload = multer({
|
||||
storage,
|
||||
limits: {
|
||||
fileSize: 50 * 1024 * 1024, // 5 MB
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
// POST /upload
|
||||
router.post(
|
||||
"/",
|
||||
//authMiddleware, // 🔒 если нужен Bearer token
|
||||
upload.single("file"), // имя поля = file
|
||||
async (req, res) => {
|
||||
if (!req.file) {
|
||||
return res.status(400).json({ message: "Файл не передан" });
|
||||
}
|
||||
|
||||
const aiText = await shneine(req.file.filename, req.file.mimetype);
|
||||
|
||||
res.json({
|
||||
message: "Файл загружен",
|
||||
text: aiText,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
import express from "express";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
import cors from 'cors'
|
||||
|
||||
import authRoutes from "./routes/auth.js";
|
||||
import userRoutes from "./routes/user.js";
|
||||
import uploadRoutes from "./routes/upload.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
app.use(cors());
|
||||
|
||||
app.use("/auth", authRoutes);
|
||||
app.use("/user", userRoutes);
|
||||
app.use("/upload", uploadRoutes);
|
||||
|
||||
|
||||
app.get("/health", (req, res) => {
|
||||
res.json({ status: "ok" });
|
||||
});
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => {
|
||||
const HOST = "0.0.0.0"
|
||||
app.listen(PORT,"0.0.0.0", () => {
|
||||
console.log(`🚀 Server started on http://localhost:${PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user