cloudcc-cli 1.9.7 → 1.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,14 +5,15 @@ public class SendEmail {
5
5
 
6
6
  }
7
7
 
8
- //Receive address, cc address, password address, subject, email content, text content
8
+ // Receive address, cc address, password address, subject, email content, text
9
+ // content
9
10
  public ServiceResult sendMailFromSystem(String[] toAddress, String[] ccAddress, String bccAddress, String subject,
10
11
  String content, boolean isText) {
11
12
  ServiceResult srt = new ServiceResult();
12
13
  return srt;
13
14
  }
14
15
 
15
- //Email template id, receipt address, cc address, password address, record id
16
+ // Email template id, receipt address, cc address, password address, record id
16
17
  public ServiceResult sendEmailNew(String templateId, String[] toAddress, String[] ccAddress, String bccAddress,
17
18
  String recordId) {
18
19
  ServiceResult srt = new ServiceResult();
@@ -4,6 +4,7 @@ import java.io.BufferedReader;
4
4
  import java.io.File;
5
5
  import java.io.FileReader;
6
6
  import java.io.IOException;
7
+ import java.io.InputStreamReader;
7
8
  import java.util.HashMap;
8
9
  import java.util.Map;
9
10
  import java.util.regex.Matcher;
@@ -117,9 +118,21 @@ public class Tool {
117
118
  String cachePath = new File("").getAbsolutePath() + "/.cloudcc-cache.json";
118
119
  File cacheFile = new File(cachePath);
119
120
 
121
+ // 如果缓存文件不存在,执行刷新token命令
120
122
  if (!cacheFile.exists()) {
121
- System.err.println("缓存文件不存在: " + cachePath);
122
- return null;
123
+ boolean refreshed = executeGetTokenCommand();
124
+ if (refreshed) {
125
+ // 重新检查缓存文件是否存在
126
+ if (cacheFile.exists()) {
127
+ return readCacheAfterRefresh(secretKey);
128
+ } else {
129
+ System.err.println("获取token失败");
130
+ return null;
131
+ }
132
+ } else {
133
+ System.err.println("获取token失败");
134
+ return null;
135
+ }
123
136
  }
124
137
 
125
138
  // 读取文件内容
@@ -135,15 +148,33 @@ public class Tool {
135
148
  // 使用Fastjson解析JSON内容
136
149
  JSONObject jsonObject = JSONObject.parseObject(jsonContent);
137
150
 
138
- // 检查secretKey是否存在
151
+ // 检查secretKey是否存在,如果不存在,执行刷新token命令
139
152
  if (!jsonObject.containsKey(secretKey)) {
140
- System.err.println("缓存文件中不存在该secretKey: " + secretKey);
141
- return null;
153
+ System.out.println("缓存文件中不存在该secretKey: " + secretKey + ",正在获取新的token...");
154
+ boolean refreshed = executeGetTokenCommand();
155
+ if (refreshed) {
156
+ return readCacheAfterRefresh(secretKey);
157
+ } else {
158
+ System.err.println("获取token失败");
159
+ return null;
160
+ }
142
161
  }
143
162
 
144
163
  // 获取secretKey对应的数据
145
164
  JSONObject secretKeyData = jsonObject.getJSONObject(secretKey);
146
165
 
166
+ // 检查时间戳是否过期(大于1小时)或者不存在
167
+ if (!secretKeyData.containsKey("timestamp") ||
168
+ (System.currentTimeMillis() - secretKeyData.getLongValue("timestamp") > 60 * 60 * 1000)) {
169
+ boolean refreshed = executeGetTokenCommand();
170
+ if (refreshed) {
171
+ // 重新读取缓存文件
172
+ return readCacheAfterRefresh(secretKey);
173
+ } else {
174
+ System.err.println("刷新Token失败");
175
+ }
176
+ }
177
+
147
178
  // 将JSON对象转换为Map
148
179
  Map<String, Object> resultMap = new HashMap<>();
149
180
  for (String key : secretKeyData.keySet()) {
@@ -153,6 +184,11 @@ public class Tool {
153
184
  } catch (IOException e) {
154
185
  System.err.println("读取缓存文件失败: " + e.getMessage());
155
186
  e.printStackTrace();
187
+ // 发生IO异常时,尝试获取新的token
188
+ boolean refreshed = executeGetTokenCommand();
189
+ if (refreshed) {
190
+ return readCacheAfterRefresh(secretKey);
191
+ }
156
192
  return null;
157
193
  } catch (Exception e) {
158
194
  System.err.println("解析缓存文件失败: " + e.getMessage());
@@ -161,7 +197,74 @@ public class Tool {
161
197
  }
162
198
  }
163
199
 
164
- public static void main(String[] args) {
165
- System.out.println(getConfig());
200
+ /**
201
+ * 执行命令 cc get token 刷新token
202
+ *
203
+ * @return 执行是否成功
204
+ */
205
+ private static boolean executeGetTokenCommand() {
206
+ try {
207
+ ProcessBuilder processBuilder = new ProcessBuilder("cc", "get", "token");
208
+ processBuilder.redirectErrorStream(true);
209
+ Process process = processBuilder.start();
210
+
211
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
212
+ // consume the stream if necessary
213
+ }
214
+
215
+ int exitCode = process.waitFor();
216
+ return exitCode == 0;
217
+ } catch (IOException | InterruptedException e) {
218
+ System.err.println("执行命令失败: " + e.getMessage());
219
+ e.printStackTrace();
220
+ return false;
221
+ }
222
+ }
223
+
224
+ /**
225
+ * 在刷新token后重新读取缓存文件
226
+ *
227
+ * @param secretKey 密钥
228
+ * @return 包含缓存信息的Map
229
+ */
230
+ private static Map<String, Object> readCacheAfterRefresh(String secretKey) {
231
+ try {
232
+ // 获取缓存文件路径
233
+ String cachePath = new File("").getAbsolutePath() + "/.cloudcc-cache.json";
234
+ File cacheFile = new File(cachePath);
235
+
236
+ if (!cacheFile.exists()) {
237
+ System.err.println("缓存文件不存在: " + cachePath);
238
+ return null;
239
+ }
240
+
241
+ // 读取文件内容
242
+ StringBuilder content = new StringBuilder();
243
+ try (BufferedReader reader = new BufferedReader(new FileReader(cacheFile))) {
244
+ String line;
245
+ while ((line = reader.readLine()) != null) {
246
+ content.append(line).append("\n");
247
+ }
248
+ }
249
+
250
+ String jsonContent = content.toString();
251
+ JSONObject jsonObject = JSONObject.parseObject(jsonContent);
252
+
253
+ if (!jsonObject.containsKey(secretKey)) {
254
+ System.err.println("缓存文件中不存在该secretKey: " + secretKey);
255
+ return null;
256
+ }
257
+
258
+ JSONObject secretKeyData = jsonObject.getJSONObject(secretKey);
259
+ Map<String, Object> resultMap = new HashMap<>();
260
+ for (String key : secretKeyData.keySet()) {
261
+ resultMap.put(key, secretKeyData.get(key));
262
+ }
263
+ return resultMap;
264
+ } catch (Exception e) {
265
+ System.err.println("刷新后读取缓存失败: " + e.getMessage());
266
+ e.printStackTrace();
267
+ return null;
268
+ }
166
269
  }
167
270
  }
@@ -21,6 +21,7 @@ public class TriggerInvoker {
21
21
 
22
22
  }
23
23
 
24
+ @SuppressWarnings("rawtypes")
24
25
  public ServiceResult handler(CCObject data) throws Exception {
25
26
  String objectApiName = data.getObjectApiName();
26
27
  ServiceResult sr = new ServiceResult();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudcc-cli",
3
- "version": "1.9.7",
3
+ "version": "1.9.8",
4
4
  "description": "cloudcc-cli",
5
5
  "keywords": [
6
6
  "cloudcc",
package/template/index.js CHANGED
@@ -1,6 +1,33 @@
1
1
  const fs = require("fs");
2
2
  const chalk = require("chalk")
3
3
  const path = require("path")
4
+
5
+ // 添加递归复制文件夹的函数
6
+ function copyFolderSync(source, target) {
7
+ // 确保目标文件夹存在
8
+ if (!fs.existsSync(target)) {
9
+ fs.mkdirSync(target, { recursive: true });
10
+ }
11
+
12
+ // 读取源文件夹内容
13
+ const files = fs.readdirSync(source);
14
+
15
+ // 遍历并复制每个文件/文件夹
16
+ files.forEach(file => {
17
+ const sourcePath = path.join(source, file);
18
+ const targetPath = path.join(target, file);
19
+
20
+ // 判断是文件还是文件夹
21
+ if (fs.statSync(sourcePath).isDirectory()) {
22
+ // 如果是文件夹,递归复制
23
+ copyFolderSync(sourcePath, targetPath);
24
+ } else {
25
+ // 如果是文件,直接复制
26
+ fs.copyFileSync(sourcePath, targetPath);
27
+ }
28
+ });
29
+ }
30
+
4
31
  module.exports = function (creator, options, callback) {
5
32
  const { name, description } = options;
6
33
 
@@ -15,6 +42,15 @@ module.exports = function (creator, options, callback) {
15
42
  const public = path.join(projectPath, "public");
16
43
  fs.mkdirSync(public)
17
44
 
45
+ const libPath = path.join(projectPath, "lib");
46
+ fs.mkdirSync(libPath)
47
+
48
+ const templateLibPath = path.join(__dirname, "lib");
49
+ if (fs.existsSync(templateLibPath)) {
50
+ copyFolderSync(templateLibPath, libPath);
51
+ console.log(`${chalk.grey(`Copy lib folder to ${name}/lib`)} ${chalk.green('✔ ')}`);
52
+ }
53
+
18
54
  creator.copyTpl('cloudcc-cli.configjs', path.join(projectPath, "cloudcc-cli.config.js"))
19
55
 
20
56
  creator.copyTpl('gitignore', path.join(projectPath, ".gitignore"))
@@ -45,7 +81,8 @@ module.exports = function (creator, options, callback) {
45
81
  console.log(`${chalk.grey(`Create directory: ${name}/public`)} ${chalk.green('✔ ')}`);
46
82
  console.log(`${chalk.grey(`Create file: ${name}/public/index.html`)} ${chalk.green('✔ ')}`);
47
83
 
48
- console.log(`${chalk.grey(`Create file: ${name}/src`)} ${chalk.green('✔ ')}`);
84
+ console.log(`${chalk.grey(`Create directory: ${name}/lib`)} ${chalk.green('✔ ')}`);
85
+ console.log(`${chalk.grey(`Create directory: ${name}/src`)} ${chalk.green('✔ ')}`);
49
86
  console.log(`${chalk.grey(`Create file: ${name}/src/App.vue`)} ${chalk.green('✔ ')}`);
50
87
  console.log(`${chalk.grey(`Create file: ${name}/src/main.js`)} ${chalk.green('✔ ')}`);
51
88
 
Binary file
Binary file
@@ -1,48 +0,0 @@
1
- package com.cloudcc.core;
2
-
3
- import java.util.HashMap;
4
-
5
- /**
6
- * @author T.han
7
- * @date 2023/8/17 16:18
8
- * @project CloudccNewPro
9
- * @Description //TODO
10
- */
11
- public class CCObject extends HashMap<String,Object> {
12
- public static final String OBJECT_API = "CCObjectAPI";
13
- public static final String IS_SHARED = "isShared";
14
-
15
- public CCObject() {
16
- /* compiled code */
17
-
18
- }
19
-
20
- public CCObject(String ccobj) {
21
- /* compiled code */
22
- put("CCObjectAPI", ccobj);
23
-
24
- }
25
-
26
- public CCObject(String ccobj, String isShared) {
27
- /* compiled code */
28
- put("CCObjectAPI", ccobj);
29
- put("isShared", "isShared");
30
- }
31
-
32
- public void putSumValue(String sumValueKey, String value) {
33
- /* compiled code */
34
- put("sum" + sumValueKey, value);
35
- }
36
-
37
- public Object getSumValue(String sumValueKey) {
38
- /* compiled code */
39
- return get("sum" + sumValueKey);
40
- }
41
-
42
- public String getObjectApiName() {
43
- /* compiled code */
44
- return (String)get("CCObjectAPI");
45
- }
46
-
47
-
48
- }