diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 7056a57..f90edf0 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -11,7 +11,7 @@ jobs: - uses: denoland/setup-deno@v1 with: - deno-version: v2.x + deno-version: vx.x.x - run: deno fmt --check @@ -20,3 +20,24 @@ jobs: - run: deno test --allow-env --allow-net env: PRODIA_TOKEN: ${{ secrets.PRODIA_TOKEN }} + + node-test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18, 20, 22] + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - run: npm run prepublish + + - run: node example.mjs + env: + PRODIA_TOKEN: ${{ secrets.PRODIA_TOKEN }} diff --git a/example.mjs b/example.mjs new file mode 100644 index 0000000..6266051 --- /dev/null +++ b/example.mjs @@ -0,0 +1,32 @@ +import { createProdia } from "./dist/v2/index.js"; +import { strictEqual } from "assert"; + +const token = process.env.PRODIA_TOKEN; + +if (typeof token !== "string") { + throw new Error("PRODIA_TOKEN is not set"); +} + +const isJpeg = (image) => { + const view = new Uint8Array(image); + + return view[0] === 0xff && view[1] === 0xd8; +}; + +const client = createProdia({ + token, +}); + +const job = await client.job({ + type: "inference.flux.dev.txt2img.v1", + config: { + prompt: "puppies in a cloud, 4k", + steps: 1, + width: 1024, + height: 1024, + }, +}); + +const image = await job.arrayBuffer(); + +strictEqual(isJpeg(image), true, "Image should be a JPEG"); diff --git a/package.json b/package.json index 9b9ccf7..e7242a0 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,9 @@ }, "author": "Monty Anderson ", "license": "ISC", + "engines": { + "node": ">=18.0.0" + }, "devDependencies": { "prettier": "^3.0.0", "typescript": "^5.1.6" diff --git a/v2/index.ts b/v2/index.ts index 1ab5393..d9e86a7 100644 --- a/v2/index.ts +++ b/v2/index.ts @@ -184,13 +184,7 @@ export const createProdia = ({ ); } - const buffer = await new Promise((resolve, reject) => { - const output = body.get("output") as File; - const reader = new FileReader(); - reader.readAsArrayBuffer(output); - reader.onload = () => resolve(reader.result as ArrayBuffer); - reader.onerror = () => reject(new Error("Failed to read output")); - }); + const buffer = await (body.get("output") as Blob).arrayBuffer(); return { job: job,