-
Couldn't load subscription status.
- Fork 5.5k
10808 bitportio #18700
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
Merged
Merged
10808 bitportio #18700
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import app from "../../bitport.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "bitport-add-item", | ||
| name: "Add Item", | ||
| description: "Add new torrent. [See the documentation](https://bitport.io/api/index.html?url=/v2/transfers&method=POST)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| props: { | ||
| app, | ||
| torrent: { | ||
| type: "string", | ||
| label: "Torrent", | ||
| description: "A URL linking to a .torrent file or a magnet link", | ||
| }, | ||
| folderCode: { | ||
| propDefinition: [ | ||
| app, | ||
| "folderCode", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.addItem({ | ||
| $, | ||
| data: { | ||
| torrent: this.torrent, | ||
| folder_code: this.folderCode, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully added torrent!"); | ||
| return response; | ||
| }, | ||
| }; |
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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import app from "../../bitport.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "bitport-search", | ||
| name: "Search", | ||
| description: "Searches folders and files in the cloud and sorts them by name. [See the documentation](https://bitport.io/api/index.html?url=/v2/search/%3Cterm%3E)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| props: { | ||
| app, | ||
| query: { | ||
| type: "string", | ||
| label: "Query", | ||
| description: "The query to search for", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { data } = await this.app.search({ | ||
| $, | ||
| query: this.query, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully found for ${data.folders.length} folder${data.folders.length > 1 | ||
| ? "s" | ||
| : ""} and ${data.files.length} file${data.files.length > 1 | ||
| ? "s" | ||
| : ""}`); | ||
| return data; | ||
| }, | ||
| }; |
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 |
|---|---|---|
| @@ -1,11 +1,66 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| import { prepareList } from "./common/utils.mjs"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "bitport", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| folderCode: { | ||
| type: "string", | ||
| label: "Folder Code", | ||
| description: "The code of the folder to add the item to", | ||
| async options() { | ||
| const { data } = await this.listFolders(); | ||
|
|
||
| return prepareList({ | ||
| items: data, | ||
| }).map((item) => ({ | ||
| label: item.fullName, | ||
| value: item.code, | ||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _apiUrl() { | ||
| return "https://api.bitport.io/v2"; | ||
| }, | ||
| _getHeaders() { | ||
| return { | ||
| "Authorization": `Bearer ${this.$auth.oauth_access_token}`, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._apiUrl()}${path}`, | ||
| headers: this._getHeaders(), | ||
| ...opts, | ||
| }); | ||
| }, | ||
| search({ | ||
| query, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/search/${query}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listFolders() { | ||
| return this._makeRequest({ | ||
| path: "/cloud/byPath", | ||
| params: { | ||
| scope: "recursive", | ||
| }, | ||
| }); | ||
| }, | ||
| addItem(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/transfers", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| export const prepareList = ({ | ||
| items, parentName = "", filesOnly = false, | ||
| }) => { | ||
| const itemsArray = []; | ||
| for (const item of items) { | ||
| const fullName = `${parentName}/${item.name}`; | ||
|
|
||
| if (filesOnly) { | ||
| itemsArray.push( | ||
| ...item.files, | ||
| ); | ||
| } else { | ||
| itemsArray.push({ | ||
| fullName, | ||
| ...item, | ||
| }); | ||
| } | ||
|
|
||
| itemsArray.push(...prepareList({ | ||
| items: item.folders, | ||
| parentName: fullName, | ||
| filesOnly, | ||
| })); | ||
| } | ||
|
|
||
| return itemsArray; | ||
| }; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/bitport", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Bitport Components", | ||
| "main": "bitport.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import bitport from "../../bitport.app.mjs"; | ||
| import { prepareList } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| bitport, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| folderCode: { | ||
| propDefinition: [ | ||
| bitport, | ||
| "folderCode", | ||
| ], | ||
| withLabel: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastDate() { | ||
| return this.db.get("lastDate") || 0; | ||
| }, | ||
| _setLastDate(lastDate) { | ||
| this.db.set("lastDate", lastDate); | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| getFilter() { | ||
| return false; | ||
| }, | ||
| async emitEvent(maxResults = false) { | ||
| const lastDate = this._getLastDate(); | ||
|
|
||
| const bufferObj = Buffer.from(this.folderCode.label, "utf8"); | ||
| const base64String = bufferObj.toString("base64"); | ||
|
|
||
| const { data: response } = await this.bitport.listFolders({ | ||
| maxResults, | ||
| params: { | ||
| folderPath: base64String, | ||
| }, | ||
| }); | ||
|
|
||
| let items = prepareList({ | ||
| items: response, | ||
| filesOnly: true, | ||
| }); | ||
|
|
||
| if (items.length) { | ||
| items = items.filter((item) => { | ||
| return Date.parse(item.created_at.date) > lastDate; | ||
| }) | ||
| .sort((a, b) => Date.parse(b.created_at.date) - Date.parse(a.created_at.date)); | ||
|
|
||
| const filteredItems = this.getFilter(items); | ||
| if (filteredItems) { | ||
| items = filteredItems; | ||
| } | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (items.length) { | ||
| if (maxResults && (items.length > maxResults)) { | ||
| items.length = maxResults; | ||
| } | ||
| this._setLastDate(Date.parse(items[0].created_at.date)); | ||
| } | ||
| } | ||
|
|
||
| for (const item of items.reverse()) { | ||
| this.$emit(item, { | ||
| id: item.code, | ||
| summary: this.getSummary(item), | ||
| ts: Date.parse(item.created_at.date), | ||
| }); | ||
| } | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.emitEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.emitEvent(); | ||
| }, | ||
| }; | ||
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "bitport-new-file", | ||
| name: "New File", | ||
| description: "Emit new event when a new file is added to a project in Bitport. [See the documentation](https://bitport.io/api/index.html?url=/v2/cloud/byPath)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getSummary(item) { | ||
| return `New File: ${item.name}`; | ||
| }, | ||
| }, | ||
| sampleEmit, | ||
| }; |
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| export default { | ||
| "name": "Big.Buck.Bunny.4K.UHD.HFR.60fps.FLAC.mkv", | ||
| "crc32": null, | ||
| "created_at": { | ||
| "date": "2016-02-09 15:36:47.000000", | ||
| "timezone_type": 3, | ||
| "timezone": "UTC" | ||
| }, | ||
| "code": "0phkm9kpro", | ||
| "parent_folder_code": null, | ||
| "size": 892862006, | ||
| "video": true, | ||
| "conversion_status": "unconverted", | ||
| "screenshots": { | ||
| "small": "https://static.bitport.io/1a338b413f21cbe0_s01.jpg", | ||
| "medium": "https://static.bitport.io/1a338b413f21cbe0_m01.jpg", | ||
| "big": "https://static.bitport.io/1a338b413f21cbe0_l01.jpg" | ||
| }, | ||
| "extension": "mkv", | ||
| "type": "video", | ||
| "virus": false | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "bitport-new-media", | ||
| name: "New Media", | ||
| description: "Emit new event when a new media is added to a project in Bitport. [See the documentation](https://bitport.io/api/index.html?url=/v2/cloud/byPath)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getFilter(items) { | ||
| return items.filter((item) => { | ||
| return [ | ||
| "video", | ||
| "audio", | ||
| ].includes(item.type); | ||
| }); | ||
| }, | ||
| getSummary(item) { | ||
| return `New Media: ${item.name}`; | ||
| }, | ||
| }, | ||
| sampleEmit, | ||
| }; |
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| export default { | ||
| "name": "Big.Buck.Bunny.4K.UHD.HFR.60fps.FLAC.mkv", | ||
| "crc32": null, | ||
| "created_at": { | ||
| "date": "2016-02-09 15:36:47.000000", | ||
| "timezone_type": 3, | ||
| "timezone": "UTC" | ||
| }, | ||
| "code": "0phkm9kpro", | ||
| "parent_folder_code": null, | ||
| "size": 892862006, | ||
| "video": true, | ||
| "conversion_status": "unconverted", | ||
| "screenshots": { | ||
| "small": "https://static.bitport.io/1a338b413f21cbe0_s01.jpg", | ||
| "medium": "https://static.bitport.io/1a338b413f21cbe0_m01.jpg", | ||
| "big": "https://static.bitport.io/1a338b413f21cbe0_l01.jpg" | ||
| }, | ||
| "extension": "mkv", | ||
| "type": "video", | ||
| "virus": false | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
🧩 Analysis chain
Verify the API response structure for folder listing.
The code destructures
datafrom thelistFolders()response on line 13. Ensure that the Bitport API actually returns an object with adataproperty. If the API returns the folder array directly (without wrapping it in adataproperty), this will fail.Run the following script to check the actual API response structure:
Alternatively, please search the web for the Bitport API documentation:
🏁 Script executed:
Length of output: 0
🌐 Web query:
💡 Result:
Top-level wrapper
When calling GET /v2/cloud/byPath?scope=recursive the data object contains the folder metadata plus recursive lists of folders and files. Skeleton (fields shown from Bitport docs):
{
"status": "success",
"data": {
"name": "",
"code": "<folder code|null>",
"size": ,
"folders": [
{
"name": "",
"code": "",
"size": "",
"created_at": { "date": "YYYY-MM-DD HH:MM:SS.000000", "timezone_type": 3, "timezone": "UTC" },
"files_count": ""
},
...
],
"files": [
{
"name": "",
"crc32": ,
"created_at": { "date": "YYYY-MM-DD HH:MM:SS.000000", "timezone_type": 3, "timezone": "UTC" },
"code": "",
"parent_folder_code": "",
"size": ,
"video": true|false,
"conversion_status": "",
"screenshots": { "small": "", "medium": "", "big": "" },
"extension": "",
"type": "<video|music|archive|...>",
"paused_at": ,
"virus": true|false
},
...
]
},
"errors": null
}
Source: Bitport API docs for cloud endpoints and file-byPath examples. [1][2]
References
[1] Bitport API — /v2/cloud (example recursive response).
[2] Bitport API — /v2/files/byPath (file object structure).
Extract the
foldersarray from the API responseThe Bitport endpoint returns
{ status, data: { folders: [...], files: […] } }, soconst { data } = await this.listFolders()yields an object, not an array. Update to:🤖 Prompt for AI Agents