Skip to content

Commit 8816f60

Browse files
committed
renamings and fix put route
1 parent d2df79e commit 8816f60

File tree

5 files changed

+23
-32
lines changed

5 files changed

+23
-32
lines changed

src/assertions/put.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { putBlobObjectResponseSchema } from "../schemas/put";
2-
import type { PutBlobObjectResponse } from "../types/put";
1+
import { putObjectResponseSchema } from "../schemas/put";
2+
import type { PutObjectResponse } from "../types/put";
33
import { handleAPIObjectAssertion } from "./handlers";
44

5-
export function assertPutBlobObjectResponse(
6-
value: unknown,
7-
): PutBlobObjectResponse {
5+
export function assertPutObjectResponse(value: unknown): PutObjectResponse {
86
return handleAPIObjectAssertion({
9-
schema: putBlobObjectResponseSchema,
7+
schema: putObjectResponseSchema,
108
code: "PUT_OBJECT",
119
route: "/put",
1210
value,

src/managers/objects.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
import { readFile } from "fs/promises";
22
import type { SquareCloudBlob } from "..";
3-
import { assertPutBlobObjectResponse } from "../assertions/put";
4-
import { putBlobObjectPayloadSchema } from "../schemas/put";
3+
import { assertPutObjectResponse } from "../assertions/put";
4+
import { putObjectPayloadSchema } from "../schemas/put";
55
import { SquareCloudBlobError } from "../structures/error";
6-
import type { PutBlobObjectResponse, PutBlobObjectType } from "../types/put";
6+
import type { PutObjectResponse, PutObjectType } from "../types/put";
77

88
export class BlobObjectsManager {
99
constructor(private readonly client: SquareCloudBlob) {}
1010

11-
async put(object: PutBlobObjectType) {
12-
const payload = putBlobObjectPayloadSchema.parse(object);
11+
async put(object: PutObjectType) {
12+
const payload = putObjectPayloadSchema.parse(object);
1313
const file = await this.parseFile(payload.file);
1414

1515
const formData = new FormData();
1616
formData.append("file", new Blob([file]));
1717

18-
const { response } = await this.client.api.request<PutBlobObjectResponse>(
19-
"blob/put",
20-
{
21-
method: "POST",
22-
body: formData,
23-
params: payload.params,
24-
},
18+
const { response } = await this.client.api.request<PutObjectResponse>(
19+
"put",
20+
{ method: "POST", body: formData, params: payload.params },
2521
);
2622

27-
return assertPutBlobObjectResponse(response);
23+
return assertPutObjectResponse(response);
2824
}
2925

3026
private async parseFile(file: string | Buffer) {

src/schemas/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { z } from "zod";
22

33
export const stringSchema = z.string();
44

5-
export const nameLikeStringSchema = z
5+
export const nameLikeSchema = z
66
.string()
77
.min(3)
88
.max(32)

src/schemas/put.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { z } from "zod";
2-
import { nameLikeStringSchema } from "./common";
2+
import { nameLikeSchema } from "./common";
33

4-
export const putBlobObjectSchema = z.object({
4+
export const putObjectSchema = z.object({
55
/** A string representing the name for the file. */
6-
name: nameLikeStringSchema,
6+
name: nameLikeSchema,
77
/** Use absolute path or Buffer, can be a single file or compressed (zip) */
88
file: z.string().or(z.instanceof(Buffer)),
99
/** A string representing the prefix for the file. */
10-
prefix: nameLikeStringSchema.optional(),
10+
prefix: nameLikeSchema.optional(),
1111
/** A number indicating the expiration period of the file, ranging from 1 to 365 days. */
1212
expire: z.number().min(1).max(365).optional(),
1313
/** Set to true if a security hash is required. */
@@ -16,7 +16,7 @@ export const putBlobObjectSchema = z.object({
1616
autoDownload: z.boolean().optional(),
1717
});
1818

19-
export const putBlobObjectPayloadSchema = putBlobObjectSchema.transform(
19+
export const putObjectPayloadSchema = putObjectSchema.transform(
2020
({ file, securityHash, autoDownload, ...rest }) => ({
2121
file,
2222
params: {
@@ -27,7 +27,7 @@ export const putBlobObjectPayloadSchema = putBlobObjectSchema.transform(
2727
}),
2828
);
2929

30-
export const putBlobObjectResponseSchema = z.object({
30+
export const putObjectResponseSchema = z.object({
3131
/** The URL of the uploaded file. (File distributed in Square Cloud CDN) */
3232
url: z.string(),
3333
});

src/types/put.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { z } from "zod";
2-
import type {
3-
putBlobObjectResponseSchema,
4-
putBlobObjectSchema,
5-
} from "../schemas/put";
2+
import type { putObjectResponseSchema, putObjectSchema } from "../schemas/put";
63

7-
export type PutBlobObjectType = z.infer<typeof putBlobObjectSchema>;
8-
export type PutBlobObjectResponse = z.infer<typeof putBlobObjectResponseSchema>;
4+
export type PutObjectType = z.infer<typeof putObjectSchema>;
5+
export type PutObjectResponse = z.infer<typeof putObjectResponseSchema>;

0 commit comments

Comments
 (0)