@qaecy/cue-cli 0.0.5 → 0.0.7
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/main.js +8458 -1
- package/package.json +5 -5
- package/readme.md +21 -0
- package/cue-cli-compare.js +0 -903
- package/cue-cli-sync.js +0 -5322
package/cue-cli-compare.js
DELETED
|
@@ -1,903 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esm = (fn, res) => function __init() {
|
|
9
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
-
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
|
-
|
|
32
|
-
// libs/js/sync-tools/src/lib/helpers/worker-pool.js
|
|
33
|
-
var worker_pool_exports = {};
|
|
34
|
-
__export(worker_pool_exports, {
|
|
35
|
-
WorkerPool: () => WorkerPool
|
|
36
|
-
});
|
|
37
|
-
var Worker, os, WorkerPool;
|
|
38
|
-
var init_worker_pool = __esm({
|
|
39
|
-
"libs/js/sync-tools/src/lib/helpers/worker-pool.js"() {
|
|
40
|
-
({ Worker } = require("worker_threads"));
|
|
41
|
-
os = require("os");
|
|
42
|
-
WorkerPool = class {
|
|
43
|
-
constructor(workerPath, poolSize = os.cpus().length) {
|
|
44
|
-
this.workerPath = workerPath;
|
|
45
|
-
this.poolSize = poolSize;
|
|
46
|
-
this.workers = [];
|
|
47
|
-
this.idleWorkers = [];
|
|
48
|
-
this.queue = [];
|
|
49
|
-
for (let i = 0; i < poolSize; i++) {
|
|
50
|
-
const worker = new Worker(workerPath);
|
|
51
|
-
worker.on("message", (result) => {
|
|
52
|
-
const callback = worker._currentCallback;
|
|
53
|
-
worker._currentCallback = null;
|
|
54
|
-
this.idleWorkers.push(worker);
|
|
55
|
-
callback(result);
|
|
56
|
-
this._next();
|
|
57
|
-
});
|
|
58
|
-
worker.on("error", (err) => {
|
|
59
|
-
if (worker._currentCallback)
|
|
60
|
-
worker._currentCallback({ error: err.message });
|
|
61
|
-
this.idleWorkers.push(worker);
|
|
62
|
-
this._next();
|
|
63
|
-
});
|
|
64
|
-
this.workers.push(worker);
|
|
65
|
-
this.idleWorkers.push(worker);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
_next() {
|
|
69
|
-
if (this.queue.length > 0 && this.idleWorkers.length > 0) {
|
|
70
|
-
const { filePath, resolve, reject } = this.queue.shift();
|
|
71
|
-
const worker = this.idleWorkers.pop();
|
|
72
|
-
worker._currentCallback = (result) => {
|
|
73
|
-
if (result.error)
|
|
74
|
-
reject(new Error(result.error));
|
|
75
|
-
else
|
|
76
|
-
resolve(result.hash);
|
|
77
|
-
};
|
|
78
|
-
worker.postMessage(filePath);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
hashFile(filePath) {
|
|
82
|
-
return new Promise((resolve, reject) => {
|
|
83
|
-
this.queue.push({ filePath, resolve, reject });
|
|
84
|
-
this._next();
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
async close() {
|
|
88
|
-
await Promise.all(this.workers.map((worker) => worker.terminate()));
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// apps/desktop/cue-cli/src/variables.ts
|
|
95
|
-
var import_path = require("path");
|
|
96
|
-
var TOKEN_ENDPOINT_EMULATOR = "http://localhost:8093/token";
|
|
97
|
-
var TOKEN_ENDPOINT = "https://accessors-api-gateway-ueyeemwf2a-oa.a.run.app/token";
|
|
98
|
-
var SPARQL_ENDPOINT_EMULATOR = "http://localhost:8093/triplestore/query";
|
|
99
|
-
var SPARQL_ENDPOINT = "https://accessors-api-gateway-ueyeemwf2a-oa.a.run.app/triplestore/query";
|
|
100
|
-
var HASH_WORKER_PATH = (0, import_path.join)(__dirname, "hash-worker.js");
|
|
101
|
-
var FIREBASE_CONFIG = (useEmulator = false) => ({
|
|
102
|
-
apiKey: "AIzaSyCLhz5Wa3ZCERQZVurSt9bqupPeREALFLk",
|
|
103
|
-
appId: "1:151132927589:web:d11c64cc55bdc0f13ab88c",
|
|
104
|
-
measurementId: "G-Z0FEE58EXY",
|
|
105
|
-
useEmulator
|
|
106
|
-
});
|
|
107
|
-
var IGNORED_LOCAL = {
|
|
108
|
-
dirs: ["node_modules", ".git", ".hg", ".svn", ".DS_Store"],
|
|
109
|
-
suffix: [".tmp", ".part", ".crdownload", ".zip", ".tar", ".gz"]
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// libs/js/sync-tools/src/lib/compare-local-remote.ts
|
|
113
|
-
function compareLocalRemote(localFiles, remoteFiles) {
|
|
114
|
-
return new Promise((resolve) => {
|
|
115
|
-
const localByContentUUID = /* @__PURE__ */ new Map();
|
|
116
|
-
const localBylocationUUID = /* @__PURE__ */ new Map();
|
|
117
|
-
for (const lf of localFiles) {
|
|
118
|
-
if (!localByContentUUID.has(lf.contentUUID)) {
|
|
119
|
-
localByContentUUID.set(lf.contentUUID, []);
|
|
120
|
-
}
|
|
121
|
-
localByContentUUID.get(lf.contentUUID)?.push(lf);
|
|
122
|
-
localBylocationUUID.set(lf.locationUUID, lf);
|
|
123
|
-
}
|
|
124
|
-
const remoteByContentUUID = /* @__PURE__ */ new Map();
|
|
125
|
-
const remoteBylocationUUID = /* @__PURE__ */ new Map();
|
|
126
|
-
for (const rf of remoteFiles) {
|
|
127
|
-
if (!remoteByContentUUID.has(rf.contentUUID)) {
|
|
128
|
-
remoteByContentUUID.set(rf.contentUUID, []);
|
|
129
|
-
}
|
|
130
|
-
remoteByContentUUID.get(rf.contentUUID)?.push(rf);
|
|
131
|
-
if (rf.locationUUID) {
|
|
132
|
-
remoteBylocationUUID.set(rf.locationUUID, rf);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
const localNotOnRemote = [];
|
|
136
|
-
const localNotOnRemotePathOnly = [];
|
|
137
|
-
for (const lf of localFiles) {
|
|
138
|
-
if (!remoteByContentUUID.has(lf.contentUUID)) {
|
|
139
|
-
localNotOnRemote.push(lf);
|
|
140
|
-
} else {
|
|
141
|
-
const remoteGroup = remoteByContentUUID.get(lf.contentUUID) || [];
|
|
142
|
-
const haslocationUUID = remoteGroup.some((rf) => rf.locationUUID === lf.locationUUID);
|
|
143
|
-
if (!haslocationUUID) {
|
|
144
|
-
localNotOnRemotePathOnly.push(lf);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const remoteNotOnLocal = [];
|
|
149
|
-
const remoteNotOnLocalPathOnly = [];
|
|
150
|
-
for (const rf of remoteFiles) {
|
|
151
|
-
const localGroup = localByContentUUID.get(rf.contentUUID);
|
|
152
|
-
if (!localGroup) {
|
|
153
|
-
remoteNotOnLocal.push(rf);
|
|
154
|
-
} else {
|
|
155
|
-
const haslocationUUID = localGroup.some((lf) => lf.locationUUID === rf.locationUUID);
|
|
156
|
-
if (!haslocationUUID) {
|
|
157
|
-
remoteNotOnLocalPathOnly.push(rf);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const syncCount = localFiles.length - localNotOnRemote.length - localNotOnRemotePathOnly.length;
|
|
162
|
-
const totalCount = localFiles.length;
|
|
163
|
-
const synctPctCount = totalCount > 0 ? syncCount / totalCount : 1;
|
|
164
|
-
let syncSize = 0;
|
|
165
|
-
let totalSize = 0;
|
|
166
|
-
for (const lf of localFiles) {
|
|
167
|
-
totalSize += lf.size || 0;
|
|
168
|
-
const remoteGroup = remoteByContentUUID.get(lf.contentUUID) || [];
|
|
169
|
-
const haslocationUUID = remoteGroup.some((rf) => rf.locationUUID === lf.locationUUID);
|
|
170
|
-
if (haslocationUUID) {
|
|
171
|
-
syncSize += lf.size || 0;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const synctPctSize = totalSize > 0 ? syncSize / totalSize : 1;
|
|
175
|
-
resolve({
|
|
176
|
-
localNotOnRemote,
|
|
177
|
-
localNotOnRemotePathOnly,
|
|
178
|
-
remoteNotOnLocal,
|
|
179
|
-
remoteNotOnLocalPathOnly,
|
|
180
|
-
syncCount,
|
|
181
|
-
totalCount,
|
|
182
|
-
syncSize,
|
|
183
|
-
totalSize,
|
|
184
|
-
synctPctSize,
|
|
185
|
-
synctPctCount
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// libs/js/firebase/src/lib/firebase.ts
|
|
191
|
-
var import_functions = require("firebase/functions");
|
|
192
|
-
|
|
193
|
-
// libs/js/firebase/src/lib/variables.ts
|
|
194
|
-
var APP_ID = "qaecy-mvp-406413";
|
|
195
|
-
var GCP_REGION = "europe-west6";
|
|
196
|
-
var FUNCTION_ACCEPT_TERMS_PATH = "acceptTerms";
|
|
197
|
-
var FUNCTION_EMIT_MESSAGE_PATH = "emitMessage";
|
|
198
|
-
var FUNCTION_GET_USER_INFO_PATH = "getUserInfo";
|
|
199
|
-
var FUNCTION_CHANGE_USER_ROLE_ON_PROJECT_PATH = "changeUserRoleOnProject";
|
|
200
|
-
var FUNCTION_INVITE_USER_TO_PROJECT_PATH = "inviteUserToProject";
|
|
201
|
-
var FUNCTION_REMOVE_USER_FROM_PROJECT_PATH = "removeUserFromProject";
|
|
202
|
-
var BUCKET_CHAT_SESSIONS = "spaces_chats_eu_west6";
|
|
203
|
-
var BUCKET_RAW = "spaces_raw_eu_west6";
|
|
204
|
-
var BUCKET_PROCESSED = "spaces_processed_eu_west6";
|
|
205
|
-
var BUCKET_LOGS = "spaces_logs_eu_west6";
|
|
206
|
-
var COLLECTION_CHAT_SESSIONS = "chatSessions";
|
|
207
|
-
var COLLECTION_ORGANIZATIONS = "organizations";
|
|
208
|
-
var COLLECTION_PROJECTS = "projects";
|
|
209
|
-
var COLLECTION_RDF_WRITING = "rdfWriting";
|
|
210
|
-
var COLLECTION_API_KEYS = "apiKeys";
|
|
211
|
-
var COLLECTION_USERS = "users";
|
|
212
|
-
var COLLECTION_USER_TERMS_ACCEPT = "userTermsAcceptance";
|
|
213
|
-
var COLLECTION_TIERS = "tiers";
|
|
214
|
-
|
|
215
|
-
// libs/js/firebase/src/lib/firebase.ts
|
|
216
|
-
var import_storage = require("firebase/storage");
|
|
217
|
-
var import_firestore = require("firebase/firestore");
|
|
218
|
-
var import_auth = require("firebase/auth");
|
|
219
|
-
var import_app = require("firebase/app");
|
|
220
|
-
var CueFirebase = class _CueFirebase {
|
|
221
|
-
constructor(config, auth, muted = false) {
|
|
222
|
-
this._muted = true;
|
|
223
|
-
this._muted = muted;
|
|
224
|
-
this._init(config, auth);
|
|
225
|
-
}
|
|
226
|
-
static getInstance(config, auth, muted = false) {
|
|
227
|
-
if (!_CueFirebase._instance) {
|
|
228
|
-
if (config === void 0)
|
|
229
|
-
throw new Error("Config needed for instantiation!");
|
|
230
|
-
if (!muted)
|
|
231
|
-
console.info("Creating new CueFirebase instance");
|
|
232
|
-
_CueFirebase._instance = new _CueFirebase(config, auth, muted);
|
|
233
|
-
}
|
|
234
|
-
return _CueFirebase._instance;
|
|
235
|
-
}
|
|
236
|
-
get functionAcceptTerms() {
|
|
237
|
-
return this._functionAcceptTerms;
|
|
238
|
-
}
|
|
239
|
-
get functionEmitMessage() {
|
|
240
|
-
return this._functionEmitMessage;
|
|
241
|
-
}
|
|
242
|
-
get functionGetUserInfo() {
|
|
243
|
-
return this._functionGetUserInfo;
|
|
244
|
-
}
|
|
245
|
-
get functionInviteUserToProject() {
|
|
246
|
-
return this._functionInviteUserToProject;
|
|
247
|
-
}
|
|
248
|
-
get functionChangeUserRoleOnProject() {
|
|
249
|
-
return this._functionChangeUserRoleOnProject;
|
|
250
|
-
}
|
|
251
|
-
get functionRemoveUserFromProject() {
|
|
252
|
-
return this._functionRemoveUserFromProject;
|
|
253
|
-
}
|
|
254
|
-
get storageProcessed() {
|
|
255
|
-
return this._storageProcessed;
|
|
256
|
-
}
|
|
257
|
-
get storageRaw() {
|
|
258
|
-
return this._storageRaw;
|
|
259
|
-
}
|
|
260
|
-
get storageLogs() {
|
|
261
|
-
return this._storageLogs;
|
|
262
|
-
}
|
|
263
|
-
get storageChatSessions() {
|
|
264
|
-
return this._storageChatSessions;
|
|
265
|
-
}
|
|
266
|
-
get collectionChatSessions() {
|
|
267
|
-
return this._collectionChatSessions;
|
|
268
|
-
}
|
|
269
|
-
get collectionOrganizations() {
|
|
270
|
-
return this._collectionOrganizations;
|
|
271
|
-
}
|
|
272
|
-
get collectionProjects() {
|
|
273
|
-
return this._collectionProjects;
|
|
274
|
-
}
|
|
275
|
-
get collectionRDFWriting() {
|
|
276
|
-
return this._collectionRDFWriting;
|
|
277
|
-
}
|
|
278
|
-
get collectionAPIKeys() {
|
|
279
|
-
return this._collectionAPIKeys;
|
|
280
|
-
}
|
|
281
|
-
get collectionUsers() {
|
|
282
|
-
return this._collectionUsers;
|
|
283
|
-
}
|
|
284
|
-
get collectionUserTermsAcceptance() {
|
|
285
|
-
return this._collectionUserTermsAcceptance;
|
|
286
|
-
}
|
|
287
|
-
get collectionTiers() {
|
|
288
|
-
return this._collectionTiers;
|
|
289
|
-
}
|
|
290
|
-
get app() {
|
|
291
|
-
return this._app;
|
|
292
|
-
}
|
|
293
|
-
get auth() {
|
|
294
|
-
return this._auth;
|
|
295
|
-
}
|
|
296
|
-
_init(config, auth) {
|
|
297
|
-
const firebaseConfig = Object.assign(config, {
|
|
298
|
-
authDomain: `${APP_ID}.firebaseapp.com`,
|
|
299
|
-
projectId: APP_ID,
|
|
300
|
-
// storageBucket: BUCKET_PROCESSED,
|
|
301
|
-
messagingSenderId: "734737865998"
|
|
302
|
-
});
|
|
303
|
-
const app = (0, import_app.initializeApp)(firebaseConfig);
|
|
304
|
-
const functions = (0, import_functions.getFunctions)(app, GCP_REGION);
|
|
305
|
-
this._functionAcceptTerms = (0, import_functions.httpsCallable)(
|
|
306
|
-
functions,
|
|
307
|
-
FUNCTION_ACCEPT_TERMS_PATH
|
|
308
|
-
);
|
|
309
|
-
this._functionEmitMessage = (0, import_functions.httpsCallable)(
|
|
310
|
-
functions,
|
|
311
|
-
FUNCTION_EMIT_MESSAGE_PATH
|
|
312
|
-
);
|
|
313
|
-
this._functionGetUserInfo = (0, import_functions.httpsCallable)(
|
|
314
|
-
functions,
|
|
315
|
-
FUNCTION_GET_USER_INFO_PATH
|
|
316
|
-
);
|
|
317
|
-
this._functionChangeUserRoleOnProject = (0, import_functions.httpsCallable)(
|
|
318
|
-
functions,
|
|
319
|
-
FUNCTION_CHANGE_USER_ROLE_ON_PROJECT_PATH
|
|
320
|
-
);
|
|
321
|
-
this._functionInviteUserToProject = (0, import_functions.httpsCallable)(
|
|
322
|
-
functions,
|
|
323
|
-
FUNCTION_INVITE_USER_TO_PROJECT_PATH
|
|
324
|
-
);
|
|
325
|
-
this._functionRemoveUserFromProject = (0, import_functions.httpsCallable)(
|
|
326
|
-
functions,
|
|
327
|
-
FUNCTION_REMOVE_USER_FROM_PROJECT_PATH
|
|
328
|
-
);
|
|
329
|
-
this._storageProcessed = (0, import_storage.getStorage)(app, BUCKET_PROCESSED);
|
|
330
|
-
this._storageRaw = (0, import_storage.getStorage)(app, BUCKET_RAW);
|
|
331
|
-
this._storageChatSessions = (0, import_storage.getStorage)(app, BUCKET_CHAT_SESSIONS);
|
|
332
|
-
this._storageLogs = (0, import_storage.getStorage)(app, BUCKET_LOGS);
|
|
333
|
-
this._collectionChatSessions = (0, import_firestore.collection)(
|
|
334
|
-
(0, import_firestore.getFirestore)(app),
|
|
335
|
-
COLLECTION_CHAT_SESSIONS
|
|
336
|
-
);
|
|
337
|
-
this._collectionOrganizations = (0, import_firestore.collection)(
|
|
338
|
-
(0, import_firestore.getFirestore)(app),
|
|
339
|
-
COLLECTION_ORGANIZATIONS
|
|
340
|
-
);
|
|
341
|
-
this._collectionProjects = (0, import_firestore.collection)((0, import_firestore.getFirestore)(app), COLLECTION_PROJECTS);
|
|
342
|
-
this._collectionRDFWriting = (0, import_firestore.collection)((0, import_firestore.getFirestore)(app), COLLECTION_RDF_WRITING);
|
|
343
|
-
this._collectionAPIKeys = (0, import_firestore.collection)((0, import_firestore.getFirestore)(app), COLLECTION_API_KEYS);
|
|
344
|
-
this._collectionUsers = (0, import_firestore.collection)((0, import_firestore.getFirestore)(app), COLLECTION_USERS);
|
|
345
|
-
this._collectionUserTermsAcceptance = (0, import_firestore.collection)(
|
|
346
|
-
(0, import_firestore.getFirestore)(app),
|
|
347
|
-
COLLECTION_USER_TERMS_ACCEPT
|
|
348
|
-
);
|
|
349
|
-
this._collectionTiers = (0, import_firestore.collection)((0, import_firestore.getFirestore)(app), COLLECTION_TIERS);
|
|
350
|
-
this._auth = auth === void 0 ? (0, import_auth.getAuth)(app) : auth;
|
|
351
|
-
this._app = app;
|
|
352
|
-
if (config.useEmulator) {
|
|
353
|
-
this.attachEmulators();
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
attachEmulators() {
|
|
357
|
-
if (this._auth === void 0)
|
|
358
|
-
throw new Error("Auth is not initialized");
|
|
359
|
-
if (this._storageProcessed === void 0)
|
|
360
|
-
throw new Error("Storage processed is not initialized");
|
|
361
|
-
if (this._storageRaw === void 0)
|
|
362
|
-
throw new Error("Storage raw is not initialized");
|
|
363
|
-
if (this._storageChatSessions === void 0)
|
|
364
|
-
throw new Error("Storage chat sessions is not initialized");
|
|
365
|
-
if (this._storageLogs === void 0)
|
|
366
|
-
throw new Error("Storage logs is not initialized");
|
|
367
|
-
if (this._app === void 0)
|
|
368
|
-
throw new Error("App is not initialized");
|
|
369
|
-
const functions = (0, import_functions.getFunctions)(this._app, GCP_REGION);
|
|
370
|
-
(0, import_auth.connectAuthEmulator)(this._auth, "http://localhost:9099");
|
|
371
|
-
(0, import_firestore.connectFirestoreEmulator)((0, import_firestore.getFirestore)(this._app), "localhost", 8080);
|
|
372
|
-
(0, import_functions.connectFunctionsEmulator)(functions, "localhost", 5001);
|
|
373
|
-
(0, import_storage.connectStorageEmulator)(this._storageProcessed, "localhost", 9199);
|
|
374
|
-
(0, import_storage.connectStorageEmulator)(this._storageRaw, "localhost", 9199);
|
|
375
|
-
(0, import_storage.connectStorageEmulator)(this._storageChatSessions, "localhost", 9199);
|
|
376
|
-
(0, import_storage.connectStorageEmulator)(this._storageLogs, "localhost", 9199);
|
|
377
|
-
if (!this._muted)
|
|
378
|
-
console.info("Firebase emulators attached");
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
// libs/js/firebase/src/lib/models.ts
|
|
383
|
-
var import_uuid = require("uuid");
|
|
384
|
-
|
|
385
|
-
// libs/js/sync-tools/src/lib/list-remote-files.ts
|
|
386
|
-
var import_storage2 = require("firebase/storage");
|
|
387
|
-
|
|
388
|
-
// libs/js/prefixes/src/lib/qaecy-prefixes.ts
|
|
389
|
-
var qaecyPrefixes = {
|
|
390
|
-
qcy: "https://dev.qaecy.com/ont#",
|
|
391
|
-
"qcy-e": "https://dev.qaecy.com/enum#",
|
|
392
|
-
obc: "https://w3id.org/obc#",
|
|
393
|
-
// OpenBIM Components
|
|
394
|
-
dicc: "https://w3id.org/digitalconstruction/0.5/Contexts#",
|
|
395
|
-
dicv: "https://w3id.org/digitalconstruction/0.5/Variables#",
|
|
396
|
-
dice: "https://w3id.org/digitalconstruction/0.5/Entities#",
|
|
397
|
-
dicp: "https://w3id.org/digitalconstruction/0.5/Processes#",
|
|
398
|
-
dica: "https://w3id.org/digitalconstruction/0.5/Agents#",
|
|
399
|
-
dici: "https://w3id.org/digitalconstruction/0.5/Information#",
|
|
400
|
-
dicbm: "https://w3id.org/digitalconstruction/0.5/Materials#",
|
|
401
|
-
dicob: "https://w3id.org/digitalconstruction/0.5/Occupancy#",
|
|
402
|
-
dicl: "https://w3id.org/digitalconstruction/0.5/Lifecycle#",
|
|
403
|
-
dices: "https://w3id.org/digitalconstruction/0.5/Energy#",
|
|
404
|
-
dicu: "https://w3id.org/digitalconstruction/0.5/Units#",
|
|
405
|
-
diclvl: "https://w3id.org/digitalconstruction/0.5/Levels#",
|
|
406
|
-
dicstg: "https://w3id.org/digitalconstruction/0.5/Stages#"
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// libs/js/sync-tools/src/lib/list-remote-files.ts
|
|
410
|
-
async function listRemoteFiles(spaceId, providerId, queryHandler2, verbose = false) {
|
|
411
|
-
const firebase = CueFirebase.getInstance();
|
|
412
|
-
const storage = firebase.storageRaw;
|
|
413
|
-
if (!storage)
|
|
414
|
-
throw new Error("Firebase storage is not initialized");
|
|
415
|
-
const listRef = (0, import_storage2.ref)(storage, spaceId);
|
|
416
|
-
if (verbose)
|
|
417
|
-
console.info(`Listing files in raw space: ${spaceId}`);
|
|
418
|
-
const [blobFiles, locationDataMap] = await Promise.all([
|
|
419
|
-
(0, import_storage2.listAll)(listRef),
|
|
420
|
-
getGraphFiles(providerId, queryHandler2)
|
|
421
|
-
]);
|
|
422
|
-
const files = [];
|
|
423
|
-
if (verbose)
|
|
424
|
-
console.info(`Found ${blobFiles.items.length} files in raw store for space: ${spaceId}`);
|
|
425
|
-
blobFiles.items.forEach((f) => {
|
|
426
|
-
const contentUUID = f.name.substring(0, 36);
|
|
427
|
-
const locations = locationDataMap[contentUUID] || [];
|
|
428
|
-
if (locations.length === 0) {
|
|
429
|
-
if (verbose)
|
|
430
|
-
console.warn(`No location data found for contentUUID: ${contentUUID}`);
|
|
431
|
-
files.push({ contentUUID });
|
|
432
|
-
} else {
|
|
433
|
-
locations.forEach((loc) => {
|
|
434
|
-
files.push({ contentUUID, locationUUID: loc.locationUUID, created: loc.created });
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
return files;
|
|
439
|
-
}
|
|
440
|
-
async function getGraphFiles(providerId, queryHandler2) {
|
|
441
|
-
if (queryHandler2 === void 0)
|
|
442
|
-
return {};
|
|
443
|
-
const q = `PREFIX qcy: <${qaecyPrefixes["qcy"]}>
|
|
444
|
-
SELECT ?fc ?loc ?created ?fp ?size
|
|
445
|
-
WHERE {
|
|
446
|
-
?fc a qcy:FileContent ;
|
|
447
|
-
qcy:sizeBytes ?size ;
|
|
448
|
-
qcy:hasFileLocation ?loc .
|
|
449
|
-
?loc qcy:remoteProviderId "${providerId}" ;
|
|
450
|
-
qcy:dateCreated ?created ;
|
|
451
|
-
qcy:filePath ?fp .
|
|
452
|
-
}`;
|
|
453
|
-
const res = await queryHandler2(q);
|
|
454
|
-
const map = {};
|
|
455
|
-
res["results"]["bindings"].forEach((b) => {
|
|
456
|
-
const locationUUID = b["loc"].value.split("/").pop();
|
|
457
|
-
const contentUUID = b["fc"].value.split("/").pop();
|
|
458
|
-
const created = b["created"].value;
|
|
459
|
-
const size = b["size"].value;
|
|
460
|
-
if (map[contentUUID] === void 0)
|
|
461
|
-
map[contentUUID] = [];
|
|
462
|
-
map[contentUUID].push({ locationUUID, created, size });
|
|
463
|
-
});
|
|
464
|
-
return map;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
// libs/js/sync-tools/src/lib/list-local-files.ts
|
|
468
|
-
var import_path2 = require("path");
|
|
469
|
-
|
|
470
|
-
// libs/js/id-builders/src/lib/id-builders.ts
|
|
471
|
-
var import_uuid2 = require("uuid");
|
|
472
|
-
var replacements = {
|
|
473
|
-
"\xE4": "ae",
|
|
474
|
-
"a\u0308": "ae",
|
|
475
|
-
"\xC4": "AE",
|
|
476
|
-
"\xF6": "oe",
|
|
477
|
-
"\xD6": "OE",
|
|
478
|
-
"\xFC": "ue",
|
|
479
|
-
"u\u0308": "ue",
|
|
480
|
-
"\xDC": "UE",
|
|
481
|
-
"U\u0308": "UE",
|
|
482
|
-
"\xDF": "ss",
|
|
483
|
-
"\xE6": "ae",
|
|
484
|
-
"\xC6": "AE",
|
|
485
|
-
"\xF8": "oe",
|
|
486
|
-
"\xD8": "OE",
|
|
487
|
-
"\xE5": "aa",
|
|
488
|
-
"\xC5": "AA",
|
|
489
|
-
"\xE1": "a",
|
|
490
|
-
"\xC1": "A",
|
|
491
|
-
"\xF0": "d",
|
|
492
|
-
"\xD0": "D",
|
|
493
|
-
"\xE9": "e",
|
|
494
|
-
"\xC9": "E",
|
|
495
|
-
"\xED": "i",
|
|
496
|
-
"\xCD": "I",
|
|
497
|
-
"\xF3": "o",
|
|
498
|
-
"\xD3": "O",
|
|
499
|
-
"\xFA": "u",
|
|
500
|
-
"\xDA": "U",
|
|
501
|
-
"\xFD": "y",
|
|
502
|
-
"\xDD": "Y",
|
|
503
|
-
"\xFE": "th",
|
|
504
|
-
"\xDE": "Th"
|
|
505
|
-
};
|
|
506
|
-
function contextBasedGuid(contextString, verbose = false) {
|
|
507
|
-
const namespace = "daca0510-72b5-48ba-9091-b918ca18136b";
|
|
508
|
-
contextString = replaceSpecialChars(contextString, verbose);
|
|
509
|
-
return (0, import_uuid2.v5)(contextString, namespace);
|
|
510
|
-
}
|
|
511
|
-
function replaceSpecialChars(str, verbose = false) {
|
|
512
|
-
let result = str;
|
|
513
|
-
for (const char in replacements) {
|
|
514
|
-
result = result.replace(new RegExp(char, "g"), replacements[char]);
|
|
515
|
-
}
|
|
516
|
-
if (verbose && result !== str)
|
|
517
|
-
console.info(`${str} -> ${result}`);
|
|
518
|
-
return result;
|
|
519
|
-
}
|
|
520
|
-
function generateFileUUID(filepath, providerId = "") {
|
|
521
|
-
return contextBasedGuid(`${providerId}${filepath}`);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
// libs/js/id-builders/src/lib/md5-builder.ts
|
|
525
|
-
var import_spark_md5 = __toESM(require("spark-md5"));
|
|
526
|
-
async function fromReadStream(readStream) {
|
|
527
|
-
return new Promise((resolve, reject) => {
|
|
528
|
-
const spark = new import_spark_md5.default.ArrayBuffer();
|
|
529
|
-
readStream.on("data", (chunk) => {
|
|
530
|
-
spark.append(chunk);
|
|
531
|
-
});
|
|
532
|
-
readStream.on("end", () => {
|
|
533
|
-
resolve(spark.end());
|
|
534
|
-
});
|
|
535
|
-
readStream.on("error", (err) => reject(err));
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
// libs/js/sync-tools/src/lib/helpers/md5-builder-node.ts
|
|
540
|
-
var import_fs = require("fs");
|
|
541
|
-
async function md5FromWorker(filePaths, hashWorkerPath, verbose = false, logIntervalPct = 1) {
|
|
542
|
-
const { WorkerPool: WorkerPool2 } = await Promise.resolve().then(() => (init_worker_pool(), worker_pool_exports));
|
|
543
|
-
const pool = new WorkerPool2(hashWorkerPath);
|
|
544
|
-
const hashes = filePaths.map((filePath) => pool.hashFile(filePath));
|
|
545
|
-
if (verbose) {
|
|
546
|
-
let completed = 0;
|
|
547
|
-
let lastPct = 0;
|
|
548
|
-
hashes.forEach(
|
|
549
|
-
(promise) => promise.then(() => {
|
|
550
|
-
completed++;
|
|
551
|
-
const pct = Math.floor(completed / filePaths.length * 100);
|
|
552
|
-
if (pct - lastPct >= logIntervalPct) {
|
|
553
|
-
lastPct = pct;
|
|
554
|
-
console.info(`MD5 progress: ${completed}/${filePaths.length} (${pct}%)`);
|
|
555
|
-
}
|
|
556
|
-
})
|
|
557
|
-
);
|
|
558
|
-
}
|
|
559
|
-
const ret = await Promise.all(hashes);
|
|
560
|
-
await pool.close();
|
|
561
|
-
return ret;
|
|
562
|
-
}
|
|
563
|
-
async function md5NoWorker(filePaths, verbose) {
|
|
564
|
-
if (verbose)
|
|
565
|
-
console.info(`Calculating MD5 hashes for ${filePaths.length} files...`);
|
|
566
|
-
const concurrency = 50;
|
|
567
|
-
const hashes = [];
|
|
568
|
-
for (let i = 0; i < filePaths.length; i += concurrency) {
|
|
569
|
-
const chunk = filePaths.slice(i, i + concurrency);
|
|
570
|
-
const chunkHashes = await Promise.all(
|
|
571
|
-
chunk.map((f) => {
|
|
572
|
-
const stream = (0, import_fs.createReadStream)(f);
|
|
573
|
-
return fromReadStream(stream);
|
|
574
|
-
})
|
|
575
|
-
);
|
|
576
|
-
hashes.push(...chunkHashes);
|
|
577
|
-
if (verbose) {
|
|
578
|
-
const pct = Math.min(
|
|
579
|
-
100,
|
|
580
|
-
Math.round((i + chunk.length) / filePaths.length * 100)
|
|
581
|
-
);
|
|
582
|
-
console.info(
|
|
583
|
-
`MD5 progress: ${pct}% (${i + chunk.length}/${filePaths.length})`
|
|
584
|
-
);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
if (verbose)
|
|
588
|
-
console.info(`Calculated MD5 hashes for ${filePaths.length} files.`);
|
|
589
|
-
return hashes;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// libs/js/sync-tools/src/lib/list-local-files.ts
|
|
593
|
-
var import_promises = require("fs/promises");
|
|
594
|
-
var import_promises2 = require("fs/promises");
|
|
595
|
-
var import_jszip = __toESM(require("jszip"));
|
|
596
|
-
var IGNORED = {
|
|
597
|
-
dirs: ["node_modules", ".git", ".hg", ".svn", ".DS_Store"],
|
|
598
|
-
suffix: [".tmp", ".part", ".crdownload"]
|
|
599
|
-
};
|
|
600
|
-
var UNZIPPED_SUFFIX = "_unzipped";
|
|
601
|
-
async function listLocalFiles(dir, providerId = "", verbose = false, logIntervalPct = 5, ignored = IGNORED, hashWorkerPath, unzipZipped = false) {
|
|
602
|
-
if (verbose)
|
|
603
|
-
console.info(`Listing files in local dir: ${dir}`);
|
|
604
|
-
if (unzipZipped) {
|
|
605
|
-
const zipFiles = await filesInLocalDirRecursive(dir, (entry) => entry.name.toLowerCase().endsWith(".zip"));
|
|
606
|
-
if (zipFiles.length && verbose)
|
|
607
|
-
console.info(`Found ${zipFiles.length} zip files to unzip...`);
|
|
608
|
-
for (const zipFile of zipFiles) {
|
|
609
|
-
await unzipFile(zipFile);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
ignored = unzipZipped ? { ...ignored, suffix: [...ignored.suffix, ".zip"] } : ignored;
|
|
613
|
-
const filterFunc = (entry) => {
|
|
614
|
-
if (ignored.dirs.some((d) => entry.name.includes(d)))
|
|
615
|
-
return false;
|
|
616
|
-
if (ignored.suffix.some((suffix) => entry.name.toLowerCase().endsWith(suffix)))
|
|
617
|
-
return false;
|
|
618
|
-
return true;
|
|
619
|
-
};
|
|
620
|
-
const fullPaths = await filesInLocalDirRecursive(dir, filterFunc);
|
|
621
|
-
if (verbose)
|
|
622
|
-
console.info(`Found ${fullPaths.length} files in ${dir}`);
|
|
623
|
-
if (verbose && fullPaths.length === 0)
|
|
624
|
-
console.warn(`No files found in ${dir}`);
|
|
625
|
-
if (verbose && fullPaths.length > 1e4)
|
|
626
|
-
console.warn(
|
|
627
|
-
`More than 10,000 files found in ${dir}. This may take a while...`
|
|
628
|
-
);
|
|
629
|
-
const hashes = hashWorkerPath ? await md5FromWorker(fullPaths, hashWorkerPath, verbose, logIntervalPct) : await md5NoWorker(fullPaths, verbose);
|
|
630
|
-
const stats = await Promise.all(fullPaths.map((f) => (0, import_promises.stat)(f)));
|
|
631
|
-
return fullPaths.map((f, i) => {
|
|
632
|
-
const relativePath = (0, import_path2.relative)(dir, f);
|
|
633
|
-
const md5 = hashes[i];
|
|
634
|
-
const contentUUID = contextBasedGuid(md5);
|
|
635
|
-
const locationUUID = generateFileUUID(relativePath, providerId);
|
|
636
|
-
const { mtimeMs, size } = stats[i];
|
|
637
|
-
return { relativePath, fullPath: f, size, md5, contentUUID, locationUUID, mtimeMs };
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
async function filesInLocalDirRecursive(dir, filterFunc = () => true, excludeDirs = true) {
|
|
641
|
-
const entries = await (0, import_promises.readdir)(dir, { withFileTypes: true, recursive: true });
|
|
642
|
-
return entries.filter((entry) => {
|
|
643
|
-
if (excludeDirs && !entry.isFile())
|
|
644
|
-
return false;
|
|
645
|
-
return filterFunc(entry);
|
|
646
|
-
}).map((entry) => (0, import_path2.join)(entry.parentPath, entry.name));
|
|
647
|
-
}
|
|
648
|
-
var DEFAULT_MAX_UNCOMPRESSED_SIZE = 500 * 1024 * 1024;
|
|
649
|
-
var DEFAULT_MAX_RECURSION_DEPTH = 3;
|
|
650
|
-
async function unzipFile(zipPath, recursive = true, options) {
|
|
651
|
-
const maxUncompressedSize = options?.maxUncompressedSize ?? DEFAULT_MAX_UNCOMPRESSED_SIZE;
|
|
652
|
-
const maxRecursionDepth = options?.maxRecursionDepth ?? DEFAULT_MAX_RECURSION_DEPTH;
|
|
653
|
-
const currentDepth = options?.currentDepth ?? 0;
|
|
654
|
-
const totalUncompressedSize = options?.totalUncompressedSize ?? { value: 0 };
|
|
655
|
-
if (currentDepth > maxRecursionDepth) {
|
|
656
|
-
throw new Error(`Zip extraction aborted: exceeded max recursion depth (${maxRecursionDepth})`);
|
|
657
|
-
}
|
|
658
|
-
const targetDir = zipPath.replace(/\.zip$/i, "") + UNZIPPED_SUFFIX;
|
|
659
|
-
await (0, import_promises2.mkdir)(targetDir, { recursive: true });
|
|
660
|
-
const data = await (0, import_promises.readFile)(zipPath);
|
|
661
|
-
const zip = await import_jszip.default.loadAsync(data);
|
|
662
|
-
const extractPromises = [];
|
|
663
|
-
for (const [relativePath, file] of Object.entries(zip.files)) {
|
|
664
|
-
if (!file.dir) {
|
|
665
|
-
const pathParts = relativePath.split("/");
|
|
666
|
-
const fileTargetDir = (0, import_path2.join)(targetDir, ...pathParts.slice(0, -1));
|
|
667
|
-
const targetPath = (0, import_path2.join)(fileTargetDir, pathParts[pathParts.length - 1]);
|
|
668
|
-
await ensureDir(fileTargetDir);
|
|
669
|
-
const promise = file.async("nodebuffer").then(async (content) => {
|
|
670
|
-
totalUncompressedSize.value += content.length;
|
|
671
|
-
if (totalUncompressedSize.value > maxUncompressedSize) {
|
|
672
|
-
throw new Error(`Zip extraction aborted: exceeded max uncompressed size (${maxUncompressedSize} bytes)`);
|
|
673
|
-
}
|
|
674
|
-
await (0, import_promises.writeFile)(targetPath, content);
|
|
675
|
-
if (recursive && targetPath.toLowerCase().endsWith(".zip")) {
|
|
676
|
-
await unzipFile(targetPath, true, {
|
|
677
|
-
maxUncompressedSize,
|
|
678
|
-
maxRecursionDepth,
|
|
679
|
-
currentDepth: currentDepth + 1,
|
|
680
|
-
totalUncompressedSize
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
extractPromises.push(promise);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
await Promise.all(extractPromises);
|
|
688
|
-
}
|
|
689
|
-
async function ensureDir(path) {
|
|
690
|
-
await (0, import_promises2.mkdir)(path, { recursive: true });
|
|
691
|
-
}
|
|
692
|
-
async function deleteUnzipped(dir) {
|
|
693
|
-
const paths = await filesInLocalDirRecursive(dir, (entry) => entry.name.toLowerCase().endsWith(UNZIPPED_SUFFIX), false);
|
|
694
|
-
for (const p of paths) {
|
|
695
|
-
await (0, import_promises.rm)(p, { recursive: true, force: true });
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
// apps/desktop/cue-cli/src/cue-cli-compare.ts
|
|
700
|
-
var import_commander = require("commander");
|
|
701
|
-
|
|
702
|
-
// apps/desktop/cue-cli/src/helpers/query-handler.ts
|
|
703
|
-
var import_auth2 = require("firebase/auth");
|
|
704
|
-
async function queryHandler(query, spaceId, useEmulator) {
|
|
705
|
-
const endpoint = useEmulator ? SPARQL_ENDPOINT_EMULATOR : SPARQL_ENDPOINT;
|
|
706
|
-
const token = await (0, import_auth2.getAuth)().currentUser?.getIdToken();
|
|
707
|
-
const res = await fetch(endpoint, {
|
|
708
|
-
method: "POST",
|
|
709
|
-
headers: {
|
|
710
|
-
"x-project-id": spaceId,
|
|
711
|
-
"authorization": `Bearer ${token}`,
|
|
712
|
-
"Content-Type": "application/sparql-query",
|
|
713
|
-
Accept: "application/sparql-results+json"
|
|
714
|
-
},
|
|
715
|
-
body: query
|
|
716
|
-
});
|
|
717
|
-
if (!res.ok) {
|
|
718
|
-
console.error(
|
|
719
|
-
`Error querying triplestore: ${res.status} ${res.statusText}`
|
|
720
|
-
);
|
|
721
|
-
return { results: { bindings: [] } };
|
|
722
|
-
}
|
|
723
|
-
return res.json();
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// apps/desktop/cue-cli/src/helpers/file-size-pretty.ts
|
|
727
|
-
function fileSizePretty(size) {
|
|
728
|
-
if (size < 1024)
|
|
729
|
-
return size + " B";
|
|
730
|
-
const i = Math.floor(Math.log(size) / Math.log(1024));
|
|
731
|
-
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
732
|
-
return (size / Math.pow(1024, i)).toFixed(2) + " " + sizes[i];
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
// apps/desktop/cue-cli/src/helpers/fetch-custom-token.ts
|
|
736
|
-
async function fetchCustomToken(pid, apiKey, useEmulator) {
|
|
737
|
-
const url = useEmulator ? TOKEN_ENDPOINT_EMULATOR : TOKEN_ENDPOINT;
|
|
738
|
-
const data = await fetch(url, {
|
|
739
|
-
method: "GET",
|
|
740
|
-
headers: {
|
|
741
|
-
"x-project-id": pid,
|
|
742
|
-
"cue-api-key": apiKey
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
if (!data.ok) {
|
|
746
|
-
console.error("Failed to fetch token:", data.statusText);
|
|
747
|
-
process.exit(1);
|
|
748
|
-
}
|
|
749
|
-
const result = await data.json();
|
|
750
|
-
return result.token;
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
// apps/desktop/cue-cli/src/helpers/auth.ts
|
|
754
|
-
var import_auth3 = require("firebase/auth");
|
|
755
|
-
async function authenticate(emulators, key, verbose = false) {
|
|
756
|
-
if (!key) {
|
|
757
|
-
key = process.env.CUE_API_KEY;
|
|
758
|
-
if (!key) {
|
|
759
|
-
console.error(
|
|
760
|
-
"API key is required. Provide it via --key option or CUE_API_KEY environment variable."
|
|
761
|
-
);
|
|
762
|
-
process.exit(1);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
const fb = CueFirebase.getInstance(
|
|
766
|
-
FIREBASE_CONFIG(emulators),
|
|
767
|
-
void 0,
|
|
768
|
-
!verbose
|
|
769
|
-
);
|
|
770
|
-
if (verbose)
|
|
771
|
-
console.info("Fetching custom token \u23F3");
|
|
772
|
-
const customToken = await fetchCustomToken("xx", key, emulators);
|
|
773
|
-
if (verbose)
|
|
774
|
-
console.info("Fetched token \u2705");
|
|
775
|
-
if (verbose)
|
|
776
|
-
console.info("Signing in \u23F3");
|
|
777
|
-
const userCredentials = await (0, import_auth3.signInWithCustomToken)(fb.auth, customToken);
|
|
778
|
-
if (verbose)
|
|
779
|
-
console.info("Signed in \u2705");
|
|
780
|
-
const idTokenResult = await userCredentials.user.getIdTokenResult();
|
|
781
|
-
const role = idTokenResult.claims["role"];
|
|
782
|
-
const isSuperAdmin = role === "superadmin";
|
|
783
|
-
return { isSuperAdmin, userId: userCredentials.user.uid };
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
// apps/desktop/cue-cli/src/cue-cli-compare.ts
|
|
787
|
-
var program = new import_commander.Command();
|
|
788
|
-
program.name("cue-cli-compare").description("Compare to files in Cue").requiredOption("-s, --space <id>", "Specify the space ID (required)").requiredOption("-p, --path <id>", "Specify the folder path (required)").option(
|
|
789
|
-
"-k, --key <api-key>",
|
|
790
|
-
"Specify the API key (or set CUE_API_KEY env variable)"
|
|
791
|
-
).option(
|
|
792
|
-
"--provider <provider ID>",
|
|
793
|
-
"Specify the provider ID (eg. sharepoint, drive, dropbox) or leave empty for default provider",
|
|
794
|
-
""
|
|
795
|
-
).option("-v, --verbose", "Enable verbose output", false).option("-e, --emulators", "Uses emulators for sync", false).option(
|
|
796
|
-
"-z, --zip",
|
|
797
|
-
"Include zipped content (will temporarily unzip files with same logic as when syncing and delete them again after the comparison)",
|
|
798
|
-
false
|
|
799
|
-
);
|
|
800
|
-
program.parse(process.argv);
|
|
801
|
-
async function main(options) {
|
|
802
|
-
const { space, path, verbose, provider, emulators, zip } = options;
|
|
803
|
-
await authenticate(emulators, options.key, verbose);
|
|
804
|
-
if (verbose)
|
|
805
|
-
console.info("Building compare base \u23F3");
|
|
806
|
-
const qh = async (query) => queryHandler(query, space, emulators);
|
|
807
|
-
const [localFiles, remoteFiles] = await Promise.all([
|
|
808
|
-
listLocalFiles(
|
|
809
|
-
path,
|
|
810
|
-
provider,
|
|
811
|
-
verbose,
|
|
812
|
-
5,
|
|
813
|
-
IGNORED_LOCAL,
|
|
814
|
-
HASH_WORKER_PATH,
|
|
815
|
-
zip
|
|
816
|
-
),
|
|
817
|
-
listRemoteFiles(space, provider, qh, verbose)
|
|
818
|
-
]);
|
|
819
|
-
const unzipPromise = zip ? deleteUnzipped(path) : Promise.resolve();
|
|
820
|
-
if (zip) {
|
|
821
|
-
if (verbose)
|
|
822
|
-
console.info("Started deletion of temp unzipped dirs \u23F3");
|
|
823
|
-
}
|
|
824
|
-
const report = await compareLocalRemote(localFiles, remoteFiles);
|
|
825
|
-
await unzipPromise;
|
|
826
|
-
if (zip && verbose)
|
|
827
|
-
console.info("Cleaned up unzipped files \u2705");
|
|
828
|
-
if (verbose)
|
|
829
|
-
console.info("Built compare base \u2705");
|
|
830
|
-
console.log("");
|
|
831
|
-
console.log("--- Compare Report ---");
|
|
832
|
-
console.log("");
|
|
833
|
-
console.log(`Total files: ${report.totalCount}`);
|
|
834
|
-
console.log(`Total size: ${fileSizePretty(report.totalSize || 0)}`);
|
|
835
|
-
console.log("");
|
|
836
|
-
console.log(
|
|
837
|
-
`Files synchronized: ${report.syncCount} (${(report.synctPctCount * 100).toFixed(2)}%)`
|
|
838
|
-
);
|
|
839
|
-
console.log(
|
|
840
|
-
`Synchronized size: ${fileSizePretty(report.syncSize || 0)} (${(report.synctPctSize * 100).toFixed(2)}%)`
|
|
841
|
-
);
|
|
842
|
-
console.log("");
|
|
843
|
-
if (report.localNotOnRemote) {
|
|
844
|
-
console.log(
|
|
845
|
-
`${report.localNotOnRemote.length} files do not exist on remote`
|
|
846
|
-
);
|
|
847
|
-
if (verbose && report.localNotOnRemote.length > 0) {
|
|
848
|
-
for (const f of report.localNotOnRemote) {
|
|
849
|
-
console.log(
|
|
850
|
-
" - " + f.relativePath + " (" + fileSizePretty(f.size || 0) + ")"
|
|
851
|
-
);
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
console.log("");
|
|
855
|
-
}
|
|
856
|
-
if (report.localNotOnRemotePathOnly) {
|
|
857
|
-
console.log(
|
|
858
|
-
`${report.localNotOnRemotePathOnly.length} file paths do not exist on remote on providerId "${provider}" (file duplicates)`
|
|
859
|
-
);
|
|
860
|
-
if (verbose && report.localNotOnRemotePathOnly.length > 0) {
|
|
861
|
-
for (const f of report.localNotOnRemotePathOnly) {
|
|
862
|
-
console.log(
|
|
863
|
-
" - " + f.relativePath + " (" + fileSizePretty(f.size || 0) + ")"
|
|
864
|
-
);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
console.log("");
|
|
868
|
-
}
|
|
869
|
-
if (report.remoteNotOnLocal) {
|
|
870
|
-
console.log(`${report.remoteNotOnLocal.length} files do not exist locally`);
|
|
871
|
-
console.log(
|
|
872
|
-
"This might expected if the files belong to another provider or have been deleted locally"
|
|
873
|
-
);
|
|
874
|
-
if (verbose && report.remoteNotOnLocal.length > 0) {
|
|
875
|
-
for (const f of report.remoteNotOnLocal) {
|
|
876
|
-
console.log(
|
|
877
|
-
" - " + f.contentUUID + " (" + fileSizePretty(f.size || 0) + ")"
|
|
878
|
-
);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
console.log("");
|
|
882
|
-
}
|
|
883
|
-
if (report.remoteNotOnLocalPathOnly) {
|
|
884
|
-
console.log(
|
|
885
|
-
`${report.remoteNotOnLocalPathOnly.length} file paths on providerId "${provider}" do not exist locally`
|
|
886
|
-
);
|
|
887
|
-
console.log(
|
|
888
|
-
"This might expected if the files belong to another provider or have been deleted locally"
|
|
889
|
-
);
|
|
890
|
-
if (verbose && report.remoteNotOnLocalPathOnly.length > 0) {
|
|
891
|
-
for (const f of report.remoteNotOnLocalPathOnly) {
|
|
892
|
-
console.log(
|
|
893
|
-
" - " + f.contentUUID + " (" + fileSizePretty(f.size || 0) + ")"
|
|
894
|
-
);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
console.log("");
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
main(program.opts()).catch((err) => {
|
|
901
|
-
console.error("Error:", err);
|
|
902
|
-
process.exit(1);
|
|
903
|
-
});
|