Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return file hash from uploaded object #978

Merged
merged 14 commits into from
Oct 6, 2024
5 changes: 5 additions & 0 deletions .changeset/nice-crabs-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"uploadthing": minor
---

feat: return object hash in onUploadComplete
2 changes: 1 addition & 1 deletion examples/minimal-appdir/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
1 change: 1 addition & 0 deletions packages/uploadthing/src/internal/shared-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class UploadedFileData extends FileUploadDataWithCustomId.extend<Uploaded
key: S.String,
url: S.String,
appUrl: S.String,
hash: S.String,
markflorkowski marked this conversation as resolved.
Show resolved Hide resolved
}) {}

/**
Expand Down
8 changes: 7 additions & 1 deletion packages/uploadthing/src/internal/upload.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ export const uploadFile = <
Micro.map(
unsafeCoerce<
unknown,
{ url: string; appUrl: string; serverData: TServerOutput }
{
url: string;
appUrl: string;
serverData: TServerOutput;
hash: string;
}
juliusmarminge marked this conversation as resolved.
Show resolved Hide resolved
>,
),
Micro.map((uploadResponse) => ({
Expand All @@ -108,6 +113,7 @@ export const uploadFile = <
appUrl: uploadResponse.appUrl,
customId: presigned.customId,
type: file.type,
hash: uploadResponse.hash,
juliusmarminge marked this conversation as resolved.
Show resolved Hide resolved
})),
);

Expand Down
4 changes: 3 additions & 1 deletion packages/uploadthing/src/internal/upload.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const uploadWithoutProgress = (
),
HttpClientResponse.json,

Effect.andThen(unsafeCoerce<unknown, { url: string; appUrl: string }>),
Effect.andThen(
unsafeCoerce<unknown, { url: string; appUrl: string; hash: string }>,
),
);

yield* Effect.logDebug(`File ${file.name} uploaded successfully`).pipe(
Expand Down
3 changes: 2 additions & 1 deletion packages/uploadthing/src/sdk/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const uploadFile = (
Effect.gen(function* () {
const { file, presigned } = input;

const { url, appUrl } = yield* uploadWithoutProgress(file, presigned);
const { url, appUrl, hash } = yield* uploadWithoutProgress(file, presigned);

return {
key: presigned.key,
Expand All @@ -189,5 +189,6 @@ const uploadFile = (
size: file.size,
type: file.type,
customId: file.customId ?? null,
hash,
};
}).pipe(Effect.withLogSpan("uploadFile"));
Loading