Merge branch 'master' of http://git.gex.com.tw/OSAA/OmniAPI
This commit is contained in:
Binary file not shown.
Generated
+8
@@ -10,6 +10,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"express": "^5.2.1",
|
"express": "^5.2.1",
|
||||||
"helmet": "^8.1.0",
|
"helmet": "^8.1.0",
|
||||||
@@ -408,6 +409,13 @@
|
|||||||
"node": ">=12.0.0"
|
"node": ">=12.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/crypto": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==",
|
||||||
|
"deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in.",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.4.3",
|
"version": "4.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"express": "^5.2.1",
|
"express": "^5.2.1",
|
||||||
"helmet": "^8.1.0",
|
"helmet": "^8.1.0",
|
||||||
|
|||||||
@@ -64,7 +64,12 @@ app.post(ormRoutes, async (req, res, next) => {
|
|||||||
|
|
||||||
app.post('/upload/:dbname/:typeid', upload.single('file'), (req, res) => {
|
app.post('/upload/:dbname/:typeid', upload.single('file'), (req, res) => {
|
||||||
if (!req.file) return res.status(400).json({ status: 400, msg: 'No file' });
|
if (!req.file) return res.status(400).json({ status: 400, msg: 'No file' });
|
||||||
const fileUrl = `/static/upload/${req.params.dbname}/${req.params.typeid}/${req.file.filename}`;
|
//const fileUrl = `/static/upload/${req.params.dbname}/${req.params.typeid}/${req.file.filename}`;
|
||||||
|
|
||||||
|
// 改為完整的 Server IP
|
||||||
|
const serverRoot = 'https://api.gex.com.tw:8033/upload';
|
||||||
|
const fileUrl = `${serverRoot}/${req.params.dbname}/${req.params.typeid}/${req.file.filename}`;
|
||||||
|
|
||||||
res.json({ status: 0, data: { value: fileUrl, url: fileUrl }, msg: 'success' });
|
res.json({ status: 0, data: { value: fileUrl, url: fileUrl }, msg: 'success' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const pool = mysql.createPool({
|
|||||||
connectionLimit: 15, // 增加併發處理能力
|
connectionLimit: 15, // 增加併發處理能力
|
||||||
queueLimit: 0,
|
queueLimit: 0,
|
||||||
multipleStatements: true,
|
multipleStatements: true,
|
||||||
|
charset: 'utf8mb4', // 確保這一行存在
|
||||||
timezone: '+08:00' // 強制時區一致
|
timezone: '+08:00' // 強制時區一致
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -246,10 +246,14 @@ class OrmService {
|
|||||||
if (spName === 'get_treedata' || spName === 'get_assignData') {
|
if (spName === 'get_treedata' || spName === 'get_assignData') {
|
||||||
finalParams = [...orderedParas, "''"];
|
finalParams = [...orderedParas, "''"];
|
||||||
}
|
}
|
||||||
// get_treedata 應傳入3個參數
|
// get_treedata 應傳入3個參數(會傳入 [_flow_level, _tag, para01, para02, para03])
|
||||||
//if (spName === 'zen_showsource') {
|
if (spName === 'zen_showsource' || spName === 'zen_updatesource') {
|
||||||
// finalParams = [...orderedParas, "''"];
|
finalParams = [body.para01, body.para02, body.para03];
|
||||||
//}
|
}
|
||||||
|
//
|
||||||
|
if (spName === 'zen_create_json_v2') {
|
||||||
|
finalParams = [body.para01, body.para02];
|
||||||
|
}
|
||||||
|
|
||||||
return finalParams;
|
return finalParams;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const crypto = require('crypto'); // 用於生成隨機字串
|
||||||
|
|
||||||
const storage = multer.diskStorage({
|
const storage = multer.diskStorage({
|
||||||
destination: (req, file, cb) => {
|
destination: (req, file, cb) => {
|
||||||
@@ -10,8 +11,45 @@ const storage = multer.diskStorage({
|
|||||||
cb(null, uploadPath);
|
cb(null, uploadPath);
|
||||||
},
|
},
|
||||||
filename: (req, file, cb) => {
|
filename: (req, file, cb) => {
|
||||||
const dateStr = new Date().toISOString().replace(/[:.]/g, '-');
|
//下行程式會自動加入日期 tag 在檔名前, 目前先取消 2026/01/10
|
||||||
cb(null, `${dateStr}-${file.originalname}`);
|
//const dateStr = new Date().toISOString().replace(/[:.]/g, '-');
|
||||||
|
//cb(null, `${dateStr}-${file.originalname}`);
|
||||||
|
|
||||||
|
// 解決中文亂碼問題:將 latin1 轉回 utf-8
|
||||||
|
//const originalName = Buffer.from(file.originalname, 'latin1').toString('utf8');
|
||||||
|
//cb(null, `${file.originalname}`);
|
||||||
|
|
||||||
|
|
||||||
|
// 1. 取得原始檔名與副檔名
|
||||||
|
const ext = path.extname(file.originalname); // 包含點,例如 .jpg
|
||||||
|
const baseName = path.basename(file.originalname, ext); // 只有主檔名
|
||||||
|
|
||||||
|
// 2. 正則表達式:判斷是否為純英數、底線、橫線
|
||||||
|
// ^[a-zA-Z0-9_-]+$ 表示從頭到尾都是英數或底線橫線
|
||||||
|
const isAlphaNumeric = /^[a-zA-Z0-9_-]+$/.test(baseName);
|
||||||
|
|
||||||
|
let finalFileName = '';
|
||||||
|
//const dateStr = new Date().toISOString().replace(/[:.]/g, '-');
|
||||||
|
const dateStr = new Date().toISOString().replace(/\D/g, '');
|
||||||
|
|
||||||
|
if (isAlphaNumeric) {
|
||||||
|
// A. 如果是純英數,保持原樣,~~加上時間戳防止重複~~
|
||||||
|
//finalFileName = `${dateStr}-${file.originalname}`;
|
||||||
|
finalFileName = `${file.originalname}`;
|
||||||
|
} else {
|
||||||
|
// B. 如果包含中文或其他字元
|
||||||
|
// 先修復 Multer 的編碼錯誤 (latin1 -> utf8)
|
||||||
|
const decodedName = Buffer.from(file.originalname, 'latin1').toString('utf8');
|
||||||
|
|
||||||
|
// 為了系統穩定,硬碟端存儲建議改用「隨機英數」防止 URL 編碼問題
|
||||||
|
const uniqueSuffix = crypto.randomBytes(4).toString('hex');
|
||||||
|
finalFileName = `${dateStr}-${uniqueSuffix}${ext}`;
|
||||||
|
|
||||||
|
// 將正確的中文名稱掛載,供 Controller 存入資料庫使用
|
||||||
|
file.decodedOriginalName = decodedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
cb(null, finalFileName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user