|
@@ -2,6 +2,32 @@ const fs = require('fs')
|
|
|
const path = require('path')
|
|
|
const bodyParser = require('body-parser');
|
|
|
const langDir = path.join(__dirname, '../src/lang')
|
|
|
+const oss = require('ali-oss');
|
|
|
+const OSSCONFIG = {
|
|
|
+ region: 'oss-cn-shenzhen',
|
|
|
+ //云账号AccessKey有所有API访问权限,建议遵循阿里云安全最佳实践,部署在服务端使用RAM子账号或STS,部署在客户端使用STS。
|
|
|
+ accessKeyId: 'LTAI4G6f1efh9idnE8DfA71X',
|
|
|
+ accessKeySecret: 'UQBHqXh4saRBXZeOYAIhJhnuzIcyhR',
|
|
|
+ bucket: '4dscene'
|
|
|
+}
|
|
|
+const store = oss(OSSCONFIG)
|
|
|
+var FtpDeploy = require("ftp-deploy");
|
|
|
+var ftpDeploy = new FtpDeploy();
|
|
|
+var config = {
|
|
|
+ user: "xuzhihao",
|
|
|
+ // Password optional, prompted if none given
|
|
|
+ password: "xuzhihao123",
|
|
|
+ host: "192.168.0.115",
|
|
|
+ port: 2222,
|
|
|
+ localRoot: './../common/data/',
|
|
|
+ remoteRoot: "/测试服务器-120.25.146.52/root/user/java/apache-tomcat-8.0.47/webapps/4dkankan_v2/WEB-INF/classes/web/www/newsList",
|
|
|
+ include: ["news.json", 'news-en.json'],
|
|
|
+ exclude: ["dist/**/*.map", "node_modules/**", "node_modules/**/.*", ".git/**"],
|
|
|
+ deleteRemote: false,
|
|
|
+ forcePasv: true,
|
|
|
+ sftp: true
|
|
|
+};
|
|
|
+
|
|
|
module.exports = function(app, server) {
|
|
|
app.use('/dev', bodyParser.json());
|
|
|
app.use('/dev', bodyParser.urlencoded({ extended: false }));
|
|
@@ -27,8 +53,31 @@ module.exports = function(app, server) {
|
|
|
|
|
|
app.post('/dev/news/update', async function(req, res) {
|
|
|
const data = req.body.data
|
|
|
- await fs.writeFile('./../common/data/news.js', `${JSON.stringify(data, null, 4)}`, err => {
|
|
|
- res.json({ ok: true });
|
|
|
+ const localUrl = {
|
|
|
+ zh: './../common/data/news.json',
|
|
|
+ en: './../common/data/news-en.json'
|
|
|
+ }
|
|
|
+ const ossPathMap = {
|
|
|
+ zh: 'new4dkk/news/news.json',
|
|
|
+ en: 'new4dkk/news/news-en.json'
|
|
|
+ }
|
|
|
+
|
|
|
+ await fs.writeFile(localUrl[req.body.lang], `${JSON.stringify(data, null, 4)}`, async err => {
|
|
|
+ const oss_path = ossPathMap[req.body.lang]
|
|
|
+ const OUTPUT = localUrl[req.body.lang]
|
|
|
+ ftpDeploy
|
|
|
+ .deploy(config)
|
|
|
+ .then(() => {
|
|
|
+ res.json({ ok: true });
|
|
|
+ })
|
|
|
+ .catch(err => console.log(err));
|
|
|
+ // try {
|
|
|
+ // await store.put(oss_path, OUTPUT)
|
|
|
+ // console.log('success')
|
|
|
+ // } catch (err) {
|
|
|
+ // console.log(err)
|
|
|
+ // }
|
|
|
+
|
|
|
})
|
|
|
})
|
|
|
}
|