Skip to content

Commit f744e4c

Browse files
committed
Enhance Bitport component with new actions and utilities
- Introduced `Add Item` action for adding torrents with optional folder selection. - Added `Search` action to find files and folders in the cloud. - Implemented utility function `prepareList` for organizing folder and file data. - Updated `bitport.app.mjs` to include new prop definitions and methods for folder management. - Created new sources for detecting new files and media, enhancing event-driven capabilities. - Bumped package version to 0.1.0 and added necessary dependencies.
1 parent 3f1fc3e commit f744e4c

File tree

10 files changed

+500
-6
lines changed

10 files changed

+500
-6
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import app from "../../bitport.app.mjs";
2+
3+
export default {
4+
key: "bitport-add-item",
5+
name: "Add Item",
6+
description: "Add new torrent. [See the documentation](https://bitport.io/api/index.html?url=/v2/transfers&method=POST)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
torrent: {
12+
type: "string",
13+
label: "Torrent",
14+
description: "A URL linking to a .torrent file or a magnet link",
15+
},
16+
folderCode: {
17+
propDefinition: [
18+
app,
19+
"folderCode",
20+
],
21+
optional: true,
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.app.addItem({
26+
$,
27+
data: {
28+
torrent: this.torrent,
29+
folder_code: this.folderCode,
30+
},
31+
});
32+
33+
$.export("$summary", "Successfully added torrent!");
34+
return response;
35+
},
36+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import app from "../../bitport.app.mjs";
2+
3+
export default {
4+
key: "bitport-search",
5+
name: "Search",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
query: {
12+
type: "string",
13+
label: "Query",
14+
description: "The query to search for",
15+
},
16+
},
17+
async run({ $ }) {
18+
const { data } = await this.app.search({
19+
$,
20+
query: this.query,
21+
});
22+
23+
$.export("$summary", `Successfully found for ${data.folders.length} folder${data.folders.length > 1
24+
? "s"
25+
: ""} and ${data.files.length} file${data.files.length > 1
26+
? "s"
27+
: ""}`);
28+
return data;
29+
},
30+
};

components/bitport/bitport.app.mjs

