-
Notifications
You must be signed in to change notification settings - Fork 0
add ability to recognize new files by time stamp or size changes #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ module.exports = function (RED) { | |
| node.depthProp = config.depth; | ||
| node.depthPropType = config.depthType; | ||
| node.returnType = config.returnType || "files"; // files|folders|all | ||
| node.detectionMode = config.detectionMode || "metadata"; // name|metadata | ||
|
|
||
| // Poll frequency configuration | ||
| const unitMultipliers = { | ||
|
|
@@ -54,8 +55,26 @@ module.exports = function (RED) { | |
| return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${d.toLocaleTimeString()}`; | ||
| }; | ||
|
|
||
| // Internal cache of previously seen object names | ||
| let previousNamesSet = null; | ||
| // Helper to create unique identifier for a file | ||
| // Mode "name": Only uses filename (original behavior - only detect truly new files) | ||
| // Mode "metadata": Uses name + lastModified/size/etag (detect changes to existing files) | ||
| const getFileIdentifier = (item) => { | ||
| if (node.detectionMode === "name") { | ||
| return item.name; | ||
| } | ||
| // metadata mode (default) | ||
| const parts = [item.name]; | ||
| if (item.lastModified) parts.push(item.lastModified); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We think that |
||
| if (item.size != null) parts.push(String(item.size)); | ||
| if (item.etag) parts.push(item.etag); | ||
| return parts.join("|"); | ||
| }; | ||
|
|
||
| // Internal cache of previously seen objects | ||
| // Store both identifiers (for change detection) and a map by name (for deletion detection) | ||
| let previousIdentifiersSet = null; | ||
| let previousItemsMap = null; | ||
| let intervalId = null; | ||
|
|
||
| // Polling function | ||
| const executePoll = async () => { | ||
|
|
@@ -78,28 +97,57 @@ module.exports = function (RED) { | |
| files: result.files.map((it) => `${result.resourceRef}/${it}`), | ||
| }; | ||
|
|
||
| // Second output: only new items since previous poll | ||
| // Build current state for comparison | ||
| const currentIdentifiers = new Set(result.items.map(getFileIdentifier)); | ||
| const currentNameToItem = new Map(result.items.map((it) => [it.name, it])); | ||
|
|
||
| // Second output: new or modified items since previous poll | ||
| let msgNew = null; | ||
| if (previousNamesSet) { | ||
| const newItems = result.items.filter((it) => !previousNamesSet.has(it.name)); | ||
| if (newItems.length) { | ||
| if (previousIdentifiersSet) { | ||
| const newOrModified = result.items.filter((it) => !previousIdentifiersSet.has(getFileIdentifier(it))); | ||
| if (newOrModified.length) { | ||
| msgNew = { | ||
| ...pollMsg, | ||
| payload: { | ||
| files: newOrModified, | ||
| resourceType: result.resourceType, | ||
| resourceRef: result.resourceRef, | ||
| provider: result.provider, | ||
| }, | ||
| files: newOrModified.map((it) => `${result.resourceRef}/${it.name}`), | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| // Third output: deleted items (present in previous poll but not current) | ||
| let msgDeleted = null; | ||
| if (previousItemsMap) { | ||
| const deletedItems = []; | ||
| for (const [name, item] of previousItemsMap.entries()) { | ||
| if (!currentNameToItem.has(name)) { | ||
| deletedItems.push(item); | ||
| } | ||
| } | ||
| if (deletedItems.length) { | ||
| msgDeleted = { | ||
| ...pollMsg, | ||
| payload: { | ||
| files: newItems, | ||
| files: deletedItems, | ||
| resourceType: result.resourceType, | ||
| resourceRef: result.resourceRef, | ||
| provider: result.provider, | ||
| }, | ||
| files: newItems.map((it) => `${result.resourceRef}/${it.name}`), | ||
| files: deletedItems.map((it) => `${result.resourceRef}/${it.name}`), | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| // Update cache | ||
| previousNamesSet = new Set(result.items.map((it) => it.name)); | ||
| previousIdentifiersSet = currentIdentifiers; | ||
| previousItemsMap = currentNameToItem; | ||
|
|
||
| node.status({ fill: "green", shape: "dot", text: `${result.items.length} items: ${formatDateTime()}` }); | ||
| node.send([msgAll, msgNew]); | ||
| node.send([msgAll, msgNew, msgDeleted]); | ||
| } catch (err) { | ||
| node.error(`Seqera datalink poll failed: ${err.message}`); | ||
| node.status({ fill: "red", shape: "dot", text: `error: ${formatDateTime()}` }); | ||
|
|
@@ -109,7 +157,7 @@ module.exports = function (RED) { | |
| // Start the polling interval | ||
| if (node.seqeraConfig && config.dataLinkName && config.dataLinkName.trim() !== "") { | ||
| const intervalMs = node.pollFrequencySec * 1000; | ||
| const intervalId = setInterval(executePoll, intervalMs); | ||
| intervalId = setInterval(executePoll, intervalMs); | ||
| // run once immediately | ||
| executePoll(); | ||
| } | ||
|
|
@@ -146,6 +194,7 @@ module.exports = function (RED) { | |
| returnType: { value: "files" }, | ||
| // poll specific | ||
| pollFrequency: { value: "15" }, | ||
| detectionMode: { value: "metadata" }, | ||
| }, | ||
| }); | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this one is a bit obvious