-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add upload file from URL functionality #8
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughA new "Upload File From URL" operation ( Changes
Sequence DiagramsequenceDiagram
participant User
participant PostizNode as "Postiz Node"
participant Validator as "URL Validator"
participant PostizAPI as "Postiz API"
User->>PostizNode: execute operation=uploadFileFromURL with url
PostizNode->>Validator: validate URL format & protocol (http/https)
alt valid URL
PostizNode->>PostizAPI: POST /upload-from-url { url }
PostizAPI-->>PostizNode: 2xx response
PostizNode-->>User: return success
else invalid URL
Validator-->>PostizNode: invalid
PostizNode-->>User: throw NodeOperationError
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
nodes/Postiz/Postiz.node.ts (1)
766-777: Consider more robust URL validation.The current validation only checks for the http:// or https:// prefix, which allows malformed URLs like "http://" or "https://incomplete" to pass. Using the URL constructor provides better validation.
Apply this diff for more comprehensive validation:
if (operation === 'uploadFileFromURL') { const url = this.getNodeParameter('url', i) as string; - // Check if it's a valid URL - if (!url.startsWith('http://') && !url.startsWith('https://')) { + + // Validate URL format + try { + const parsedUrl = new URL(url); + if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') { + throw new Error('Invalid protocol'); + } + } catch { throw new NodeOperationError( this.getNode(), - `URL is not a valid URL: ${url}`, + `Invalid URL format. URL must be a valid http:// or https:// address`, { itemIndex: i }, ); } + responseData = await postizApiRequest.call(this, 'POST', '/upload-from-url', { url }); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
nodes/Postiz/Postiz.node.ts(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
nodes/Postiz/Postiz.node.ts (1)
nodes/Postiz/GenericFunctions.ts (1)
postizApiRequest(13-42)
🪛 ESLint
nodes/Postiz/Postiz.node.ts
[error] 77-77: Change to title case [autofixable]
(n8n-nodes-base/node-param-display-name-miscased)
🔇 Additional comments (2)
nodes/Postiz/Postiz.node.ts (2)
600-613: LGTM!The URL parameter is properly configured with appropriate display conditions, type, and description.
776-776: Code matches Postiz API specification.The endpoint path
/upload-from-url, HTTP methodPOST, and payload structure{ url }all match the official Postiz API documentation. No changes required.
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.
Actionable comments posted: 0
♻️ Duplicate comments (1)
nodes/Postiz/Postiz.node.ts (1)
76-81: Address the linting errors for display name and action casing.The ESLint linter is flagging casing issues that were also noted in previous review comments:
- Line 77: Display name should be in title case:
'Upload File From URL'(capitalize "From")- Line 80: Action should follow sentence case convention per n8n guidelines
Apply this diff to fix the casing:
{ - name: 'Upload File from URL', + name: 'Upload File From URL', value: 'uploadFileFromURL', description: 'Upload a file to Postiz from URL', - action: 'Upload a file to Postiz from URL', + action: 'Upload a file to Postiz from url', },
🧹 Nitpick comments (1)
nodes/Postiz/Postiz.node.ts (1)
766-777: Consider more robust URL validation.The current validation only checks if the URL starts with
http://orhttps://, which prevents obvious errors but allows malformed URLs through (e.g.,http://with nothing after).Consider using the URL constructor for more comprehensive validation:
if (operation === 'uploadFileFromURL') { const url = this.getNodeParameter('url', i) as string; - // Check if it's a valid URL - if (!url.startsWith('http://') && !url.startsWith('https://')) { + // Validate URL format + try { + const parsedUrl = new URL(url); + if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') { + throw new Error('Invalid protocol'); + } + } catch { throw new NodeOperationError( this.getNode(), - `URL is not a valid URL: ${url}`, + `Invalid URL format: ${url}. Please provide a valid HTTP or HTTPS URL.`, { itemIndex: i }, ); } responseData = await postizApiRequest.call(this, 'POST', '/upload-from-url', { url }); }This approach catches malformed URLs and provides clearer error messages.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
nodes/Postiz/Postiz.node.ts(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
nodes/Postiz/Postiz.node.ts (1)
nodes/Postiz/GenericFunctions.ts (1)
postizApiRequest(13-42)
🪛 ESLint
nodes/Postiz/Postiz.node.ts
[error] 44-44: Change to sentence case [autofixable]
(n8n-nodes-base/node-param-operation-option-action-miscased)
[error] 74-74: Change to sentence case [autofixable]
(n8n-nodes-base/node-param-operation-option-action-miscased)
[error] 77-77: Change to title case [autofixable]
(n8n-nodes-base/node-param-display-name-miscased)
[error] 80-80: Change to sentence case [autofixable]
(n8n-nodes-base/node-param-operation-option-action-miscased)
🔇 Additional comments (2)
nodes/Postiz/Postiz.node.ts (2)
44-44: Good fix for brand consistency.Correctly capitalizing "Postiz" in the action strings improves consistency across the node.
Also applies to: 74-74
600-613: Well-structured parameter definition.The URL parameter is properly configured with appropriate visibility controls and clear description.
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.
Actionable comments posted: 2
♻️ Duplicate comments (1)
nodes/Postiz/Postiz.node.ts (1)
76-81: Fix casing issues in operation definition.These issues were previously flagged but remain unresolved. ESLint confirms:
- Line 77
nameshould use title case: "Upload File From URL" (capitalize "From")- Line 80
actionshould use sentence case: "Upload a file to postiz from URL" (lowercase "postiz")Apply this diff:
{ - name: 'Upload File from URL', + name: 'Upload File From URL', value: 'uploadFileFromURL', description: 'Upload a file to Postiz from URL', - action: 'Upload a file to Postiz from URL', + action: 'Upload a file to postiz from URL', },As per coding guidelines (ESLint: n8n-nodes-base/node-param-display-name-miscased, n8n-nodes-base/node-param-operation-option-action-miscased)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
nodes/Postiz/Postiz.node.ts(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
nodes/Postiz/Postiz.node.ts (1)
nodes/Postiz/GenericFunctions.ts (1)
postizApiRequest(13-42)
🪛 ESLint
nodes/Postiz/Postiz.node.ts
[error] 44-44: Change to sentence case [autofixable]
(n8n-nodes-base/node-param-operation-option-action-miscased)
[error] 74-74: Change to sentence case [autofixable]
(n8n-nodes-base/node-param-operation-option-action-miscased)
[error] 77-77: Change to title case [autofixable]
(n8n-nodes-base/node-param-display-name-miscased)
[error] 80-80: Change to sentence case [autofixable]
(n8n-nodes-base/node-param-operation-option-action-miscased)
[error] 772-772: Use ApplicationError, NodeApiError, NodeOperationError, or TriggerCloseError` [non-autofixable]
(n8n-nodes-base/node-execute-block-wrong-error-thrown)
🔇 Additional comments (1)
nodes/Postiz/Postiz.node.ts (1)
600-613: LGTM!The URL parameter is properly defined with appropriate display conditions, required validation, and clear description.
What kind of change does this PR introduce?
This PR adds the ability to upload files from URLs to Postiz, like it's documented in the API documentation.
https://docs.postiz.com/public-api#upload-a-new-file-from-an-existing-url
Why was this change needed?
Currently, the only way to upload files to Postiz in n8n is by using a custom http request node.
Other information:
Summary by CodeRabbit
New Features
Bug Fixes