-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatalink-list.js
More file actions
99 lines (90 loc) · 3.67 KB
/
Copy pathdatalink-list.js
File metadata and controls
99 lines (90 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// New node implementation for seqera-datalink-list
module.exports = function (RED) {
const { handleDatalinkAutoComplete } = require("./_utils");
// Add HTTP endpoint for datalink auto-complete
RED.httpAdmin.get("/admin/seqera/datalinks/:nodeId", (req, res) => {
handleDatalinkAutoComplete(RED, req, res);
});
function SeqeraDatalinkListNode(config) {
RED.nodes.createNode(this, config);
const node = this;
// Store typedInput properties
node.dataLinkNameProp = config.dataLinkName;
node.dataLinkNamePropType = config.dataLinkNameType;
node.basePathProp = config.basePath;
node.basePathPropType = config.basePathType;
node.prefixProp = config.prefix;
node.prefixPropType = config.prefixType;
node.patternProp = config.pattern;
node.patternPropType = config.patternType;
node.maxResultsProp = config.maxResults;
node.maxResultsPropType = config.maxResultsType;
node.workspaceIdProp = config.workspaceId;
node.workspaceIdPropType = config.workspaceIdType;
node.baseUrlProp = config.baseUrl;
node.baseUrlPropType = config.baseUrlType;
node.depthProp = config.depth;
node.depthPropType = config.depthType;
node.returnType = config.returnType || "files"; // files|folders|all
// Reference Seqera config node
node.seqeraConfig = RED.nodes.getNode(config.seqera);
node.defaultBaseUrl = (node.seqeraConfig && node.seqeraConfig.baseUrl) || "https://api.cloud.seqera.io";
node.credentials = RED.nodes.getCredentials(node.id);
const datalinkUtils = require("./datalink-utils");
// Helper to format date as yyyy-mm-dd HH:MM:SS
const formatDateTime = () => {
const d = new Date();
const pad = (n) => n.toString().padStart(2, "0");
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${d.toLocaleTimeString()}`;
};
node.on("input", async function (msg, send, done) {
node.status({ fill: "blue", shape: "ring", text: `listing: ${formatDateTime()}` });
try {
const result = await datalinkUtils.listDataLink(RED, node, msg);
const outMsg = {
...msg,
payload: {
files: result.items,
resourceType: result.resourceType,
resourceRef: result.resourceRef,
provider: result.provider,
},
files: result.files.map((it) => `${result.resourceRef}/${it}`),
};
node.status({ fill: "green", shape: "dot", text: `${result.items.length} items: ${formatDateTime()}` });
send(outMsg);
if (done) done();
} catch (err) {
node.error(`Seqera datalink list failed: ${err.message}`, msg);
node.status({ fill: "red", shape: "dot", text: `error: ${formatDateTime()}` });
return;
}
});
}
RED.nodes.registerType("seqera-datalink-list", SeqeraDatalinkListNode, {
credentials: { token: { type: "password" } },
defaults: {
name: { value: "" },
seqera: { value: "", type: "seqera-config", required: true },
dataLinkName: { value: "dataLinkName" },
dataLinkNameType: { value: "str" },
basePath: { value: "" },
basePathType: { value: "str" },
prefix: { value: "" },
prefixType: { value: "str" },
pattern: { value: "" },
patternType: { value: "str" },
maxResults: { value: "100" },
maxResultsType: { value: "num" },
workspaceId: { value: "workspaceId" },
workspaceIdType: { value: "str" },
baseUrl: { value: "baseUrl" },
baseUrlType: { value: "str" },
token: { value: "token" },
tokenType: { value: "str" },
depth: { value: "0" },
depthType: { value: "num" },
returnType: { value: "files" },
},
});
};