Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions components/bitport/actions/add-item/add-item.mjs
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;
},
};
35 changes: 35 additions & 0 deletions components/bitport/actions/search/search.mjs
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;
},
};
65 changes: 60 additions & 5 deletions components/bitport/bitport.app.mjs
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,
}));
},
Comment on lines +12 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify the API response structure for folder listing.

The code destructures data from the listFolders() response on line 13. Ensure that the Bitport API actually returns an object with a data property. If the API returns the folder array directly (without wrapping it in a data property), 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:

#!/bin/bash
# Description: Search for API response examples or tests that show the structure

# Search for any test files or documentation about the listFolders response
rg -n -A10 -B3 'cloud/byPath|listFolders' --type=js

# Search for any example responses or mock data
rg -n -A10 'status.*success.*data' --type=json --type=js

Length of output: 0


🌐 Web query:

What is the response structure of the Bitport.io API endpoint GET /v2/cloud/byPath with scope=recursive parameter?

💡 Result:

Top-level wrapper

  • status: "success" | "error"
  • data: object (on success)
  • errors: null | array

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 folders array from the API response
The Bitport endpoint returns { status, data: { folders: [...], files: […] } }, so const { data } = await this.listFolders() yields an object, not an array. Update to:

const { data: { folders } } = await this.listFolders();
return prepareList({ items: folders }).map(/* … */);
🤖 Prompt for AI Agents
In components/bitport/bitport.app.mjs around lines 12 to 21, the code
destructures the API response as const { data } = await this.listFolders(), but
the endpoint returns data: { folders: [...], files: [...] } so data is an object
not an array; change the destructure to extract folders (const { data: { folders
} } = await this.listFolders()) and pass folders into prepareList (prepareList({
items: folders })) then map over the resulting list to return label/value
objects.

},
},
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,
});
},
},
};
};
27 changes: 27 additions & 0 deletions components/bitport/common/utils.mjs
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;
};
5 changes: 4 additions & 1 deletion components/bitport/package.json
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": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
86 changes: 86 additions & 0 deletions components/bitport/sources/common/base.mjs
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);
},
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;
}
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();
},
};
19 changes: 19 additions & 0 deletions components/bitport/sources/new-file/new-file.mjs
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,
};
22 changes: 22 additions & 0 deletions components/bitport/sources/new-file/test-event.mjs
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
}
27 changes: 27 additions & 0 deletions components/bitport/sources/new-media/new-media.mjs
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,
};
22 changes: 22 additions & 0 deletions components/bitport/sources/new-media/test-event.mjs
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
}
Loading
Loading