98 lines
2.9 KiB
JavaScript
98 lines
2.9 KiB
JavaScript
const express = require('express');
|
|
|
|
//他のファイルを取り込む
|
|
const PDFtoCSV = require('./1_PDFtoCSV.js');
|
|
const CSVtoPleasanter = require('./2_CSVtoPleasanter.js');
|
|
const DataAnalyze = require('./3_DataAnalyze.js');
|
|
|
|
// HTTPSサーバ起動
|
|
const PORT = 30398;
|
|
const ENDPOINT = '/care7analysis';
|
|
|
|
// HTTPS用証明書・秘密鍵のパス
|
|
const sslOptions = {
|
|
cert: fs.readFileSync('/etc/letsencrypt/live/neo999.next-hd.net/fullchain.pem'),
|
|
key: fs.readFileSync('/etc/letsencrypt/live/neo999.next-hd.net/privkey.pem')
|
|
};
|
|
|
|
const app = express();
|
|
app.use(express.json({ limit: '20mb' })); // 大きなファイルにも対応
|
|
app.use(cors({
|
|
origin: [
|
|
'https://neo999.next-hd.net',
|
|
'https://nextoffice.next-hd.co.jp',
|
|
], // 許可するオリジン
|
|
optionsSuccessStatus: 200
|
|
})); // CORS対応
|
|
|
|
//APIキーの設定
|
|
const API_KEY = 'pgqhLFWbDFu4Byz#4afNYX2F6Fa1&$KPjved$8%sUdTQV52caip#EpIKxYUkdd4S'; // 任意のAPIキーを設定
|
|
|
|
// POSTエンドポイント
|
|
app.post(`/${ENDPOINT}`, async (req, res) => {
|
|
try {
|
|
// APIキーの検証
|
|
const apiKey = req.headers['x-api-key'];
|
|
if (!apiKey || apiKey !== API_KEY) {
|
|
return res.status(401).json({ error: 'APIキーが不正です' });
|
|
}
|
|
|
|
const { base64, year, month } = req.body;
|
|
if (!base64 || !fileName) {
|
|
return res.status(400).json({ error: 'base64とfileNameは必須です' });
|
|
}
|
|
|
|
const csvData = await PDFtoCSV.convert(base64, year, month);
|
|
const analyzeData = await DataAnalyze.analyze(csvData);
|
|
/*
|
|
res.set({
|
|
'Content-Type': 'application/pdf',
|
|
'Content-Disposition': `attachment; filename="${path.parse(fileName).name}.pdf"`
|
|
});
|
|
*/
|
|
|
|
//res.send(pdfBuffer);
|
|
|
|
|
|
} catch (err) {
|
|
console.error('変換エラー:', err.message);
|
|
res.status(500).json({ error: err.message });
|
|
}
|
|
});
|
|
|
|
|
|
/*
|
|
try {
|
|
//PDFからCSVに変換する処理
|
|
const csvFileName = PDFtoCSV.main();
|
|
if (!csvFileName) {
|
|
console.error('PDFtoCSV.main failed to convert PDF to CSV.');
|
|
return;
|
|
}
|
|
|
|
//変換したCSVのデータを分析する処理
|
|
const dataAnalyzeResult = DataAnalyze.main();
|
|
if (!dataAnalyzeResult || dataAnalyzeResult !== 'success') {
|
|
console.error('DataAnalyze.main failed.');
|
|
return;
|
|
}
|
|
|
|
//プリザンターにCSVをアップロードする処理
|
|
const csvToPleasanterResult = CSVtoPleasanter.main();
|
|
if (!csvToPleasanterResult || csvToPleasanterResult !== 'success') {
|
|
console.error('CSVtoPleasanter.main failed.');
|
|
return;
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('An error occurred in PDFtoCSV.main:', error);
|
|
return; // エラーが発生した場合はリターン
|
|
|
|
}
|
|
*/
|
|
|
|
// HTTPSサーバーを起動
|
|
https.createServer(sslOptions, app).listen(PORT, () => {
|
|
console.log(`HTTPSサーバー起動: https://localhost:${PORT}/${ENDPOINT}`);
|
|
});
|