@fnndsc/salsa 4.5.7 → 4.6.0
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/README.md +0 -2
- package/dist/compute/index.d.ts +0 -9
- package/dist/compute/index.js +0 -16
- package/dist/compute/index.js.map +1 -1
- package/dist/dag/feedData.js +166 -73
- package/dist/dag/feedData.js.map +1 -1
- package/dist/dag/feedLoad.d.ts +1 -1
- package/dist/dag/feedLoad.js +6 -4
- package/dist/dag/feedLoad.js.map +1 -1
- package/dist/dicom/pixels.js +95 -36
- package/dist/dicom/pixels.js.map +1 -1
- package/dist/dicom/series.d.ts +4 -1
- package/dist/dicom/series.js +80 -31
- package/dist/dicom/series.js.map +1 -1
- package/dist/dicom/tags.d.ts +28 -0
- package/dist/dicom/tags.js +30 -0
- package/dist/dicom/tags.js.map +1 -1
- package/dist/files/copy.d.ts +197 -0
- package/dist/files/copy.js +636 -0
- package/dist/files/copy.js.map +1 -0
- package/dist/files/copyFolder.d.ts +103 -0
- package/dist/files/copyFolder.js +199 -0
- package/dist/files/copyFolder.js.map +1 -0
- package/dist/files/create.d.ts +178 -0
- package/dist/files/create.js +444 -0
- package/dist/files/create.js.map +1 -0
- package/dist/files/download.d.ts +188 -0
- package/dist/files/download.js +541 -0
- package/dist/files/download.js.map +1 -0
- package/dist/files/index.d.ts +69 -141
- package/dist/files/index.js +184 -535
- package/dist/files/index.js.map +1 -1
- package/dist/files/listing.d.ts +132 -0
- package/dist/files/listing.js +179 -0
- package/dist/files/listing.js.map +1 -0
- package/dist/files/move.d.ts +125 -0
- package/dist/files/move.js +334 -0
- package/dist/files/move.js.map +1 -0
- package/dist/files/pathMapper.d.ts +24 -1
- package/dist/files/pathMapper.js +108 -47
- package/dist/files/pathMapper.js.map +1 -1
- package/dist/files/proof.d.ts +315 -0
- package/dist/files/proof.js +574 -0
- package/dist/files/proof.js.map +1 -0
- package/dist/files/removal.d.ts +223 -0
- package/dist/files/removal.js +318 -0
- package/dist/files/removal.js.map +1 -0
- package/dist/files/replace.d.ts +175 -0
- package/dist/files/replace.js +582 -0
- package/dist/files/replace.js.map +1 -0
- package/dist/files/upload.d.ts +205 -0
- package/dist/files/upload.js +478 -0
- package/dist/files/upload.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.js +45 -32
- package/dist/index.js.map +1 -1
- package/dist/jobs/index.d.ts +1 -1
- package/dist/jobs/index.js +1 -2
- package/dist/jobs/index.js.map +1 -1
- package/dist/jobs/jobOps.d.ts +0 -13
- package/dist/jobs/jobOps.js +0 -37
- package/dist/jobs/jobOps.js.map +1 -1
- package/dist/pacs/anonymise.d.ts +17 -36
- package/dist/pacs/anonymise.js +29 -67
- package/dist/pacs/anonymise.js.map +1 -1
- package/dist/pipelines/index.d.ts +1 -13
- package/dist/pipelines/index.js +0 -38
- package/dist/pipelines/index.js.map +1 -1
- package/dist/pipelines/invocation.js +321 -167
- package/dist/pipelines/invocation.js.map +1 -1
- package/dist/pipelines/manifest.js.map +1 -1
- package/dist/pipelines/packages.d.ts +11 -8
- package/dist/pipelines/packages.js +253 -77
- package/dist/pipelines/packages.js.map +1 -1
- package/dist/plugins/adminToken.d.ts +67 -0
- package/dist/plugins/adminToken.js +77 -0
- package/dist/plugins/adminToken.js.map +1 -0
- package/dist/plugins/index.d.ts +0 -7
- package/dist/plugins/index.js +0 -16
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/peer_search.d.ts +0 -15
- package/dist/plugins/peer_search.js +0 -25
- package/dist/plugins/peer_search.js.map +1 -1
- package/dist/plugins/plugin_add.d.ts +14 -2
- package/dist/plugins/plugin_add.js +42 -13
- package/dist/plugins/plugin_add.js.map +1 -1
- package/dist/plugins/plugin_docker.d.ts +25 -0
- package/dist/plugins/plugin_docker.js +33 -0
- package/dist/plugins/plugin_docker.js.map +1 -1
- package/dist/plugins/plugin_register.d.ts +0 -10
- package/dist/plugins/plugin_register.js +3 -54
- package/dist/plugins/plugin_register.js.map +1 -1
- package/dist/plugins/plugin_sync.js +45 -22
- package/dist/plugins/plugin_sync.js.map +1 -1
- package/dist/plugins/plugin_validate.js +47 -13
- package/dist/plugins/plugin_validate.js.map +1 -1
- package/dist/plugins/store_import.d.ts +0 -9
- package/dist/plugins/store_import.js +3 -29
- package/dist/plugins/store_import.js.map +1 -1
- package/dist/retrieve/task.d.ts +137 -0
- package/dist/retrieve/task.js +41 -0
- package/dist/retrieve/task.js.map +1 -0
- package/dist/retrieve/watch.d.ts +2 -118
- package/dist/retrieve/watch.js +452 -321
- package/dist/retrieve/watch.js.map +1 -1
- package/dist/vfs/providers/etc.d.ts +6 -4
- package/dist/vfs/providers/etc.js +12 -4
- package/dist/vfs/providers/etc.js.map +1 -1
- package/dist/vfs/providers/native.d.ts +116 -39
- package/dist/vfs/providers/native.js +291 -347
- package/dist/vfs/providers/native.js.map +1 -1
- package/dist/vfs/providers/pacs.d.ts +29 -3
- package/dist/vfs/providers/pacs.js +303 -73
- package/dist/vfs/providers/pacs.js.map +1 -1
- package/dist/vfs/providers/pacs_content.js +22 -6
- package/dist/vfs/providers/pacs_content.js.map +1 -1
- package/dist/vfs/providers/proc/backfill.d.ts +46 -0
- package/dist/vfs/providers/proc/backfill.js +147 -0
- package/dist/vfs/providers/proc/backfill.js.map +1 -0
- package/dist/vfs/providers/proc/book.d.ts +176 -0
- package/dist/vfs/providers/proc/book.js +73 -0
- package/dist/vfs/providers/proc/book.js.map +1 -0
- package/dist/vfs/providers/proc/catchup.d.ts +69 -0
- package/dist/vfs/providers/proc/catchup.js +125 -0
- package/dist/vfs/providers/proc/catchup.js.map +1 -0
- package/dist/vfs/providers/proc/feedIndex.d.ts +146 -0
- package/dist/vfs/providers/proc/feedIndex.js +354 -0
- package/dist/vfs/providers/proc/feedIndex.js.map +1 -0
- package/dist/vfs/providers/proc/feedTopology.d.ts +85 -0
- package/dist/vfs/providers/proc/feedTopology.js +192 -0
- package/dist/vfs/providers/proc/feedTopology.js.map +1 -0
- package/dist/vfs/providers/proc/locate.d.ts +60 -0
- package/dist/vfs/providers/proc/locate.js +103 -0
- package/dist/vfs/providers/proc/locate.js.map +1 -0
- package/dist/vfs/providers/proc/path.d.ts +50 -0
- package/dist/vfs/providers/proc/path.js +106 -0
- package/dist/vfs/providers/proc/path.js.map +1 -0
- package/dist/vfs/providers/proc/roster.d.ts +95 -0
- package/dist/vfs/providers/proc/roster.js +425 -0
- package/dist/vfs/providers/proc/roster.js.map +1 -0
- package/dist/vfs/providers/proc/rows.d.ts +120 -0
- package/dist/vfs/providers/proc/rows.js +181 -0
- package/dist/vfs/providers/proc/rows.js.map +1 -0
- package/dist/vfs/providers/proc/subtree.d.ts +73 -0
- package/dist/vfs/providers/proc/subtree.js +125 -0
- package/dist/vfs/providers/proc/subtree.js.map +1 -0
- package/dist/vfs/providers/proc/sweep.d.ts +89 -0
- package/dist/vfs/providers/proc/sweep.js +297 -0
- package/dist/vfs/providers/proc/sweep.js.map +1 -0
- package/dist/vfs/providers/proc.d.ts +47 -346
- package/dist/vfs/providers/proc.js +349 -1806
- package/dist/vfs/providers/proc.js.map +1 -1
- package/dist/vfs/providers/share.js +4 -1
- package/dist/vfs/providers/share.js.map +1 -1
- package/package.json +3 -3
- package/dist/pacs/resultDecode.d.ts +0 -13
- package/dist/pacs/resultDecode.js +0 -19
- package/dist/pacs/resultDecode.js.map +0 -1
package/dist/files/index.js
CHANGED
|
@@ -38,24 +38,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
38
38
|
};
|
|
39
39
|
})();
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.files_listRecursive =
|
|
42
|
-
exports.files_copyRecursively = files_copyRecursively;
|
|
41
|
+
exports.uploadPlanCreateOnly_make = exports.uploadPlan_make = exports.files_uploadPath = exports.UploadPlan = exports.sourceTree_walk = exports.path_copy = exports.path_mkdirTree = exports.path_mkdir = exports.files_touch = exports.files_mkdir = exports.files_create = exports.file_place = exports.storePath_bare = exports.listedRow_name = exports.files_listRecursiveChecked = exports.files_listRecursive = void 0;
|
|
43
42
|
exports.files_path_isDirectory = files_path_isDirectory;
|
|
44
|
-
exports.files_create = files_create;
|
|
45
|
-
exports.files_touch = files_touch;
|
|
46
|
-
exports.files_copy = files_copy;
|
|
47
|
-
exports.files_move = files_move;
|
|
48
|
-
exports.files_uploadPath = files_uploadPath;
|
|
49
|
-
exports.pathHolders_find = pathHolders_find;
|
|
50
|
-
exports.folderPath_holder = folderPath_holder;
|
|
51
|
-
exports.files_mkdir = files_mkdir;
|
|
52
43
|
exports.files_getGroup = files_getGroup;
|
|
53
44
|
exports.files_list = files_list;
|
|
54
45
|
exports.files_listAll = files_listAll;
|
|
55
46
|
exports.files_listOutcome = files_listOutcome;
|
|
47
|
+
exports.path_isProjection = path_isProjection;
|
|
48
|
+
exports.files_listWhole = files_listWhole;
|
|
56
49
|
exports.fileFields_get = fileFields_get;
|
|
57
50
|
exports.files_delete = files_delete;
|
|
58
|
-
exports.folderByPath_delete = folderByPath_delete;
|
|
59
51
|
exports.files_getSingle = files_getSingle;
|
|
60
52
|
exports.files_share = files_share;
|
|
61
53
|
exports.fileContent_get = fileContent_get;
|
|
@@ -68,150 +60,26 @@ const pipeline_content_1 = require("./pipeline_content");
|
|
|
68
60
|
const regular_content_1 = require("./regular_content");
|
|
69
61
|
const pacs_content_1 = require("./pacs_content");
|
|
70
62
|
const dispatcher_js_1 = require("../vfs/dispatcher.js");
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// 2. List subdirectories
|
|
94
|
-
const dirsGroup = await files_getGroup('dirs', rootPath);
|
|
95
|
-
if (dirsGroup) {
|
|
96
|
-
const dirResults = await dirsGroup.asset.resources_getAll();
|
|
97
|
-
if (dirResults && dirResults.tableData) {
|
|
98
|
-
for (const d of dirResults.tableData) {
|
|
99
|
-
const dirPath = d.path;
|
|
100
|
-
items.push({ path: dirPath, type: 'dir' });
|
|
101
|
-
// Recurse
|
|
102
|
-
const subItems = await files_listRecursive(dirPath);
|
|
103
|
-
items = items.concat(subItems);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return items;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Recursively copies a directory from source to destination within ChRIS.
|
|
111
|
-
*
|
|
112
|
-
* @param srcPath - The source directory path.
|
|
113
|
-
* @param destPath - The destination directory path (the parent + new dir name).
|
|
114
|
-
* @returns A Promise resolving to true on success, false on failure.
|
|
115
|
-
*/
|
|
116
|
-
async function files_copyRecursively(srcPath, destPath) {
|
|
117
|
-
try {
|
|
118
|
-
// Ensure destination directory exists (mkdir -p behavior ideally, but files_mkdir is shallow?)
|
|
119
|
-
// Actually files_mkdir assumes parent exists.
|
|
120
|
-
// For a copy, we create the target root first.
|
|
121
|
-
await files_mkdir(destPath);
|
|
122
|
-
const items = await files_listRecursive(srcPath);
|
|
123
|
-
let successCount = 0;
|
|
124
|
-
let failCount = 0;
|
|
125
|
-
// The folders each target folder holds, listed once: a file is never
|
|
126
|
-
// copied onto a folder's name, and a large copy pays one listing per
|
|
127
|
-
// folder rather than one per file.
|
|
128
|
-
const foldersIn = new Map();
|
|
129
|
-
const folders_fetch = async (folder) => {
|
|
130
|
-
const known = foldersIn.get(folder);
|
|
131
|
-
if (known !== undefined)
|
|
132
|
-
return known;
|
|
133
|
-
const outcome = await files_listOutcome({ limit: 1000, offset: 0 }, 'dirs', folder);
|
|
134
|
-
const names = new Set(outcome.kind === 'listing'
|
|
135
|
-
? (outcome.data.tableData ?? []).map((row) => path.posix.basename(String(row.path ?? row.fname ?? '')))
|
|
136
|
-
: []);
|
|
137
|
-
foldersIn.set(folder, names);
|
|
138
|
-
return names;
|
|
139
|
-
};
|
|
140
|
-
for (const item of items) {
|
|
141
|
-
// Normalize item.path to ensure it has a leading slash
|
|
142
|
-
const normalizedItemPath = item.path.startsWith('/') ? item.path : '/' + item.path;
|
|
143
|
-
const relativePath = normalizedItemPath.substring(srcPath.length).replace(/^\//, '');
|
|
144
|
-
const targetPath = path.posix.join(destPath, relativePath); // Use posix for ChRIS paths
|
|
145
|
-
if (item.type === 'dir') {
|
|
146
|
-
(0, cumin_1.runtimeOutput_data)(` Creating directory: ${targetPath}\n`);
|
|
147
|
-
const created = await files_mkdir(targetPath);
|
|
148
|
-
if (!created) {
|
|
149
|
-
(0, cumin_1.runtimeOutput_err)(` Warning: Failed to create directory ${targetPath}\n`);
|
|
150
|
-
failCount++;
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
(await folders_fetch(path.posix.dirname(targetPath))).add(path.posix.basename(targetPath));
|
|
154
|
-
successCount++;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else if (item.type === 'file') {
|
|
158
|
-
(0, cumin_1.runtimeOutput_data)(` Copying file: ${path.posix.basename(normalizedItemPath)}\n`);
|
|
159
|
-
if ((await folders_fetch(path.posix.dirname(targetPath))).has(path.posix.basename(targetPath))) {
|
|
160
|
-
(0, cumin_1.runtimeOutput_err)(` Warning: a folder already holds ${targetPath}; the file is not copied over it\n`);
|
|
161
|
-
failCount++;
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
const copied = await files_copy(normalizedItemPath, targetPath, { folderClear: true });
|
|
165
|
-
if (!copied) {
|
|
166
|
-
(0, cumin_1.runtimeOutput_err)(` Warning: Failed to copy file ${normalizedItemPath}\n`);
|
|
167
|
-
failCount++;
|
|
168
|
-
// Continue trying to copy other files instead of aborting
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
successCount++;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
(0, cumin_1.runtimeOutput_data)(`Copied ${successCount} items, ${failCount} failed\n`);
|
|
176
|
-
return failCount === 0;
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
180
|
-
cumin_1.errorStack.stack_push("error", `Recursive copy failed: ${msg}`);
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Resolves a file ID from a ChRIS path.
|
|
186
|
-
*
|
|
187
|
-
* @param srcPath - The absolute ChRIS file path.
|
|
188
|
-
* @returns Result containing the file ID or Err on failure.
|
|
189
|
-
*/
|
|
190
|
-
async function fileId_resolve(srcPath) {
|
|
191
|
-
const srcDir = path.posix.dirname(srcPath);
|
|
192
|
-
const srcName = path.posix.basename(srcPath);
|
|
193
|
-
const group = await files_getGroup('files', srcDir);
|
|
194
|
-
if (!group) {
|
|
195
|
-
cumin_1.errorStack.stack_push("error", `Could not access source directory: ${srcDir}`);
|
|
196
|
-
return (0, cumin_1.Err)();
|
|
197
|
-
}
|
|
198
|
-
const results = await group.asset.resources_getAll();
|
|
199
|
-
let fileId;
|
|
200
|
-
if (results && results.tableData) {
|
|
201
|
-
const match = results.tableData.find((f) => {
|
|
202
|
-
const fname = f.fname || '';
|
|
203
|
-
return fname === srcPath || path.posix.basename(fname) === srcName;
|
|
204
|
-
});
|
|
205
|
-
if (match && match.id !== undefined) {
|
|
206
|
-
fileId = Number(match.id);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (fileId === undefined) {
|
|
210
|
-
cumin_1.errorStack.stack_push("error", `Source file not found: ${srcPath}`);
|
|
211
|
-
return (0, cumin_1.Err)();
|
|
212
|
-
}
|
|
213
|
-
return (0, cumin_1.Ok)(fileId);
|
|
214
|
-
}
|
|
63
|
+
var listing_js_1 = require("./listing.js");
|
|
64
|
+
Object.defineProperty(exports, "files_listRecursive", { enumerable: true, get: function () { return listing_js_1.files_listRecursive; } });
|
|
65
|
+
Object.defineProperty(exports, "files_listRecursiveChecked", { enumerable: true, get: function () { return listing_js_1.files_listRecursiveChecked; } });
|
|
66
|
+
Object.defineProperty(exports, "listedRow_name", { enumerable: true, get: function () { return listing_js_1.listedRow_name; } });
|
|
67
|
+
Object.defineProperty(exports, "storePath_bare", { enumerable: true, get: function () { return listing_js_1.storePath_bare; } });
|
|
68
|
+
var create_js_1 = require("./create.js");
|
|
69
|
+
Object.defineProperty(exports, "file_place", { enumerable: true, get: function () { return create_js_1.file_place; } });
|
|
70
|
+
Object.defineProperty(exports, "files_create", { enumerable: true, get: function () { return create_js_1.files_create; } });
|
|
71
|
+
Object.defineProperty(exports, "files_mkdir", { enumerable: true, get: function () { return create_js_1.files_mkdir; } });
|
|
72
|
+
Object.defineProperty(exports, "files_touch", { enumerable: true, get: function () { return create_js_1.files_touch; } });
|
|
73
|
+
Object.defineProperty(exports, "path_mkdir", { enumerable: true, get: function () { return create_js_1.path_mkdir; } });
|
|
74
|
+
Object.defineProperty(exports, "path_mkdirTree", { enumerable: true, get: function () { return create_js_1.path_mkdirTree; } });
|
|
75
|
+
var copy_js_1 = require("./copy.js");
|
|
76
|
+
Object.defineProperty(exports, "path_copy", { enumerable: true, get: function () { return copy_js_1.path_copy; } });
|
|
77
|
+
Object.defineProperty(exports, "sourceTree_walk", { enumerable: true, get: function () { return copy_js_1.sourceTree_walk; } });
|
|
78
|
+
var upload_js_1 = require("./upload.js");
|
|
79
|
+
Object.defineProperty(exports, "UploadPlan", { enumerable: true, get: function () { return upload_js_1.UploadPlan; } });
|
|
80
|
+
Object.defineProperty(exports, "files_uploadPath", { enumerable: true, get: function () { return upload_js_1.files_uploadPath; } });
|
|
81
|
+
Object.defineProperty(exports, "uploadPlan_make", { enumerable: true, get: function () { return upload_js_1.uploadPlan_make; } });
|
|
82
|
+
Object.defineProperty(exports, "uploadPlanCreateOnly_make", { enumerable: true, get: function () { return upload_js_1.uploadPlanCreateOnly_make; } });
|
|
215
83
|
/**
|
|
216
84
|
* Determines whether a given ChRIS path refers to a directory.
|
|
217
85
|
*
|
|
@@ -219,310 +87,59 @@ async function fileId_resolve(srcPath) {
|
|
|
219
87
|
* @returns Promise resolving to true if the path is a directory, false otherwise.
|
|
220
88
|
*/
|
|
221
89
|
async function files_path_isDirectory(targetPath) {
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
90
|
+
const clean = targetPath.length > 1 && targetPath.endsWith("/") ? targetPath.slice(0, -1) : targetPath;
|
|
91
|
+
if (clean === "/")
|
|
92
|
+
return true;
|
|
93
|
+
const parent = path.posix.dirname(clean);
|
|
94
|
+
const name = path.posix.basename(clean);
|
|
95
|
+
const outcome = await files_listWhole("dirs", parent);
|
|
96
|
+
if (outcome.kind === "refused")
|
|
97
|
+
throw outcome.error;
|
|
98
|
+
if (outcome.kind === "missing")
|
|
99
|
+
throw new Error(`could not list dirs of ${parent}`);
|
|
100
|
+
if (outcome.kind !== "listing")
|
|
226
101
|
return false;
|
|
102
|
+
if (outcome.data.incomplete !== undefined) {
|
|
103
|
+
throw new Error(`the dirs of ${parent} were not all read (${outcome.data.incomplete.reason})`);
|
|
227
104
|
}
|
|
228
|
-
return
|
|
105
|
+
return outcome.data.tableData.some((entry) => {
|
|
229
106
|
const candidate = entry.path || entry.fname || "";
|
|
230
|
-
return candidate ===
|
|
107
|
+
return candidate === clean || path.posix.basename(candidate) === name;
|
|
231
108
|
});
|
|
232
109
|
}
|
|
110
|
+
/** The contexts cumin builds for a folder's three listings. */
|
|
111
|
+
const FOLDER_CONTEXTS = { files: "ChRISFilesContext", links: "ChRISLinksContext", dirs: "ChRISDirsContext" };
|
|
233
112
|
/**
|
|
234
|
-
*
|
|
113
|
+
* Makes the listing context of one of a folder's three collections, saying
|
|
114
|
+
* which of the three answers it got. cumin answers null both for a folder
|
|
115
|
+
* its lookup did not find (said as a warning) and for a lookup that failed
|
|
116
|
+
* (said as an error); the error said on the way tells them apart.
|
|
235
117
|
*
|
|
236
|
-
* @param
|
|
237
|
-
* @param
|
|
238
|
-
* @returns
|
|
239
|
-
*/
|
|
240
|
-
async function files_create(content, pathStr, options = {}) {
|
|
241
|
-
// A file is never written over a folder: CUBE would keep both, and
|
|
242
|
-
// removing either later damages the other (CUBE #732). A caller that has
|
|
243
|
-
// already checked the folder's names says so, and is not asked again.
|
|
244
|
-
if (options.folderClear !== true) {
|
|
245
|
-
const holders = await pathHolders_find(pathStr);
|
|
246
|
-
if (!holders.ok)
|
|
247
|
-
return false;
|
|
248
|
-
if (holders.value.includes('dir')) {
|
|
249
|
-
cumin_1.errorStack.stack_push('error', `Is a directory: a folder already holds ${pathStr}`);
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
try {
|
|
254
|
-
let uploadContent;
|
|
255
|
-
if (typeof content === 'string') {
|
|
256
|
-
uploadContent = new Blob([content]);
|
|
257
|
-
}
|
|
258
|
-
else if (Buffer.isBuffer(content)) {
|
|
259
|
-
uploadContent = new Blob([new Uint8Array(content)]); // Convert Buffer to Uint8Array for Blob
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
uploadContent = content; // Assume it's already a Blob
|
|
263
|
-
}
|
|
264
|
-
// Split path into directory and filename
|
|
265
|
-
const dir = path.posix.dirname(pathStr);
|
|
266
|
-
const name = path.posix.basename(pathStr);
|
|
267
|
-
const success = await cumin_1.chrisIO.file_upload(uploadContent, dir, name);
|
|
268
|
-
if (!success) {
|
|
269
|
-
cumin_1.errorStack.stack_push("error", `File upload failed for ${pathStr}.`);
|
|
270
|
-
}
|
|
271
|
-
return success;
|
|
272
|
-
}
|
|
273
|
-
catch (error) {
|
|
274
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
275
|
-
cumin_1.errorStack.stack_push("error", `File creation failed for ${pathStr}: ${msg}`);
|
|
276
|
-
return false;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Creates a new empty file at the specified path (like Unix touch).
|
|
281
|
-
* Optionally creates the file with specified content.
|
|
282
|
-
*
|
|
283
|
-
* @param path - The ChRIS path for the new file.
|
|
284
|
-
* @param content - Optional content to write to the file (string, Buffer, or Blob).
|
|
285
|
-
* @returns A Promise resolving to true on success, false on failure.
|
|
286
|
-
*/
|
|
287
|
-
async function files_touch(target, content) {
|
|
288
|
-
const fileContent = content ?? new Blob([""]);
|
|
289
|
-
// A projection's file (a feed's note under /proc) is written through the
|
|
290
|
-
// projection that owns it, never uploaded into CUBE's store as a file of
|
|
291
|
-
// that name.
|
|
292
|
-
const { vfsDispatcher } = await import("../vfs/dispatcher.js");
|
|
293
|
-
if (vfsDispatcher.path_isVirtual(target)) {
|
|
294
|
-
if (typeof content !== "string") {
|
|
295
|
-
cumin_1.errorStack.stack_push("error", `touch: ${target}: a projected file takes text (--withContents)`);
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
return (0, fond_1.vfsOutcome_convertToResult)(await vfsDispatcher.write(target, content), 'write', target).ok;
|
|
299
|
-
}
|
|
300
|
-
// CUBE's upload does not replace: uploading over a path that already holds
|
|
301
|
-
// a file leaves the OLD content in place and still reports success, so a
|
|
302
|
-
// caller writing content to a file it has written before was silently
|
|
303
|
-
// keeping the first version forever. Content given for a path that already
|
|
304
|
-
// exists is a REWRITE, so the file it holds is removed first and the
|
|
305
|
-
// failure to remove it is reported rather than written over.
|
|
306
|
-
if (content !== undefined) {
|
|
307
|
-
const mark = cumin_1.errorStack.checkpoint_mark();
|
|
308
|
-
const existing = await fileId_resolve(target);
|
|
309
|
-
if (!existing.ok) {
|
|
310
|
-
// Not being there is the ordinary case, not a fault to report.
|
|
311
|
-
cumin_1.errorStack.checkpoint_drain(mark);
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
const parent = path.posix.dirname(target);
|
|
315
|
-
const removed = await files_delete(existing.value, "files", parent);
|
|
316
|
-
if (!removed) {
|
|
317
|
-
cumin_1.errorStack.stack_push("error", `Could not rewrite ${target}: the file already there could not be removed.`);
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return await files_create(fileContent, target);
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Copies a single file from one ChRIS path to another.
|
|
326
|
-
*
|
|
327
|
-
* @param srcPath - The full path to the source file.
|
|
328
|
-
* @param destPath - The full path to the destination file (including filename).
|
|
329
|
-
* @returns A Promise resolving to true on success, false on failure.
|
|
330
|
-
*/
|
|
331
|
-
async function files_copy(srcPath, destPath, options = {}) {
|
|
332
|
-
try {
|
|
333
|
-
// 1. Resolve source file to get ID (needed for download)
|
|
334
|
-
const fileIdResult = await fileId_resolve(srcPath);
|
|
335
|
-
if (!fileIdResult.ok) {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
const fileId = fileIdResult.value;
|
|
339
|
-
// 2. Download content
|
|
340
|
-
const content = await cumin_1.chrisIO.file_download(fileId);
|
|
341
|
-
if (content === null) {
|
|
342
|
-
cumin_1.errorStack.stack_push("error", `Failed to download source file (ID: ${fileId}): ${srcPath}`);
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
// 3. Upload to destination
|
|
346
|
-
// files_create handles Blob/Buffer conversion and path splitting
|
|
347
|
-
const uploadSuccess = await files_create(content, destPath, options);
|
|
348
|
-
if (!uploadSuccess) {
|
|
349
|
-
const lastError = cumin_1.errorStack.stack_pop();
|
|
350
|
-
if (lastError) {
|
|
351
|
-
(0, cumin_1.runtimeOutput_err)(` Error: ${lastError.message}\n`);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return uploadSuccess;
|
|
355
|
-
}
|
|
356
|
-
catch (error) {
|
|
357
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
358
|
-
cumin_1.errorStack.stack_push("error", `Copy failed from ${srcPath} to ${destPath}: ${msg}`);
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Moves a file or directory by updating its path on the server.
|
|
364
|
-
*
|
|
365
|
-
* For directories, this performs a server-side rename without data transfer.
|
|
366
|
-
* For files, the file ID is resolved and the path is updated.
|
|
367
|
-
*
|
|
368
|
-
* @param srcPath - The source file or directory path.
|
|
369
|
-
* @param destPath - The target path. If an existing directory or trailing slash is provided,
|
|
370
|
-
* the source basename is appended.
|
|
371
|
-
* @returns Promise resolving to true on success, false on failure.
|
|
118
|
+
* @param assetName - The type of asset ('files', 'links', 'dirs').
|
|
119
|
+
* @param path - The ChRIS path.
|
|
120
|
+
* @returns What the making came to.
|
|
372
121
|
*/
|
|
373
|
-
async function
|
|
122
|
+
async function folderGroup_make(assetName, path) {
|
|
123
|
+
// A projection path (/proc, /net/pacs, /etc, /usr/share, or an ancestor of
|
|
124
|
+
// one) has no CUBE folder of files behind it: its provider lists it. Asking
|
|
125
|
+
// cumin to build a folder context for it cannot succeed, and a path walk
|
|
126
|
+
// that visits every ancestor turns that failure into a wall of identical errors.
|
|
127
|
+
if (dispatcher_js_1.vfsDispatcher.path_isVirtual(path))
|
|
128
|
+
return { kind: "missing" };
|
|
129
|
+
const context = FOLDER_CONTEXTS[assetName];
|
|
130
|
+
if (context === undefined)
|
|
131
|
+
return { kind: "failed", reason: `Unsupported asset type: ${assetName}`, said: false };
|
|
132
|
+
const mark = cumin_1.errorStack.checkpoint_mark();
|
|
374
133
|
try {
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
const finalDest = (destIsDir || destLooksDir)
|
|
379
|
-
? path.posix.join(destPath, path.posix.basename(srcPath))
|
|
380
|
-
: destPath;
|
|
381
|
-
// Nothing is moved onto a path something already holds: CUBE has no
|
|
382
|
-
// overwrite, and a folder and a file sharing one path damage each other
|
|
383
|
-
// when either is removed (CUBE #732).
|
|
384
|
-
const holders = await pathHolders_find(finalDest);
|
|
385
|
-
if (!holders.ok)
|
|
386
|
-
return false;
|
|
387
|
-
if (holders.value.length > 0) {
|
|
388
|
-
cumin_1.errorStack.stack_push('error', `Destination exists: ${finalDest} — mise cannot overwrite a ${holders.value[0]}; remove it first`);
|
|
389
|
-
return false;
|
|
390
|
-
}
|
|
391
|
-
if (srcIsDir) {
|
|
392
|
-
const moveResult = await cumin_1.chrisIO.folder_moveByPath(srcPath, finalDest);
|
|
393
|
-
return moveResult.ok && moveResult.value;
|
|
394
|
-
}
|
|
395
|
-
const fileIdResult = await fileId_resolve(srcPath);
|
|
396
|
-
if (!fileIdResult.ok) {
|
|
397
|
-
return false;
|
|
398
|
-
}
|
|
399
|
-
const moveResult = await cumin_1.chrisIO.file_moveById(fileIdResult.value, finalDest);
|
|
400
|
-
return moveResult.ok && moveResult.value;
|
|
134
|
+
const group = (await (0, cumin_1.objContext_create)(context, `folder:${path}`));
|
|
135
|
+
if (group)
|
|
136
|
+
return { kind: "made", group };
|
|
401
137
|
}
|
|
402
138
|
catch (error) {
|
|
403
|
-
|
|
404
|
-
cumin_1.errorStack.stack_push("error", `Move failed from ${srcPath} to ${destPath}: ${msg}`);
|
|
405
|
-
return false;
|
|
139
|
+
return { kind: "failed", reason: `Error creating ChRISEmbeddedResourceGroup for ${assetName}: ${String(error)}`, said: false };
|
|
406
140
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
* Uploads a local file or directory to ChRIS recursively.
|
|
410
|
-
*
|
|
411
|
-
* @param localPath - The local filesystem path.
|
|
412
|
-
* @param remotePath - The ChRIS destination path.
|
|
413
|
-
* @returns Promise<boolean> success.
|
|
414
|
-
*/
|
|
415
|
-
async function files_uploadPath(localPath, remotePath) {
|
|
416
|
-
return await cumin_1.chrisIO.uploadLocalPath(localPath, remotePath);
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Every kind of entry that holds a path, from its parent's three listings.
|
|
420
|
-
*
|
|
421
|
-
* CUBE lets a folder and a file share one path, and that is a hazard: a
|
|
422
|
-
* folder made over a file, then deleted, takes the file's record with it
|
|
423
|
-
* and every listing of the parent fails (CUBE #732, mise #462). Writers ask
|
|
424
|
-
* this first and refuse a path something else holds.
|
|
425
|
-
*
|
|
426
|
-
* @param target - The absolute CUBE path.
|
|
427
|
-
* @returns The kinds holding it (none, one, or more than one), or Err when
|
|
428
|
-
* the parent could not be read (the reason stacked): a probe that cannot
|
|
429
|
-
* answer counts the path as taken.
|
|
430
|
-
*/
|
|
431
|
-
async function pathHolders_find(target) {
|
|
432
|
-
const clean = target.length > 1 && target.endsWith('/') ? target.slice(0, -1) : target;
|
|
433
|
-
if (clean === '/' || clean === '')
|
|
434
|
-
return (0, cumin_1.Ok)(['dir']);
|
|
435
|
-
const parent = path.posix.dirname(clean);
|
|
436
|
-
const name = path.posix.basename(clean);
|
|
437
|
-
const holders = [];
|
|
438
|
-
const kinds = [['dirs', 'dir'], ['files', 'file'], ['links', 'link']];
|
|
439
|
-
for (const [asset, kind] of kinds) {
|
|
440
|
-
const mark = cumin_1.errorStack.checkpoint_mark();
|
|
441
|
-
const outcome = await files_listOutcome({ limit: 1000, offset: 0 }, asset, parent);
|
|
442
|
-
if (outcome.kind === 'refused') {
|
|
443
|
-
cumin_1.errorStack.stack_push('error', `Cannot check ${clean}: ${outcome.error.message}`);
|
|
444
|
-
return (0, cumin_1.Err)();
|
|
445
|
-
}
|
|
446
|
-
// A parent that is not there holds nothing: an answer, so what the
|
|
447
|
-
// lookup said on the way is not left to fail the command.
|
|
448
|
-
if (outcome.kind === 'missing')
|
|
449
|
-
cumin_1.errorStack.checkpoint_drain(mark);
|
|
450
|
-
if (outcome.kind !== 'listing')
|
|
451
|
-
continue;
|
|
452
|
-
// A folder row names itself by `path`; a file or link row by `fname`
|
|
453
|
-
// (a link's ends in `.chrislink`, and its `path` is where it points).
|
|
454
|
-
const held = (outcome.data.tableData ?? []).some((row) => {
|
|
455
|
-
const raw = String((kind === 'dir' ? row.path : row.fname) ?? '');
|
|
456
|
-
const entry = path.posix.basename(raw).replace(/\.chrislink$/, '');
|
|
457
|
-
return entry === name;
|
|
458
|
-
});
|
|
459
|
-
if (held)
|
|
460
|
-
holders.push(kind);
|
|
461
|
-
}
|
|
462
|
-
return (0, cumin_1.Ok)(holders);
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* What already holds a folder path, or the nearest parent of it that is
|
|
466
|
-
* held: a folder there ends the walk, as does a file or a link, which no
|
|
467
|
-
* folder may be made over or under (CUBE would make one anyway, and
|
|
468
|
-
* deleting it later takes the file's record with it, CUBE #732).
|
|
469
|
-
*
|
|
470
|
-
* @param folderPath - The folder's absolute path.
|
|
471
|
-
* @returns The first holder walking up, null when nothing up to the root
|
|
472
|
-
* holds any of it, or Err when a parent could not be read (stacked).
|
|
473
|
-
*/
|
|
474
|
-
async function folderPath_holder(folderPath) {
|
|
475
|
-
const target = folderPath.length > 1 && folderPath.endsWith('/') ? folderPath.slice(0, -1) : folderPath;
|
|
476
|
-
let at = target;
|
|
477
|
-
while (at !== '/' && at !== '') {
|
|
478
|
-
const holders = await pathHolders_find(at);
|
|
479
|
-
if (!holders.ok)
|
|
480
|
-
return (0, cumin_1.Err)();
|
|
481
|
-
if (holders.value.length > 0) {
|
|
482
|
-
const holder = holders.value.includes('dir') ? 'dir' : holders.value[0];
|
|
483
|
-
return (0, cumin_1.Ok)({ path: at, holder, atTarget: at === target });
|
|
484
|
-
}
|
|
485
|
-
at = path.posix.dirname(at);
|
|
486
|
-
}
|
|
487
|
-
return (0, cumin_1.Ok)(null);
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Whether a folder may be made at a path: no file or link holds it or any
|
|
491
|
-
* parent of it. Says why not on the error stack.
|
|
492
|
-
*
|
|
493
|
-
* @param folderPath - The folder's absolute path.
|
|
494
|
-
* @returns True when it may.
|
|
495
|
-
*/
|
|
496
|
-
async function folderPath_clear(folderPath) {
|
|
497
|
-
const first = await folderPath_holder(folderPath);
|
|
498
|
-
if (!first.ok)
|
|
499
|
-
return false;
|
|
500
|
-
if (first.value === null || first.value.holder === 'dir')
|
|
501
|
-
return true;
|
|
502
|
-
cumin_1.errorStack.stack_push('error', first.value.atTarget
|
|
503
|
-
? `File exists: a ${first.value.holder} already holds ${first.value.path}`
|
|
504
|
-
: `Not a directory: a ${first.value.holder} holds ${first.value.path}`);
|
|
505
|
-
return false;
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Creates a new folder (directory) at the specified ChRIS path.
|
|
509
|
-
*
|
|
510
|
-
* @param folderPath - The full ChRIS path for the new folder.
|
|
511
|
-
* @param options - `cleared` when the caller has already found no file or link holding the path or a parent of it.
|
|
512
|
-
* @returns A Promise resolving to true on success, false on failure.
|
|
513
|
-
*/
|
|
514
|
-
async function files_mkdir(folderPath, options = {}) {
|
|
515
|
-
// A folder is never made over a file: deleting it later would take the
|
|
516
|
-
// file's record with it (CUBE #732). A caller that has looked already says so.
|
|
517
|
-
if (options.cleared !== true && !(await folderPath_clear(folderPath)))
|
|
518
|
-
return false;
|
|
519
|
-
const result = await cumin_1.chrisIO.folder_create(folderPath);
|
|
520
|
-
if (!result.ok) {
|
|
521
|
-
return false;
|
|
522
|
-
}
|
|
523
|
-
// result.value is true if created, false if already exists
|
|
524
|
-
// Both cases are considered success
|
|
525
|
-
return true;
|
|
141
|
+
const failed = cumin_1.errorStack.stack_getAll().slice(mark).find((message) => message.type === "error")?.message;
|
|
142
|
+
return failed === undefined ? { kind: "missing" } : { kind: "failed", reason: failed, said: true };
|
|
526
143
|
}
|
|
527
144
|
/**
|
|
528
145
|
* Creates a ChRISEmbeddedResourceGroup for a specific asset type (files, links, dirs).
|
|
@@ -533,45 +150,24 @@ async function files_mkdir(folderPath, options = {}) {
|
|
|
533
150
|
* @returns A Promise resolving to a ChRISEmbeddedResourceGroup instance, or null on error.
|
|
534
151
|
*/
|
|
535
152
|
async function files_getGroup(assetName, path) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
break;
|
|
555
|
-
case "links":
|
|
556
|
-
chrisFileSystemGroup = (await (0, cumin_1.objContext_create)("ChRISLinksContext", `folder:${path}`));
|
|
557
|
-
break;
|
|
558
|
-
case "dirs":
|
|
559
|
-
chrisFileSystemGroup = (await (0, cumin_1.objContext_create)("ChRISDirsContext", `folder:${path}`));
|
|
560
|
-
break;
|
|
561
|
-
default:
|
|
562
|
-
cumin_1.errorStack.stack_push("error", `Unsupported asset type: ${assetName}`);
|
|
563
|
-
return null;
|
|
564
|
-
}
|
|
565
|
-
if (!chrisFileSystemGroup) {
|
|
566
|
-
cumin_1.errorStack.stack_push("error", `Failed to initialize ChRIS context for ${assetName} at ${path}`);
|
|
567
|
-
return null;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
catch (error) {
|
|
571
|
-
cumin_1.errorStack.stack_push("error", `Error creating ChRISEmbeddedResourceGroup for ${assetName}: ${error}`);
|
|
572
|
-
return null;
|
|
573
|
-
}
|
|
574
|
-
return chrisFileSystemGroup;
|
|
153
|
+
const at = path ?? await folderCurrent_get();
|
|
154
|
+
const made = await folderGroup_make(assetName, at);
|
|
155
|
+
if (made.kind === "made")
|
|
156
|
+
return made.group;
|
|
157
|
+
if (made.kind === "failed" && !made.said)
|
|
158
|
+
cumin_1.errorStack.stack_push("error", made.reason);
|
|
159
|
+
else if (!dispatcher_js_1.vfsDispatcher.path_isVirtual(at))
|
|
160
|
+
cumin_1.errorStack.stack_push("error", `Failed to initialize ChRIS context for ${assetName} at ${at}`);
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The session's current folder, the root when it has none.
|
|
165
|
+
*
|
|
166
|
+
* @returns The folder.
|
|
167
|
+
*/
|
|
168
|
+
async function folderCurrent_get() {
|
|
169
|
+
const fileContext = await cumin_1.chrisContext.current_get(cumin_1.Context.ChRISfolder);
|
|
170
|
+
return fileContext ? fileContext : "/";
|
|
575
171
|
}
|
|
576
172
|
/**
|
|
577
173
|
* List files, links, or directories based on options.
|
|
@@ -609,6 +205,11 @@ async function files_listAll(options, assetName = "files", path) {
|
|
|
609
205
|
* an empty folder, a missing one and a refusal are told apart. A caller that
|
|
610
206
|
* renders a listing must use this — "nothing here" and "I could not read it"
|
|
611
207
|
* look identical to an operator otherwise, and only one of them is true.
|
|
208
|
+
* `empty` is answered only for a first page actually received, a list
|
|
209
|
+
* carrying its items, with none in it; a walk that fetched no such page
|
|
210
|
+
* (never bound, or answered with no list) is `refused`. A lookup of the
|
|
211
|
+
* folder that failed (an error said on the way) is `refused`, never
|
|
212
|
+
* `missing`.
|
|
612
213
|
*
|
|
613
214
|
* @param options - Search options (limit and offset are managed internally).
|
|
614
215
|
* @param assetName - The type of asset to list ('files', 'links', 'dirs').
|
|
@@ -616,15 +217,75 @@ async function files_listAll(options, assetName = "files", path) {
|
|
|
616
217
|
* @returns Which answer the folder gave.
|
|
617
218
|
*/
|
|
618
219
|
async function files_listOutcome(options, assetName = "files", path) {
|
|
220
|
+
const made = await folderGroup_make(assetName, path ?? await folderCurrent_get());
|
|
221
|
+
if (made.kind === "missing")
|
|
222
|
+
return { kind: "missing" };
|
|
223
|
+
if (made.kind === "failed")
|
|
224
|
+
return { kind: "refused", error: new Error(made.reason) };
|
|
225
|
+
const group = made.group;
|
|
226
|
+
try {
|
|
227
|
+
const data = await group.asset.resources_getAll(options);
|
|
228
|
+
if (data !== null)
|
|
229
|
+
return { kind: "listing", data };
|
|
230
|
+
if (group.asset.firstPage_isWhole())
|
|
231
|
+
return { kind: "empty" };
|
|
232
|
+
return { kind: "refused", error: new Error(`the ${assetName} of ${path ?? "the folder"} did not come as a list`) };
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
return { kind: "refused", error: error instanceof Error ? error : new Error(String(error)) };
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Whether a path is a projection's (a mount's, or a folder of mounts):
|
|
240
|
+
* no folder of CUBE's files stands behind it.
|
|
241
|
+
*
|
|
242
|
+
* @param path - The absolute path.
|
|
243
|
+
* @returns True when a mount owns it, or it is a parent of one.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* if (path_isProjection('/net')) return Ok([]);
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
function path_isProjection(path) {
|
|
251
|
+
return dispatcher_js_1.vfsDispatcher.path_isVirtual(path);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Lists every file, link or directory of a folder, or says it could not.
|
|
255
|
+
*
|
|
256
|
+
* The strict counterpart of {@link files_listOutcome}, for an act that
|
|
257
|
+
* destroys or overwrites on the strength of what a folder holds. That
|
|
258
|
+
* listing is made for showing: a page it cannot read ends its walk with the
|
|
259
|
+
* rows it has, and an answer that is no list at all reads as `empty`. Here
|
|
260
|
+
* the whole collection is walked (cumin's `resources_getWhole`), and a page
|
|
261
|
+
* that could not be fetched, is not a list, or carries no items is `refused`.
|
|
262
|
+
*
|
|
263
|
+
* @param assetName - The type of asset to list ('files', 'links', 'dirs').
|
|
264
|
+
* @param path - The absolute ChRIS path of the folder.
|
|
265
|
+
* @param walk - `hrefs`: keep each row's own address, as `href`.
|
|
266
|
+
* @returns `listing` with every row (and `incomplete` when the server's
|
|
267
|
+
* count says rows are missing, even with none in hand), `empty` when the
|
|
268
|
+
* folder answered in full and holds none of this kind, `missing` when no
|
|
269
|
+
* listing could be made for the path, `refused` when the walk failed.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```ts
|
|
273
|
+
* const files: ListingOutcome = await files_listWhole('files', '/home/ada/uploads');
|
|
274
|
+
* const proved: boolean = files.kind === 'listing' || files.kind === 'empty';
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
async function files_listWhole(assetName, path, walk = {}) {
|
|
619
278
|
const group = await files_getGroup(assetName, path);
|
|
620
279
|
if (!group) {
|
|
621
280
|
return { kind: "missing" };
|
|
622
281
|
}
|
|
623
282
|
try {
|
|
624
|
-
const data = await group.asset.
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
283
|
+
const data = await group.asset.resources_getWhole(undefined, walk);
|
|
284
|
+
// A walk the server's own count calls short is never "empty": it is
|
|
285
|
+
// answered as the listing it is, its `incomplete` there to be read.
|
|
286
|
+
if (data.incomplete !== undefined)
|
|
287
|
+
return { kind: "listing", data };
|
|
288
|
+
return data.tableData.length === 0 ? { kind: "empty" } : { kind: "listing", data };
|
|
628
289
|
}
|
|
629
290
|
catch (error) {
|
|
630
291
|
return { kind: "refused", error: error instanceof Error ? error : new Error(String(error)) };
|
|
@@ -645,49 +306,35 @@ async function fileFields_get(assetName = "files") {
|
|
|
645
306
|
return results ? results.fields : null;
|
|
646
307
|
}
|
|
647
308
|
/**
|
|
648
|
-
* Deletes a file, link, or directory by its ID
|
|
309
|
+
* Deletes a file, link, or directory by its ID, at CUBE's own address for
|
|
310
|
+
* it, and waits to see it gone: done only once it answers that it is gone
|
|
311
|
+
* (`holder_remove`). Nothing is listed to find it.
|
|
649
312
|
*
|
|
650
313
|
* @param id - The ID of the asset to delete.
|
|
651
314
|
* @param assetName - The type of asset ('files', 'links', 'dirs').
|
|
652
|
-
* @returns
|
|
315
|
+
* @returns True when it was seen gone; false otherwise, with the reason on
|
|
316
|
+
* the error stack (a delete accepted and not seen done is false).
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* const removed: boolean = await files_delete(41, 'files');
|
|
321
|
+
* ```
|
|
653
322
|
*/
|
|
654
|
-
async function files_delete(id, assetName = "files"
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
// the parent. Callers that know the path must pass it.
|
|
659
|
-
const group = await files_getGroup(assetName, parentPath);
|
|
660
|
-
if (!group) {
|
|
323
|
+
async function files_delete(id, assetName = "files") {
|
|
324
|
+
const kind = { files: 'file', links: 'link', dirs: 'dir' }[assetName];
|
|
325
|
+
if (kind === undefined) {
|
|
326
|
+
cumin_1.errorStack.stack_push("error", `Unsupported asset type: ${assetName}`);
|
|
661
327
|
return false;
|
|
662
328
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
return
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
// the id against the loaded list; load it explicitly so deleting works
|
|
673
|
-
// without depending on a prior listing of the same folder.
|
|
674
|
-
await group.asset.resources_getAll({ limit: 1000, offset: 0 });
|
|
675
|
-
return await group.asset.resourceItem_delete(id);
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Deletes a folder (and its contents) addressed by CUBE path.
|
|
679
|
-
*
|
|
680
|
-
* The path-addressed complement to `files_delete`: no id lookup, no ambient
|
|
681
|
-
* folder context, and the call returns only once the CUBE confirms the
|
|
682
|
-
* folder no longer resolves (server-side deletion is asynchronous).
|
|
683
|
-
*
|
|
684
|
-
* @param path - The folder's CUBE path (e.g. `/home/alice/scratch`).
|
|
685
|
-
* @param options - `timeoutMs` bounds the disappearance poll (default 10s).
|
|
686
|
-
* @returns True when the folder is verifiably gone (or never existed).
|
|
687
|
-
*/
|
|
688
|
-
async function folderByPath_delete(path, options = {}) {
|
|
689
|
-
const result = await cumin_1.chrisIO.folder_deleteByPath(path, options);
|
|
690
|
-
return result.ok;
|
|
329
|
+
const bound = await cumin_1.chrisIO.holderClient_bind();
|
|
330
|
+
if (!bound.ok)
|
|
331
|
+
return false;
|
|
332
|
+
const { holder_remove } = await import('./removal.js');
|
|
333
|
+
const removed = await holder_remove(bound.value, { kind, id, href: null }, `${assetName} ID ${String(id)}`);
|
|
334
|
+
if (removed.kind === 'removed')
|
|
335
|
+
return true;
|
|
336
|
+
cumin_1.errorStack.stack_push("error", removed.kind === 'unconfirmed' ? removed.reason : removed.kind === 'refused' ? removed.reason ?? `Cannot remove ${assetName} ID ${String(id)}: ${removed.errno}` : `Cannot remove ${assetName} ID ${String(id)}`);
|
|
337
|
+
return false;
|
|
691
338
|
}
|
|
692
339
|
/**
|
|
693
340
|
* Creates a ChRISEmbeddedResourceGroup for a single file.
|
|
@@ -712,16 +359,18 @@ async function files_getSingle(path) {
|
|
|
712
359
|
return chrisFilesGroup;
|
|
713
360
|
}
|
|
714
361
|
/**
|
|
715
|
-
*
|
|
362
|
+
* Answers that a file cannot be shared by its id from here.
|
|
716
363
|
*
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
364
|
+
* Sharing by file id is not offered: permissions are set through `setfacl`.
|
|
365
|
+
* This says so, and shares nothing.
|
|
366
|
+
*
|
|
367
|
+
* @param fileId - The ID of the file asked about.
|
|
368
|
+
* @param _options - The sharing options asked for; none is acted on.
|
|
369
|
+
* @returns Always false, with the reason on the error stack.
|
|
720
370
|
*/
|
|
721
|
-
async function files_share(fileId,
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
return Promise.resolve(true);
|
|
371
|
+
async function files_share(fileId, _options) {
|
|
372
|
+
cumin_1.errorStack.stack_push("error", `Sharing file ${fileId} by its id is not offered here: nothing was shared. Permissions are set with setfacl.`);
|
|
373
|
+
return false;
|
|
725
374
|
}
|
|
726
375
|
/**
|
|
727
376
|
* Retrieves the content of a file by its path.
|