@xuda.io/drive_module 1.1.895 → 1.1.896
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.
- package/index.js +59 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -182,6 +182,63 @@ exports.get_drive_files = async function (req) {
|
|
|
182
182
|
else return (bytes / 1073741824).toFixed(2) + " GB";
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
const process_drive_data = async function (ret, file_doc) {
|
|
186
|
+
let files = {
|
|
187
|
+
path: req.path || "/",
|
|
188
|
+
name: file_doc.data.folder_name || "/",
|
|
189
|
+
file_path: req.path || "/",
|
|
190
|
+
// size: 0,
|
|
191
|
+
sizeInBytes: 0,
|
|
192
|
+
children: [],
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
for await (let doc of ret.docs) {
|
|
196
|
+
if (doc.type === "file") {
|
|
197
|
+
try {
|
|
198
|
+
files.sizeInBytes += doc.size;
|
|
199
|
+
files.children.push({
|
|
200
|
+
name: doc.originalname,
|
|
201
|
+
sizeInBytes: doc.size,
|
|
202
|
+
size: formatBytes(doc.size),
|
|
203
|
+
extension: doc?.file_ext?.substr(1),
|
|
204
|
+
type: doc.type,
|
|
205
|
+
access_link: `https://${process.env.XUDA_HOSTNAME}/workspace-drive/${app_id}/${doc._id}`, //?gtp_token=${gtp_token}
|
|
206
|
+
is_archive: doc.is_archive,
|
|
207
|
+
public: doc.public,
|
|
208
|
+
path: doc.file_path, // "/" + doc._id,
|
|
209
|
+
date_created: doc.date_created,
|
|
210
|
+
file_path: path.join(doc.file_path, doc.originalname),
|
|
211
|
+
});
|
|
212
|
+
} catch (err) {
|
|
213
|
+
console.error(err.message);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (doc.type === "directory") {
|
|
217
|
+
try {
|
|
218
|
+
const sizeInBytes = await get_folder_size(
|
|
219
|
+
req.path,
|
|
220
|
+
drive_type,
|
|
221
|
+
app_id_reference
|
|
222
|
+
);
|
|
223
|
+
files.sizeInBytes += sizeInBytes;
|
|
224
|
+
files.children.push({
|
|
225
|
+
sizeInBytes,
|
|
226
|
+
size: formatBytes(sizeInBytes),
|
|
227
|
+
name: doc.folder_name,
|
|
228
|
+
path: "/" + doc._id,
|
|
229
|
+
file_path: "/" + doc._id,
|
|
230
|
+
type: doc.type,
|
|
231
|
+
is_folder: true,
|
|
232
|
+
date_created: doc.date_created,
|
|
233
|
+
});
|
|
234
|
+
} catch (err) {
|
|
235
|
+
console.error(err.message);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
files.size = formatBytes(files.sizeInBytes);
|
|
240
|
+
};
|
|
241
|
+
|
|
185
242
|
const get_workspace_files = async function () {
|
|
186
243
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
187
244
|
opt.selector.docType = "workspace_drive";
|
|
@@ -263,7 +320,8 @@ exports.get_drive_files = async function (req) {
|
|
|
263
320
|
}
|
|
264
321
|
}
|
|
265
322
|
files.size = formatBytes(files.sizeInBytes);
|
|
266
|
-
|
|
323
|
+
|
|
324
|
+
return { code: 1, data: await process_drive_data(ret) };
|
|
267
325
|
};
|
|
268
326
|
const get_user_files = async function () {
|
|
269
327
|
opt.selector.docType = "user_drive";
|