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 => { 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; } }, };