-
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 2 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
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,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; | ||
| }, | ||
| }; | ||
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,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: { | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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,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, | ||
luancazarine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }).map((item) => ({ | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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, | ||
| }; | ||
luancazarine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // return this._makeRequest({ | ||
| // path: "/cloud/byPath", | ||
| // params: { | ||
| // scope: "recursive", | ||
| // }, | ||
| // }); | ||
luancazarine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
luancazarine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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); | ||
| },*/ | ||
luancazarine marked this conversation as resolved.
Outdated
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 |
|---|---|---|
| @@ -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" | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.