sales_tool/functions/generate_minutes/src/logics/file.ts
2025-12-05 16:01:59 +09:00

55 lines
No EOL
2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { create } from "domain";
import { dateController } from "./date";
import path, { join } from "path";
import archiver from "archiver";
import { googleDriveController } from "./googleDrive";
import fs from "fs";
export const fileController = {
createMinutesFileName: (title: string, hostName: string, jstStartsAt: Date): string => {
const dateStr = dateController.getFormattedDate(jstStartsAt, "yyyy年MM月dd日");
const fileName = `${dateStr} ${title} ${hostName}`;
return fileName;
},
extractCompanyNameFromTitle: (title: string) => {
const normalizedTitle = title.replace("【", "").replace("】", "");
const companyName = normalizedTitle.split("様")[0];
return companyName
},
createMinutesContent: (videoUrl: string, hostName: string, minutes: string): string => {
let minutesContent = `会議履歴URL${videoUrl}\n`;
minutesContent += `担当者:${hostName}\n\n`;
minutesContent += minutes;
return minutesContent;
},
createZip: async (body: any, outputPath: string, fileName: string): Promise<boolean> => {
try {
await new Promise((resolve, reject) => {
const output = fs.createWriteStream(outputPath);
const archive = archiver('zip', {
zlib: { level: 9 }
});
output.on('close', () => {
// console.log(archive.pointer() + ' total bytes');
// console.log('archiver has been finalized and the output file descriptor has closed.');
resolve(true);
});
archive.on('error', (err) => {
reject(err);
});
archive.pipe(output);
archive.append(JSON.stringify(body), { name: fileName + '.json' });
archive.finalize();
})
return true;
} catch(error) {
return false;
}
},
};