Lines changed: 227 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,233 @@
1+
import { axios } from "@pipedream/platform";
2+
import { prepareList } from "./common/utils.mjs";
3+
14
export default {
25
type: "app",
36
app: "bitport",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
folderCode: {
9+
type: "string",
10+
label: "Folder Code",
11+
description: "The code of the folder to add the item to",
12+
async options() {
13+
const { data } = await this.listFolders();
14+
15+
return prepareList({
16+
items: data,
17+
foldersOnly: true,
18+
}).map((item) => ({
19+
label: item.fullName,
20+
value: item.code,
21+
}));
22+
},
23+
},
24+
},
525
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
26+
_apiUrl() {
27+
return "https://api.bitport.io/v2";
28+
},
29+
_getHeaders() {
30+
return {
31+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
32+
};
33+
},
34+
_makeRequest({
35+
$ = this, path, ...opts
36+
}) {
37+
return axios($, {
38+
url: `${this._apiUrl()}${path}`,
39+
headers: this._getHeaders(),
40+
...opts,
41+
});
42+
},
43+
search({
44+
query, ...opts
45+
}) {
46+
return this._makeRequest({
47+
path: `/search/${query}`,
48+
...opts,
49+
});
50+
},
51+
listFolders() {
52+
return this._makeRequest({
53+
path: "/cloud/byPath",
54+
params: {
55+
scope: "recursive",
56+
},
57+
});
58+
},
59+
listFiles() {
60+
return {
61+
"status": "success",
62+
"data": [
63+
{
64+
"name": "My files",
65+
"code": null,
66+
"size": 118230773819,
67+
"folders": [
68+
{
69+
"name": "Big buck bunny",
70+
"code": "j4f02eidbb",
71+
"size": "5233819",
72+
"folders": [],
73+
"files": [],
74+
"created_at": {
75+
"date": "2016-03-11 8:51:32.000000",
76+
"timezone_type": 3,
77+
"timezone": "UTC",
78+
},
79+
"files_count": "3",
80+
},
81+
{
82+
"name": "Videos",
83+
"code": "9kw6nh1h2z",
84+
"size": "2814299",
85+
"created_at": {
86+
"date": "2016-03-11 8:54:29.000000",
87+
"timezone_type": 3,
88+
"timezone": "UTC",
89+
},
90+
"files_count": "53",
91+
"folders": [],
92+
"files": [],
93+
},
94+
],
95+
"files": [
96+
{
97+
"name": "Big.Buck.Bunny.4K.UHD.HFR.60fps.FLAC.mkv",
98+
"crc32": null,
99+
"created_at": {
100+
"date": "2016-02-09 15:36:47.000000",
101+
"timezone_type": 3,
102+
"timezone": "UTC",
103+
},
104+
"code": "0phkm9kpro",
105+
"parent_folder_code": null,
106+
"size": 892862006,
107+
"video": true,
108+
"conversion_status": "unconverted",
109+
"screenshots": {
110+
"small": "https://static.bitport.io/1a338b413f21cbe0_s01.jpg",
111+
"medium": "https://static.bitport.io/1a338b413f21cbe0_m01.jpg",
112+
"big": "https://static.bitport.io/1a338b413f21cbe0_l01.jpg",
113+
},
114+
"extension": "mkv",
115+
"type": "audio",
116+
"virus": false,
117+
},
118+
{
119+
"name": "2Big.Buck.Bunny.4K.UHD.HFR.60fps.FLAC.mkv",
120+
"crc32": null,
121+
"created_at": {
122+
"date": "2016-02-09 15:36:47.000000",
123+
"timezone_type": 3,
124+
"timezone": "UTC",
125+
},
126+
"code": "0phkm9kpro2",
127+
"parent_folder_code": null,
128+
"size": 892862006,
129+
"video": true,
130+
"conversion_status": "unconverted",
131+
"screenshots": {
132+
"small": "https://static.bitport.io/1a338b413f21cbe0_s01.jpg",
133+
"medium": "https://static.bitport.io/1a338b413f21cbe0_m01.jpg",
134+
"big": "https://static.bitport.io/1a338b413f21cbe0_l01.jpg",
135+
},
136+
"extension": "mkv",
137+
"type": "document",
138+
"virus": false,
139+
},
140+
{
141+
"name": "3Big.Buck.Bunny.4K.UHD.HFR.60fps.FLAC.mkv",
142+
"crc32": null,
143+
"created_at": {
144+
"date": "2016-02-09 15:36:47.000000",
145+
"timezone_type": 3,
146+
"timezone": "UTC",
147+
},
148+
"code": "0phkm9kpro3",
149+
"parent_folder_code": null,
150+
"size": 892862006,
151+
"video": true,
152+
"conversion_status": "unconverted",
153+
"screenshots": {
154+
"small": "https://static.bitport.io/1a338b413f21cbe0_s01.jpg",
155+
"medium": "https://static.bitport.io/1a338b413f21cbe0_m01.jpg",
156+
"big": "https://static.bitport.io/1a338b413f21cbe0_l01.jpg",
157+
},
158+
"extension": "mkv",
159+
"type": "image",
160+
"virus": false,
161+
},
162+
{
163+
"name": "4Big.Buck.Bunny.4K.UHD.HFR.60fps.FLAC.mkv",
164+
"crc32": null,
165+
"created_at": {
166+
"date": "2016-02-09 15:36:47.000000",
167+
"timezone_type": 3,
168+
"timezone": "UTC",
169+
},
170+
"code": "0phkm9kpro4",
171+
"parent_folder_code": null,
172+
"size": 892862006,
173+
"video": true,
174+
"conversion_status": "unconverted",
175+
"screenshots": {
176+
"small": "https://static.bitport.io/1a338b413f21cbe0_s01.jpg",
177+
"medium": "https://static.bitport.io/1a338b413f21cbe0_m01.jpg",
178+
"big": "https://static.bitport.io/1a338b413f21cbe0_l01.jpg",
179+
},
180+
"extension": "mkv",
181+
"type": "video",
182+
"virus": false,
183+
},
184+
],
185+
"parent_folder": null,
186+
},
187+
],
188+
"errors": null,
189+
};
190+
// return this._makeRequest({
191+
// path: "/cloud/byPath",
192+
// params: {
193+
// scope: "recursive",
194+
// },
195+
// });
196+
},
197+
addItem(opts = {}) {
198+
return this._makeRequest({
199+
method: "POST",
200+
path: "/transfers",
201+
...opts,
202+
});
9203
},
204+
205+
/*async *paginate({
206+
fn, params = {}, maxResults = null,
207+
}) {
208+
let lastPage = false;
209+
let count = 0;
210+
let page = 0;
211+
212+
do {
213+
params.page = ++page;
214+
const {
215+
data,
216+
meta: {
217+
current_page, last_page,
218+
},
219+
} = await fn({params});
220+
for (const d of data) {
221+
yield d;
222+
223+
if (maxResults && ++count === maxResults) {
224+
return count;
225+
}
226+
}
227+
228+
lastPage = !(current_page == last_page);
229+
230+
} while (lastPage);
231+
},*/
10232
},
11-
};
233+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export const prepareList = ({
2+
items, parentName = "", filesOnly = false,
3+
}) => {
4+
const itemsArray = [];
5+
for (const item of items) {
6+
const fullName = `${parentName}/${item.name}`;
7+
8+
if (filesOnly) {
9+
itemsArray.push(
10+
...item.files,
11+
);
12+
} else {
13+
itemsArray.push({
14+
fullName,
15+
...item,
16+
});
17+
}
18+
19+
itemsArray.push(...prepareList({
20+
items: item.folders,
21+
parentName: fullName,
22+
filesOnly,
23+
}));
24+
}
25+
26+
return itemsArray;
27+
};

components/bitport/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/bitport",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Bitport Components",
55
"main": "bitport.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
1518
}

0 commit comments

Comments
 (0)