@xuda.io/drive_module 1.1.1212 → 1.1.1214

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.
Files changed (2) hide show
  1. package/index.js +27 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1111,22 +1111,44 @@ exports.upload_drive_file = async function (req, job_id, headers, file_obj) {
1111
1111
  type: 'file',
1112
1112
  };
1113
1113
  const check_existing_file_ret = await module.exports.check_drive_file(check_req);
1114
- debugger;
1114
+
1115
1115
  if (check_existing_file_ret.code < 0) {
1116
+ // const rename_file_name = async function (i) {
1117
+ // if (i > 1000) {
1118
+ // return { code: -1, data: 'too many retries renaming existing file' };
1119
+ // }
1120
+
1121
+ // let tmp_originalname = originalname + ` (${i})`;
1122
+
1123
+ // // check_req.file_name = tmp_originalname;
1124
+ // check_req.file_path = path.join(doc.file_path, tmp_originalname);
1125
+
1126
+ // const re_check_res = await module.exports.check_drive_file(check_req);
1127
+ // if (re_check_res.code < 0) {
1128
+ // i++;
1129
+ // return await rename_file_name(i);
1130
+ // }
1131
+ // return { code: 1, data: tmp_originalname };
1132
+ // };
1133
+
1116
1134
  const rename_file_name = async function (i) {
1117
1135
  if (i > 1000) {
1118
1136
  return { code: -1, data: 'too many retries renaming existing file' };
1119
1137
  }
1120
1138
 
1121
- let tmp_originalname = originalname + ` (${i})`;
1139
+ // Extract filename parts
1140
+ const parsed = path.parse(originalname);
1141
+ const baseName = parsed.name; // filename without extension
1142
+ const extension = parsed.ext; // .webp, .jpg, etc.
1143
+
1144
+ // Insert (i) before the extension
1145
+ let tmp_originalname = `${baseName} (${i})${extension}`;
1122
1146
 
1123
- // check_req.file_name = tmp_originalname;
1124
1147
  check_req.file_path = path.join(doc.file_path, tmp_originalname);
1125
1148
 
1126
1149
  const re_check_res = await module.exports.check_drive_file(check_req);
1127
1150
  if (re_check_res.code < 0) {
1128
- i++;
1129
- return await rename_file_name(i);
1151
+ return await rename_file_name(i + 1);
1130
1152
  }
1131
1153
  return { code: 1, data: tmp_originalname };
1132
1154
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/drive_module",
3
- "version": "1.1.1212",
3
+ "version": "1.1.1214",
4
4
  "description": "Xuda Drive Server Module",
5
5
  "main": "index.js",
6
6
  "dependencies": {