|
@@ -0,0 +1,59 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+const fs = require('fs');
|
|
|
+const path = require('path');
|
|
|
+var util = require('util');
|
|
|
+const oss = require('ali-oss');
|
|
|
+const config = process.argv.splice(2)[0];
|
|
|
+if (['local', 'uat', 'default'].indexOf(config) < 0) throw `参数错误: ${config}`;
|
|
|
+const options = require(`../config/config.${config}`)({ baseDir: __dirname + '/app', root: __dirname, name: 'calc' });
|
|
|
+
|
|
|
+const ossOption = {
|
|
|
+ bucket: options.oss.clients.his.bucket,
|
|
|
+ accessKeyId: options.oss.default.accessKeyId,
|
|
|
+ accessKeySecret: options.oss.default.accessKeySecret,
|
|
|
+ endpoint: options.oss.default.endpoint,
|
|
|
+ timeout: options.oss.default.timeout,
|
|
|
+};
|
|
|
+const ossClient = new oss(ossOption);
|
|
|
+
|
|
|
+var logPath = path.join(__dirname, 'update_revise.log');
|
|
|
+var logFile = fs.createWriteStream(logPath, { flags: 'a' });
|
|
|
+
|
|
|
+console.log = function() {
|
|
|
+ logFile.write(util.format.apply(null, arguments) + '\n');
|
|
|
+ process.stdout.write(util.format.apply(null, arguments) + '\n');
|
|
|
+};
|
|
|
+
|
|
|
+const filepath = ['/etc/calc/files/revise', 'mnt/files/calc/revise'];
|
|
|
+// const filepath = ['/etc/calc/files/xx'];
|
|
|
+
|
|
|
+let iCount = 0;
|
|
|
+const updatePath = async function (filepath) {
|
|
|
+ console.log(`UpdatePath: ${filepath}`);
|
|
|
+ const files = fs.readdirSync(filepath);
|
|
|
+ for (const f of files) {
|
|
|
+ const stat = fs.statSync(path.join(filepath, f));
|
|
|
+ const ossPath = options.hisOssPath + 'revise/' + f;
|
|
|
+ if (stat.isFile()) await ossClient.put(ossPath, path.join(filepath, f));
|
|
|
+ console.log(`UpdateOss: ${path.join(filepath, f)} --> ${ossPath}`);
|
|
|
+ iCount++;
|
|
|
+ }
|
|
|
+ console.log('');
|
|
|
+};
|
|
|
+const updateAll = async function () {
|
|
|
+ for (const p of filepath) {
|
|
|
+ await updatePath(p);
|
|
|
+ }
|
|
|
+ console.log(`UpdateOss: ${iCount} files`);
|
|
|
+};
|
|
|
+
|
|
|
+updateAll();
|