Skip to content

Commit

Permalink
Merge branch 'main' into v7
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge committed Aug 28, 2024
2 parents c798949 + 9a69b90 commit a55d1e7
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-zoos-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"uploadthing": patch
---

fix: types for renameFiles match infra
5 changes: 5 additions & 0 deletions .changeset/slimy-pets-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@uploadthing/shared": patch
---

refactor: use effect/Encoding over Node.js Buffer
2 changes: 1 addition & 1 deletion docs/src/pages/getting-started/pagedir.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const UploadDropzone = generateUploadDropzone<OurFileRouter>();
The `@uploadthing/react` package includes an "UploadButton" component that you
can simply drop into your app, and start uploading files immediately.

```tsx copy filename="app/example-uploader.tsx"
```tsx copy filename="pages/example-uploader.tsx"
import { UploadButton } from "~/utils/uploadthing";

export default function Home() {
Expand Down
2 changes: 1 addition & 1 deletion packages/uploadthing/src/sdk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface ListFilesOptions {
offset?: number;
}

type KeyRename = { key: string; newName: string };
type KeyRename = { fileKey: string; newName: string };
type CustomIdRename = { customId: string; newName: string };
export type RenameFileUpdate = KeyRename | CustomIdRename;

Expand Down
43 changes: 42 additions & 1 deletion packages/uploadthing/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,48 @@ describe.runIf(shouldRun)(
localInfo.filesUploaded++;
});

rawIt("should rename a file", async () => {
rawIt("should rename a file with fileKey", async () => {
const customId = crypto.randomUUID();

const file = new UTFile(["foo"], "bar.txt");
const result = await utapi.uploadFiles(file);
expect(result).toEqual({
data: {
customId: null,
key: expect.stringMatching(/.+/),
name: "bar.txt",
size: 3,
type: "text/plain",
url: expect.stringMatching(/https:\/\/utfs.io\/f\/.+/),
},
error: null,
});

const fileKey = result.data!.key;

const { success } = await utapi.renameFiles({
fileKey,
newName: "baz.txt",
});
expect(success).toBe(true);

const { files } = await utapi.listFiles();
expect(files.find((f) => f.key === fileKey)).toHaveProperty(
"name",
"baz.txt",
);

// FIXME: Bug in uploadthing server
// const heads = await fetch(result.data!.url).then((r) => r.headers);
// expect(heads.get("Content-Disposition")).toEqual(
// expect.stringContaining("filename=baz.txt"),
// );

localInfo.totalBytes += result.data!.size;
localInfo.filesUploaded++;
});

rawIt("should rename a file with customId", async () => {
const customId = crypto.randomUUID();

const file = new UTFile(["foo"], "bar.txt", { customId });
Expand Down

0 comments on commit a55d1e7

Please sign in to comment.