Skip to content

Commit 416bb62

Browse files
committed
Refactor Bitport component and enhance functionality
- Removed the `foldersOnly` option from the `prepareList` function. - Deleted the `listFiles` method to streamline file management. - Updated the `listFolders` method call for improved folder handling. - Added `annotations` to `Add Item` and `Search` actions for better metadata. - Adjusted timestamp parsing to ensure consistency across data handling.
1 parent 7325139 commit 416bb62

File tree

4 files changed

+13
-170
lines changed

4 files changed

+13
-170
lines changed

components/bitport/actions/add-item/add-item.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export default {
66
description: "Add new torrent. [See the documentation](https://bitport.io/api/index.html?url=/v2/transfers&method=POST)",
77
version: "0.0.1",
88
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
914
props: {
1015
app,
1116
torrent: {

components/bitport/actions/search/search.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export default {
66
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)",
77
version: "0.0.1",
88
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
914
props: {
1015
app,
1116
query: {

components/bitport/bitport.app.mjs

Lines changed: 0 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export default {
1414

1515
return prepareList({
1616
items: data,
17-
foldersOnly: true,
1817
}).map((item) => ({
1918
label: item.fullName,
2019
value: item.code,
@@ -56,178 +55,12 @@ export default {
5655
},
5756
});
5857
},
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-
},
19758
addItem(opts = {}) {
19859
return this._makeRequest({
19960
method: "POST",
20061
path: "/transfers",
20162
...opts,
20263
});
20364
},
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-
},*/
23265
},
23366
};

components/bitport/sources/common/base.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
const bufferObj = Buffer.from(this.folderCode.label, "utf8");
3737
const base64String = bufferObj.toString("base64");
3838

39-
const { data: response } = await this.bitport.listFiles({
39+
const { data: response } = await this.bitport.listFolders({
4040
maxResults,
4141
params: {
4242
folderPath: base64String,
@@ -62,15 +62,15 @@ export default {
6262
if (maxResults && (items.length > maxResults)) {
6363
items.length = maxResults;
6464
}
65-
this._setLastDate(items[0].created_at.date);
65+
this._setLastDate(Date.parse(items[0].created_at.date));
6666
}
6767
}
6868

6969
for (const item of items.reverse()) {
7070
this.$emit(item, {
7171
id: item.code,
7272
summary: this.getSummary(item),
73-
ts: Date.parse(new Date()),
73+
ts: Date.parse(item.created_at.date),
7474
});
7575
}
7676
},

0 commit comments

Comments
 (0)