Skip to content
Merged
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
31 changes: 15 additions & 16 deletions paginated_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default defineComponent({
name: "Paginated HTTP Request",
description: "Creates a HTTP Request until end of paginated data or timeout is reached",
key: "paginated_http_request",
version: "0.0.1",
version: "0.0.2",
type: "action",

props: {
Expand Down Expand Up @@ -46,22 +46,25 @@ export default defineComponent({
}
},
methods: {
get_pagination_index() {
for (const key in this.http_request.params) {
if (this.http_request.params[key].name == this.paginator) {
return key
}
getPaginationIndex() {
let i = this.http_request.params.findIndex(p => p.name == this.paginator)
if (i < 0) {
i = this.http_request.params.length
this.http_request.params.push({
"name": this.paginator,
"value": "0"
})
}
return null
return i
},
get_response_data(resp) {
getResponseData(resp) {
let data = resp
for (const field of this.data_field.split(".")) {
data = data[field]
}
return data
},
handle_timeout(start) {
handleTimeout(start) {
const duration = Date.now() - start
if (this.timeout && duration > this.timeout * 1000) {
const msg = `Timeout reached at ${duration / 1000} seconds`
Expand All @@ -75,18 +78,14 @@ export default defineComponent({
}
},
async run({ $ }) {
const i = await this.get_pagination_index()
if (i === null) {
throw new Error("Pagination parameter not set")
}

const i = await this.getPaginationIndex()
const start = Date.now()
const results = []
let data = []
let count = 1
do {
const resp = await this.http_request.execute()
data = await this.get_response_data(resp)
data = await this.getResponseData(resp)

if (!Array.isArray(data)) {
throw new Error(`Response data is not an array: ${typeof data}`);
Expand All @@ -98,7 +97,7 @@ export default defineComponent({

results.push(...data)

if (await this.handle_timeout(start)) {
if (await this.handleTimeout(start)) {
break
}
count++
Expand Down