From df4d0146430e480d922879805d3e0732a859d58c Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Oct 2023 20:00:45 -0500 Subject: [PATCH] Change status to boolean --- .../src/Payload/ImageThumbnailResult.ts | 3 +- .../packages/diviner/src/Diviner/Diviner.ts | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/plugins/packages/payload/packages/image-thumbnail/src/Payload/ImageThumbnailResult.ts b/packages/plugins/packages/payload/packages/image-thumbnail/src/Payload/ImageThumbnailResult.ts index 2536d480d00..c54c5dc5f78 100644 --- a/packages/plugins/packages/payload/packages/image-thumbnail/src/Payload/ImageThumbnailResult.ts +++ b/packages/plugins/packages/payload/packages/image-thumbnail/src/Payload/ImageThumbnailResult.ts @@ -7,8 +7,7 @@ export type ImageThumbnailResultIndexSchema = typeof ImageThumbnailResultIndexSc export interface ImageThumbnailResultInfo { sources: string[] - // TODO: Something richer than HTTP status code that allows for info about failure modes - status: number + status: boolean timestamp: number url: string } diff --git a/packages/plugins/packages/payloadset/packages/image-thumbnail/packages/diviner/src/Diviner/Diviner.ts b/packages/plugins/packages/payloadset/packages/image-thumbnail/packages/diviner/src/Diviner/Diviner.ts index 6ba9d74c67d..76b65c7c3ef 100644 --- a/packages/plugins/packages/payloadset/packages/image-thumbnail/packages/diviner/src/Diviner/Diviner.ts +++ b/packages/plugins/packages/payloadset/packages/image-thumbnail/packages/diviner/src/Diviner/Diviner.ts @@ -7,7 +7,7 @@ import { isBoundWitness } from '@xyo-network/boundwitness-model' import { PayloadHasher } from '@xyo-network/core' import { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model' import { asDivinerInstance, DivinerConfigSchema } from '@xyo-network/diviner-model' -import { PayloadDivinerQueryPayload, PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model' +import { PayloadDivinerQueryPayload, PayloadDivinerQuerySchema, SortDirection } from '@xyo-network/diviner-payload-model' import { DivinerWrapper } from '@xyo-network/diviner-wrapper' import { ImageThumbnail, @@ -62,6 +62,10 @@ export class ImageThumbnailDiviner => { // Load last state const lastState = (await this.retrieveState()) ?? { offset: 0 } @@ -76,6 +80,7 @@ export class ImageThumbnailDiviner const indexableHashes: IndexableHashes[] = ( await Promise.all( @@ -95,6 +100,7 @@ export class ImageThumbnailDiviner { const { sourceUrl: url } = thumbnailPayload const { timestamp } = timestampPayload - const status = thumbnailPayload.http?.status ?? -1 + const status = thumbnailPayload.http?.status ? true : false const sources = [boundWitnessHash, thumbnailHash, timestampHash] const result = new PayloadBuilder({ schema: ImageThumbnailResultIndexSchema }) .fields({ sources, status, timestamp, url }) @@ -162,11 +168,20 @@ export class ImageThumbnailDiviner { - const { url, status: payloadStatus } = payload as UrlPayload & { status: number } - const status = payloadStatus ?? 200 + const { + limit: payloadLimit, + offset: payloadOffset, + order: payloadOrder, + status: payloadStatus, + url, + } = payload as UrlPayload & { limit: number; offset: number; order: SortDirection; status: boolean } + // TODO: Expose status, limit (and possibly offset) to caller. Currently only exposing URL + const limit = payloadLimit ?? 1 + const order = payloadOrder ?? 'desc' + const offset = payloadOffset ?? 0 + const status = payloadStatus ?? true const query = new PayloadBuilder({ schema: PayloadDivinerQuerySchema }) - // TODO: Expose status, limit (and possibly offset) to caller. Currently only exposing URL - .fields({ limit: 1, offset: 0, order: 'desc', status, url }) + .fields({ limit, offset, order, status, url }) .build() return await diviner.divine([query]) }),