Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 36 additions & 0 deletions components/bitport/actions/add-item/add-item.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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",
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;
},
};
30 changes: 30 additions & 0 deletions components/bitport/actions/search/search.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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",
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;
},
};
232 changes: 227 additions & 5 deletions components/bitport/bitport.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,233 @@
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,
foldersOnly: true,
}).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",
},
});
},
listFiles() {
return {
"status": "success",
"data": [
{
"name": "My files",
"code": null,
"size": 118230773819,
"folders": [
{
"name": "Big buck bunny",
"code": "j4f02eidbb",
"size": "5233819",
"folders": [],
"files": [],
"created_at": {
"date": "2016-03-11 8:51:32.000000",
"timezone_type": 3,
"timezone": "UTC",
},
"files_count": "3",
},
{
"name": "Videos",
"code": "9kw6nh1h2z",
"size": "2814299",
"created_at": {
"date": "2016-03-11 8:54:29.000000",
"timezone_type": 3,
"timezone": "UTC",
},
"files_count": "53",
"folders": [],
"files": [],
},
],
"files": [
{
"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": "audio",
"virus": false,
},
{
"name": "2Big.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": "0phkm9kpro2",
"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": "document",
"virus": false,
},
{
"name": "3Big.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": "0phkm9kpro3",
"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": "image",
"virus": false,
},
{
"name": "4Big.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": "0phkm9kpro4",
"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,
},
],
"parent_folder": null,
},
],
"errors": null,
};
// return this._makeRequest({
// path: "/cloud/byPath",
// params: {
// scope: "recursive",
// },
// });
},
addItem(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/transfers",
...opts,
});
},

/*async *paginate({
fn, params = {}, maxResults = null,
}) {
let lastPage = false;
let count = 0;
let page = 0;

do {
params.page = ++page;
const {
data,
meta: {
current_page, last_page,
},
} = await fn({params});
for (const d of data) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

lastPage = !(current_page == last_page);

} while (lastPage);
},*/
},
};
};
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"
}
}
Loading
Loading