From da58628d2d4b9216d8195fed0f432ff6e3cc7847 Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Sun, 17 Sep 2023 11:37:15 +0100 Subject: [PATCH] Fix list object endpoint limit parameter --- packages/dashboard/src/api.js | 1 + worker/package-lock.json | 8 ++++---- worker/package.json | 2 +- worker/src/buckets/api/createFolder.ts | 2 +- worker/src/buckets/api/deleteObject.ts | 2 +- worker/src/buckets/api/getObject.ts | 2 +- worker/src/buckets/api/headObject.ts | 2 +- worker/src/buckets/api/listObjects.ts | 4 ++-- worker/src/buckets/api/moveObject.ts | 4 ++-- worker/src/buckets/api/multipart/completeUpload.ts | 2 +- worker/src/buckets/api/multipart/createUpload.ts | 2 +- worker/src/buckets/api/multipart/partUpload.ts | 14 ++++++++++++-- worker/src/buckets/api/putObject.ts | 14 ++++++++++++-- 13 files changed, 40 insertions(+), 19 deletions(-) diff --git a/packages/dashboard/src/api.js b/packages/dashboard/src/api.js index 6c9234c..8f31e7a 100644 --- a/packages/dashboard/src/api.js +++ b/packages/dashboard/src/api.js @@ -119,6 +119,7 @@ const apiHandler = { params: { delimiter: '/', prefix: encodeKey(prefix) + // limit: 1000 TODO: only use this parameter on 1.0.3 or above } }) diff --git a/worker/package-lock.json b/worker/package-lock.json index 456e086..6cd2b5d 100644 --- a/worker/package-lock.json +++ b/worker/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "MIT", "dependencies": { - "@cloudflare/itty-router-openapi": "^1.0.1", + "@cloudflare/itty-router-openapi": "^1.0.3", "postal-mime": "^1.0.16" }, "bin": { @@ -58,9 +58,9 @@ } }, "node_modules/@cloudflare/itty-router-openapi": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@cloudflare/itty-router-openapi/-/itty-router-openapi-1.0.1.tgz", - "integrity": "sha512-6qGUraCHdx/8/S2LZ4wziidd8POWEqID5yPVmxnN5NlSIvw6bqXjgh2LF+Ev21YKkHnoA6w01zEVvgTUg7qJsA==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@cloudflare/itty-router-openapi/-/itty-router-openapi-1.0.3.tgz", + "integrity": "sha512-lNsxqJ+qrk6VPIWZ9FssHnDyPXvk12FAeqdsSCqTk1AI5OIq4DBAOl/JNsc7AN1JrGcvfm31zCSZ6oo8OXNaJA==", "dependencies": { "@asteasolutions/zod-to-openapi": "^5.3.1", "itty-router": "^4.0.22", diff --git a/worker/package.json b/worker/package.json index 60b2526..9f57227 100644 --- a/worker/package.json +++ b/worker/package.json @@ -95,7 +95,7 @@ "wrangler": "^3.6.0" }, "dependencies": { - "@cloudflare/itty-router-openapi": "^1.0.1", + "@cloudflare/itty-router-openapi": "^1.0.3", "postal-mime": "^1.0.16" }, "bin": { diff --git a/worker/src/buckets/api/createFolder.ts b/worker/src/buckets/api/createFolder.ts index 7efe767..c1240d0 100644 --- a/worker/src/buckets/api/createFolder.ts +++ b/worker/src/buckets/api/createFolder.ts @@ -12,7 +12,7 @@ export class CreateFolder extends OpenAPIRoute { bucket: Path(String), }, requestBody: { - key: z.string().optional().describe('base64 encoded file key'), + key: z.string().describe('base64 encoded file key'), } } diff --git a/worker/src/buckets/api/deleteObject.ts b/worker/src/buckets/api/deleteObject.ts index 4d6b109..64c46df 100644 --- a/worker/src/buckets/api/deleteObject.ts +++ b/worker/src/buckets/api/deleteObject.ts @@ -12,7 +12,7 @@ export class DeleteObject extends OpenAPIRoute { bucket: Path(String), }, requestBody: { - key: z.string().optional().describe('base64 encoded file key'), + key: z.string().describe('base64 encoded file key'), } } diff --git a/worker/src/buckets/api/getObject.ts b/worker/src/buckets/api/getObject.ts index 4b3530f..3e4b362 100644 --- a/worker/src/buckets/api/getObject.ts +++ b/worker/src/buckets/api/getObject.ts @@ -10,7 +10,7 @@ export class GetObject extends OpenAPIRoute { summary: 'Get Object', parameters: { bucket: Path(String), - key: Path(z.string().optional().describe('base64 encoded file key')), + key: Path(z.string().describe('base64 encoded file key')), }, responses: { '200': { diff --git a/worker/src/buckets/api/headObject.ts b/worker/src/buckets/api/headObject.ts index 71f976c..d49ea84 100644 --- a/worker/src/buckets/api/headObject.ts +++ b/worker/src/buckets/api/headObject.ts @@ -10,7 +10,7 @@ export class HeadObject extends OpenAPIRoute { summary: 'Get Object', parameters: { bucket: Path(String), - key: Query(z.string().optional().describe('base64 encoded file key')), + key: Query(z.string().describe('base64 encoded file key')), }, } diff --git a/worker/src/buckets/api/listObjects.ts b/worker/src/buckets/api/listObjects.ts index b3e7a07..c3cdc8f 100644 --- a/worker/src/buckets/api/listObjects.ts +++ b/worker/src/buckets/api/listObjects.ts @@ -1,4 +1,4 @@ -import {OpenAPIRoute, Path, Query} from "@cloudflare/itty-router-openapi"; +import { OpenAPIRoute, Path, Query } from "@cloudflare/itty-router-openapi"; import {Context} from "../../interfaces"; import {OpenAPIRouteSchema} from "@cloudflare/itty-router-openapi/dist/src/types"; import {z} from 'zod' @@ -10,7 +10,7 @@ export class ListObjects extends OpenAPIRoute { summary: 'List objects', parameters: { bucket: Path(String), - limit: Query(z.number().optional()), + limit: Query(Number, {required: false}), prefix: Query(z.string().optional().describe('base64 encoded prefix'),), cursor: Query(z.string().optional()), delimiter: Query(z.string().optional()), diff --git a/worker/src/buckets/api/moveObject.ts b/worker/src/buckets/api/moveObject.ts index a419185..d5c5bcb 100644 --- a/worker/src/buckets/api/moveObject.ts +++ b/worker/src/buckets/api/moveObject.ts @@ -12,8 +12,8 @@ export class MoveObject extends OpenAPIRoute { bucket: Path(String), }, requestBody: { - oldKey: z.string().optional().describe('base64 encoded file key'), - newKey: z.string().optional().describe('base64 encoded file key'), + oldKey: z.string().describe('base64 encoded file key'), + newKey: z.string().describe('base64 encoded file key'), } } diff --git a/worker/src/buckets/api/multipart/completeUpload.ts b/worker/src/buckets/api/multipart/completeUpload.ts index 5e05c85..93ebeed 100644 --- a/worker/src/buckets/api/multipart/completeUpload.ts +++ b/worker/src/buckets/api/multipart/completeUpload.ts @@ -13,7 +13,7 @@ export class CompleteUpload extends OpenAPIRoute { }, requestBody: { uploadId: String, - key: z.string().optional().describe('base64 encoded file key'), + key: z.string().describe('base64 encoded file key'), parts: [{ etag: String, partNumber: Int diff --git a/worker/src/buckets/api/multipart/createUpload.ts b/worker/src/buckets/api/multipart/createUpload.ts index e6ee569..f60c107 100644 --- a/worker/src/buckets/api/multipart/createUpload.ts +++ b/worker/src/buckets/api/multipart/createUpload.ts @@ -10,7 +10,7 @@ export class CreateUpload extends OpenAPIRoute { summary: 'Create upload', parameters: { bucket: Path(String), - key: Query(z.string().optional().describe('base64 encoded file key')), + key: Query(z.string().describe('base64 encoded file key')), customMetadata: Query(z.string().optional().describe('base64 encoded json string')), httpMetadata: Query(z.string().optional().describe('base64 encoded json string')), } diff --git a/worker/src/buckets/api/multipart/partUpload.ts b/worker/src/buckets/api/multipart/partUpload.ts index ba7d4a1..140aaf2 100644 --- a/worker/src/buckets/api/multipart/partUpload.ts +++ b/worker/src/buckets/api/multipart/partUpload.ts @@ -1,4 +1,4 @@ -import {Int, OpenAPIRoute, Path, Query} from "@cloudflare/itty-router-openapi"; +import { Int, OpenAPIRoute, Path, Query, RequestBody } from "@cloudflare/itty-router-openapi"; import {Context} from "../../../interfaces"; import {OpenAPIRouteSchema} from "@cloudflare/itty-router-openapi/dist/src/types"; import {z} from "zod"; @@ -8,9 +8,19 @@ export class PartUpload extends OpenAPIRoute { operationId: 'post-multipart-part-upload', tags: ['Multipart'], summary: 'Part upload', + requestBody: new RequestBody({ + content: { + 'application/octet-stream': { + schema: { + type: 'string', + format: 'binary', + }, + }, + }, + }), parameters: { bucket: Path(String), - key: Query(z.string().optional().describe('base64 encoded file key')), + key: Query(z.string().describe('base64 encoded file key')), uploadId: Query(String), partNumber: Query(Int), } diff --git a/worker/src/buckets/api/putObject.ts b/worker/src/buckets/api/putObject.ts index 96775ea..0834e9a 100644 --- a/worker/src/buckets/api/putObject.ts +++ b/worker/src/buckets/api/putObject.ts @@ -1,4 +1,4 @@ -import {OpenAPIRoute, Path, Query} from "@cloudflare/itty-router-openapi"; +import { OpenAPIRoute, Path, Query, RequestBody } from "@cloudflare/itty-router-openapi"; import {Context} from "../../interfaces"; import {OpenAPIRouteSchema} from "@cloudflare/itty-router-openapi/dist/src/types"; import {z} from 'zod' @@ -8,9 +8,19 @@ export class PutObject extends OpenAPIRoute { operationId: 'post-bucket-upload-object', tags: ['Buckets'], summary: 'Upload object', + requestBody: new RequestBody({ + content: { + 'application/octet-stream': { + schema: { + type: 'string', + format: 'binary', + }, + }, + }, + }), parameters: { bucket: Path(String), - key: Query(z.string().optional().describe('base64 encoded file key')), + key: Query(z.string().describe('base64 encoded file key')), customMetadata: Query(z.string().optional().describe('base64 encoded json string')), httpMetadata: Query(z.string().optional().describe('base64 encoded json string')), },