python -> node.js

This commit is contained in:
kosukesuenaga 2025-12-05 14:12:11 +09:00
parent 092f2ec0f3
commit 395fba645d
62 changed files with 726 additions and 1702 deletions

View file

@ -1,28 +1,56 @@
import express from "express";
import zlib from "zlib";
import { storageController } from "./logics/storage";
import { MiiTelWebhookSchema, processRequest } from "./logics/process";
import { hubspotController } from "./logics/hubspot";
import { createCustomError } from "./logics/error";
import { CLOUD_STORAGE_LOG_FOLDER_NAME, CLOUD_STORAGE_MASTER_FOLDER_NAME, COMPANIES_FILE_NAME, OWNERS_FILE_NAME } from "../serverConfig";
const router = express.Router();
router.get("/hello", (req, res) => res.send("こんにちは!"));
// Process Request From Miitel Webhook
router.post("/miitel", async (req, res) => {
try {
const body = req.body;
const parsedBody = MiiTelWebhookSchema.safeParse(body);
if (!parsedBody.success) throw createCustomError("ZOD_FAILED");
router.post("/miitel", async(req, res) => {
const body = req.body;
// await storageController.saveToGCS("request_log",'test', JSON.stringify(req.body));
const videoInfo = parsedBody.data.video;
const gzipped = zlib.gzipSync(JSON.stringify(body));
await storageController.saveToGCS(CLOUD_STORAGE_LOG_FOLDER_NAME, `${videoInfo.id}.json.gz`, gzipped, 'application/gzip');
const parsedBody = MiiTelWebhookSchema.safeParse(body);
if(!parsedBody.success) {
console.error("Invalid webhook body:", parsedBody.error);
return;
await processRequest(videoInfo);
res.status(200).send("ok");
} catch(err) {
res.status(400).send("Invalid webhook body");
}
console.log("miitel webhook received:", parsedBody.data.video.id);
await processRequest(parsedBody.data.video);
res.send("こんにちは!");
});
router.post("/getLog", async(req, res) => {
// Update Master Data And Check Google Drive Folder
router.post("/dailyBatch", async (req, res) => {
try {
console.log("Starting daily batch process...");
// export companies to GCS
const companies = await hubspotController.getCompanies();
if(!companies) throw createCustomError("GET_OWNERS_FAILED");
await storageController.saveToGCS(CLOUD_STORAGE_MASTER_FOLDER_NAME, COMPANIES_FILE_NAME, JSON.stringify(companies), 'application/json');
// export owners to GCS
const owners = await hubspotController.getOwners();
if(!owners) throw createCustomError("GET_COMPANIES_FAILED");
await storageController.saveToGCS(CLOUD_STORAGE_MASTER_FOLDER_NAME, OWNERS_FILE_NAME, JSON.stringify(owners), 'application/json');
// check folders in Google Drive
res.status(200).send("Daily batch executed.");
} catch (error) {
console.error("Error in daily batch:", error);
}
});
// Check Log By Meeting ID
router.post("/getLog", async (req, res) => {
console.log(req.body);
const meetingId = req.body.meetingId;
const exist = await storageController.existsInGCS("request_log", "test.json.gz");
@ -32,4 +60,33 @@ router.post("/getLog", async(req, res) => {
res.send(log);
});
// router.post("/deleteFile", async (req, res) => {
// console.log(req.body);
// const fileId = req.body.fileId;
// const googleAuth = await googleDriveController.getAuth();
// const driveClilent = googleDriveController.getDriveClient(googleAuth);
// await googleDriveController.deleteFile(driveClilent, fileId);
// res.send('ok');
// });
// router.post("/test", async (req, res) => {
// try {
// const googleAuth = await googleDriveController.getAuth();
// const driveClilent = googleDriveController.getDriveClient(googleAuth);
// const sheetsClient = googleDriveController.getSheetsClient(googleAuth);
// const folderId = await googleDriveController.searchFileIdByFileName(driveClilent, MINUTES_CREATION_HISTORY_FOLDER_ID, '2025');
// if(!folderId) throw new Error()
// // console.log(fileId);
// // const sheetId = await googleDriveController.getLogSheetId(driveClilent, sheetsClient, folderId, 'test1');
// // console.log('sheet id : ', sheetId);
// res.send("ok");
// } catch (error) {
// console.error("Error in /test endpoint:", error);
// res.status(500).send("Error in /test endpoint");
// }
// });
export default router;