@xuda.io/drive_module 1.1.1479 → 1.1.1480
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.mjs +136 -1
- package/index_ms.mjs +24 -0
- package/index_msa.mjs +24 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -100,7 +100,11 @@ export const get_drive_files = async (req) => {
|
|
|
100
100
|
opt.selector.is_system = { $exists: false };
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
// The Starred view is flat — bookmarked items across ALL folders — so it
|
|
104
|
+
// ignores the folder path; the normal listing scopes to the current folder.
|
|
105
|
+
if (req.starred) {
|
|
106
|
+
opt.selector.starred = true;
|
|
107
|
+
} else if (file_path) {
|
|
104
108
|
opt.selector.file_path = file_path;
|
|
105
109
|
}
|
|
106
110
|
|
|
@@ -232,6 +236,7 @@ export const get_drive_files = async (req) => {
|
|
|
232
236
|
date_modified: doc.date_modified,
|
|
233
237
|
file_path: path.join(doc.file_path, doc.originalname),
|
|
234
238
|
tags: doc.tags || [],
|
|
239
|
+
starred: !!doc.starred,
|
|
235
240
|
});
|
|
236
241
|
} catch (err) {
|
|
237
242
|
console.error(err.message);
|
|
@@ -251,6 +256,7 @@ export const get_drive_files = async (req) => {
|
|
|
251
256
|
is_folder: true,
|
|
252
257
|
date_created: doc.date_created,
|
|
253
258
|
tags: doc.tags || [],
|
|
259
|
+
starred: !!doc.starred,
|
|
254
260
|
});
|
|
255
261
|
} catch (err) {
|
|
256
262
|
console.error(err.message);
|
|
@@ -1001,6 +1007,121 @@ export const update_drive_file_sharing_mode = async (req, job_id, headers) => {
|
|
|
1001
1007
|
}
|
|
1002
1008
|
};
|
|
1003
1009
|
|
|
1010
|
+
// Toggle a file/folder's `starred` flag — a per-owner bookmark within the
|
|
1011
|
+
// account's own drive DB (mirrors update_drive_file_sharing_mode). The Starred
|
|
1012
|
+
// view is get_drive_files with `starred: true`.
|
|
1013
|
+
export const star_drive_file = async (req, job_id, headers) => {
|
|
1014
|
+
try {
|
|
1015
|
+
const { type, drive_type, uid, app_id, file_path, starred } = req;
|
|
1016
|
+
|
|
1017
|
+
validate_drive_type(drive_type);
|
|
1018
|
+
|
|
1019
|
+
let doc = await get_drive_doc(type, drive_type, app_id, uid, file_path, headers);
|
|
1020
|
+
|
|
1021
|
+
doc.ts = Date.now();
|
|
1022
|
+
doc.starred = !!starred;
|
|
1023
|
+
|
|
1024
|
+
return await save_drive_doc(drive_type, uid, app_id, doc);
|
|
1025
|
+
} catch (err) {
|
|
1026
|
+
return err.message;
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
// Drive items shared *with* the current user. Drive shares are auto-accepted
|
|
1031
|
+
// team_request docs (access_type 'user_drive', stat 3) whose share_item_id is a
|
|
1032
|
+
// full path in the *sharer's* drive — so we resolve each owner's default project
|
|
1033
|
+
// and fetch the doc cross-account, returning the same {children:[]} shape as
|
|
1034
|
+
// get_drive_files so the frontend renders shared items identically.
|
|
1035
|
+
export const get_shared_with_me_files = async (req, job_id, headers) => {
|
|
1036
|
+
try {
|
|
1037
|
+
const { uid, type } = req;
|
|
1038
|
+
|
|
1039
|
+
const fmtBytes = (b = 0) =>
|
|
1040
|
+
b < 1024 ? b + ' Bytes' : b < 1048576 ? (b / 1024).toFixed(2) + ' KB' : b < 1073741824 ? (b / 1048576).toFixed(2) + ' MB' : (b / 1073741824).toFixed(2) + ' GB';
|
|
1041
|
+
|
|
1042
|
+
const ownerCard = (o = {}) => ({
|
|
1043
|
+
uid: o.uid,
|
|
1044
|
+
email: o.email,
|
|
1045
|
+
first_name: o.first_name,
|
|
1046
|
+
last_name: o.last_name,
|
|
1047
|
+
full_name: o.full_name,
|
|
1048
|
+
profile_picture: o.profile_picture,
|
|
1049
|
+
profile_avatar: o.profile_avatar,
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
const shares_ret = await db_module.find_couch_query('xuda_team', {
|
|
1053
|
+
selector: { docType: 'team_request', access_type: 'user_drive', team_req_to_uid: uid, team_req_stat: 3 },
|
|
1054
|
+
});
|
|
1055
|
+
const shares = shares_ret?.docs || [];
|
|
1056
|
+
|
|
1057
|
+
const children = [];
|
|
1058
|
+
for (const share of shares) {
|
|
1059
|
+
const from_uid = share.team_req_from_uid;
|
|
1060
|
+
const item_path = share.share_item_id;
|
|
1061
|
+
if (!from_uid || !item_path) continue;
|
|
1062
|
+
|
|
1063
|
+
// share_item_type may be absent on older shares → probe file then directory.
|
|
1064
|
+
const try_types = share.share_item_type ? [share.share_item_type] : ['file', 'directory'];
|
|
1065
|
+
let doc = null;
|
|
1066
|
+
for (const t of try_types) {
|
|
1067
|
+
try {
|
|
1068
|
+
doc = await get_drive_doc(t, 'user', null, from_uid, item_path, headers);
|
|
1069
|
+
if (doc) break;
|
|
1070
|
+
} catch (e) {}
|
|
1071
|
+
}
|
|
1072
|
+
if (!doc) continue; // sharer deleted the item
|
|
1073
|
+
if (type && doc.type !== type) continue;
|
|
1074
|
+
|
|
1075
|
+
const owner_pid = await get_account_default_project_id(from_uid);
|
|
1076
|
+
const owner = ownerCard(share.sender_account_info);
|
|
1077
|
+
|
|
1078
|
+
if (doc.type === 'file') {
|
|
1079
|
+
children.push({
|
|
1080
|
+
name: doc.originalname,
|
|
1081
|
+
sizeInBytes: doc.size,
|
|
1082
|
+
size: fmtBytes(doc.size),
|
|
1083
|
+
extension: doc?.file_ext?.substr(1),
|
|
1084
|
+
type: doc.type,
|
|
1085
|
+
access_link: `https://${process.env.XUDA_HOSTNAME}/user-drive/${owner_pid}/${doc._id}`,
|
|
1086
|
+
is_archive: doc.is_archive,
|
|
1087
|
+
public: doc.public,
|
|
1088
|
+
path: doc.file_path,
|
|
1089
|
+
date_created: doc.date_created,
|
|
1090
|
+
date_modified: doc.date_modified,
|
|
1091
|
+
file_path: path.join(doc.file_path, doc.originalname),
|
|
1092
|
+
tags: doc.tags || [],
|
|
1093
|
+
shared_by: owner,
|
|
1094
|
+
owner_uid: from_uid,
|
|
1095
|
+
share_id: share._id,
|
|
1096
|
+
});
|
|
1097
|
+
} else {
|
|
1098
|
+
children.push({
|
|
1099
|
+
name: doc.folder_name,
|
|
1100
|
+
sizeInBytes: 0,
|
|
1101
|
+
size: fmtBytes(0),
|
|
1102
|
+
type: doc.type,
|
|
1103
|
+
is_folder: true,
|
|
1104
|
+
path: doc.file_path,
|
|
1105
|
+
file_path: path.join(doc.file_path, doc.folder_name),
|
|
1106
|
+
date_created: doc.date_created,
|
|
1107
|
+
tags: doc.tags || [],
|
|
1108
|
+
shared_by: owner,
|
|
1109
|
+
owner_uid: from_uid,
|
|
1110
|
+
share_id: share._id,
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
return { code: 1, data: { path: '/', name: 'Shared with me', file_path: '/', children, sizeInBytes: 0, size: fmtBytes(0) } };
|
|
1116
|
+
} catch (err) {
|
|
1117
|
+
return { code: -1, data: err.message };
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
export const get_shared_with_me_files_user = async (req, job_id, headers) => {
|
|
1121
|
+
if (!req.uid && req.token_ret?.data?.uid) req.uid = req.token_ret.data.uid; // resolve from the authenticated session
|
|
1122
|
+
return await get_shared_with_me_files(req, job_id, headers);
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1004
1125
|
export const extract_drive_file = async (req, job_id, headers) => {
|
|
1005
1126
|
const { app_id, file_path, uid, drive_type } = req;
|
|
1006
1127
|
|
|
@@ -3133,6 +3254,20 @@ export const update_drive_file_sharing_mode_user = async (req, job_id, headers,
|
|
|
3133
3254
|
return await update_drive_file_sharing_mode(req, job_id, headers, file_obj);
|
|
3134
3255
|
};
|
|
3135
3256
|
|
|
3257
|
+
export const star_drive_file_workspace = async (req, job_id, headers, file_obj) => {
|
|
3258
|
+
req.drive_type = 'workspace';
|
|
3259
|
+
return await star_drive_file(req, job_id, headers, file_obj);
|
|
3260
|
+
};
|
|
3261
|
+
export const star_drive_file_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
|
|
3262
|
+
req.drive_type = 'studio';
|
|
3263
|
+
return await star_drive_file(req, job_id, headers, file_obj);
|
|
3264
|
+
});
|
|
3265
|
+
export const star_drive_file_user = async (req, job_id, headers, file_obj) => {
|
|
3266
|
+
req.drive_type = 'user';
|
|
3267
|
+
if (!req.uid && req.token_ret?.data?.uid) req.uid = req.token_ret.data.uid; // user-drive ops resolve the project from the authenticated uid
|
|
3268
|
+
return await star_drive_file(req, job_id, headers, file_obj);
|
|
3269
|
+
};
|
|
3270
|
+
|
|
3136
3271
|
export const delete_file_bulk_workspace = async (req, job_id, headers, file_obj) => {
|
|
3137
3272
|
req.drive_type = 'workspace';
|
|
3138
3273
|
return await delete_file_bulk(req, job_id, headers, file_obj);
|
package/index_ms.mjs
CHANGED
|
@@ -49,6 +49,18 @@ export const update_drive_file_sharing_mode = async function (...args) {
|
|
|
49
49
|
return await broker.send_to_queue("update_drive_file_sharing_mode", ...args);
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
export const star_drive_file = async function (...args) {
|
|
53
|
+
return await broker.send_to_queue("star_drive_file", ...args);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const get_shared_with_me_files = async function (...args) {
|
|
57
|
+
return await broker.send_to_queue("get_shared_with_me_files", ...args);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const get_shared_with_me_files_user = async function (...args) {
|
|
61
|
+
return await broker.send_to_queue("get_shared_with_me_files_user", ...args);
|
|
62
|
+
};
|
|
63
|
+
|
|
52
64
|
export const extract_drive_file = async function (...args) {
|
|
53
65
|
return await broker.send_to_queue("extract_drive_file", ...args);
|
|
54
66
|
};
|
|
@@ -233,6 +245,14 @@ export const update_drive_file_sharing_mode_user = async function (...args) {
|
|
|
233
245
|
return await broker.send_to_queue("update_drive_file_sharing_mode_user", ...args);
|
|
234
246
|
};
|
|
235
247
|
|
|
248
|
+
export const star_drive_file_workspace = async function (...args) {
|
|
249
|
+
return await broker.send_to_queue("star_drive_file_workspace", ...args);
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export const star_drive_file_user = async function (...args) {
|
|
253
|
+
return await broker.send_to_queue("star_drive_file_user", ...args);
|
|
254
|
+
};
|
|
255
|
+
|
|
236
256
|
export const delete_file_bulk_workspace = async function (...args) {
|
|
237
257
|
return await broker.send_to_queue("delete_file_bulk_workspace", ...args);
|
|
238
258
|
};
|
|
@@ -333,6 +353,10 @@ export const update_drive_file_sharing_mode_studio = async function (...args) {
|
|
|
333
353
|
return await broker.send_to_queue("update_drive_file_sharing_mode_studio", ...args);
|
|
334
354
|
};
|
|
335
355
|
|
|
356
|
+
export const star_drive_file_studio = async function (...args) {
|
|
357
|
+
return await broker.send_to_queue("star_drive_file_studio", ...args);
|
|
358
|
+
};
|
|
359
|
+
|
|
336
360
|
export const delete_file_bulk_studio = async function (...args) {
|
|
337
361
|
return await broker.send_to_queue("delete_file_bulk_studio", ...args);
|
|
338
362
|
};
|
package/index_msa.mjs
CHANGED
|
@@ -49,6 +49,18 @@ export const update_drive_file_sharing_mode = function (...args) {
|
|
|
49
49
|
broker.send_to_queue_async("update_drive_file_sharing_mode", ...args);
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
export const star_drive_file = function (...args) {
|
|
53
|
+
broker.send_to_queue_async("star_drive_file", ...args);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const get_shared_with_me_files = function (...args) {
|
|
57
|
+
broker.send_to_queue_async("get_shared_with_me_files", ...args);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const get_shared_with_me_files_user = function (...args) {
|
|
61
|
+
broker.send_to_queue_async("get_shared_with_me_files_user", ...args);
|
|
62
|
+
};
|
|
63
|
+
|
|
52
64
|
export const extract_drive_file = function (...args) {
|
|
53
65
|
broker.send_to_queue_async("extract_drive_file", ...args);
|
|
54
66
|
};
|
|
@@ -233,6 +245,14 @@ export const update_drive_file_sharing_mode_user = function (...args) {
|
|
|
233
245
|
broker.send_to_queue_async("update_drive_file_sharing_mode_user", ...args);
|
|
234
246
|
};
|
|
235
247
|
|
|
248
|
+
export const star_drive_file_workspace = function (...args) {
|
|
249
|
+
broker.send_to_queue_async("star_drive_file_workspace", ...args);
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export const star_drive_file_user = function (...args) {
|
|
253
|
+
broker.send_to_queue_async("star_drive_file_user", ...args);
|
|
254
|
+
};
|
|
255
|
+
|
|
236
256
|
export const delete_file_bulk_workspace = function (...args) {
|
|
237
257
|
broker.send_to_queue_async("delete_file_bulk_workspace", ...args);
|
|
238
258
|
};
|
|
@@ -333,6 +353,10 @@ export const update_drive_file_sharing_mode_studio = function (...args) {
|
|
|
333
353
|
broker.send_to_queue_async("update_drive_file_sharing_mode_studio", ...args);
|
|
334
354
|
};
|
|
335
355
|
|
|
356
|
+
export const star_drive_file_studio = function (...args) {
|
|
357
|
+
broker.send_to_queue_async("star_drive_file_studio", ...args);
|
|
358
|
+
};
|
|
359
|
+
|
|
336
360
|
export const delete_file_bulk_studio = function (...args) {
|
|
337
361
|
broker.send_to_queue_async("delete_file_bulk_studio", ...args);
|
|
338
362
|
};
|