Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinav Kumar <[email protected]>
  • Loading branch information
abhinavkrin committed Nov 1, 2024
1 parent 3b31379 commit c8ca402
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions apps/meteor/app/api/server/lib/getUploadFormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type UploadResult<K> = {
fields: K;
};

type OptionalUploadResult<K> =
type UploadResultWithOptionalFile<K> =
| UploadResult<K>
| ({
[P in keyof Omit<UploadResult<K>, 'fields'>]: undefined;
Expand All @@ -35,9 +35,9 @@ export async function getUploadFormData<
field?: T;
validate?: V;
sizeLimit?: number;
optional: true;
fileOptional: true;
},
): Promise<OptionalUploadResult<K>>;
): Promise<UploadResultWithOptionalFile<K>>;

export async function getUploadFormData<
T extends string,
Expand All @@ -49,7 +49,7 @@ export async function getUploadFormData<
field?: T;
validate?: V;
sizeLimit?: number;
optional?: false | undefined;
fileOptional?: false | undefined;
},
): Promise<UploadResult<K>>;

Expand All @@ -63,9 +63,9 @@ export async function getUploadFormData<
field?: T;
validate?: V;
sizeLimit?: number;
optional?: boolean;
fileOptional?: boolean;
} = {},
): Promise<OptionalUploadResult<K>> {
): Promise<UploadResultWithOptionalFile<K>> {
const limits = {
files: 1,
...(options.sizeLimit && options.sizeLimit > -1 && { fileSize: options.sizeLimit }),
Expand All @@ -74,9 +74,9 @@ export async function getUploadFormData<
const bb = busboy({ headers: request.headers, defParamCharset: 'utf8', limits });
const fields = Object.create(null) as K;

let uploadedFile: OptionalUploadResult<K> | undefined;
let uploadedFile: UploadResultWithOptionalFile<K> | undefined;

let returnResult = (_value: OptionalUploadResult<K>) => {
let returnResult = (_value: UploadResultWithOptionalFile<K>) => {
// noop
};
let returnError = (_error?: Error | string | null | undefined) => {
Expand All @@ -100,7 +100,7 @@ export async function getUploadFormData<
if (!uploadedFile) {
return returnError(new MeteorError('No file or fields were uploaded'));
}
if (!('file' in uploadedFile) && !options.optional) {
if (!('file' in uploadedFile) && !options.fileOptional) {
return returnError(new MeteorError('No file uploaded'));
}
if (options.validate !== undefined && !options.validate(fields)) {
Expand Down Expand Up @@ -170,7 +170,7 @@ export async function getUploadFormData<

request.pipe(bb);

return new Promise<OptionalUploadResult<K>>((resolve, reject) => {
return new Promise<UploadResultWithOptionalFile<K>>((resolve, reject) => {
returnResult = resolve;
returnError = reject;
});
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/emoji-custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ API.v1.addRoute(
{
request: this.request,
},
{ field: 'emoji', sizeLimit: settings.get('FileUpload_MaxFileSize'), optional: true },
{ field: 'emoji', sizeLimit: settings.get('FileUpload_MaxFileSize'), fileOptional: true },
);

const { fields, fileBuffer, mimetype } = emoji;
Expand Down

0 comments on commit c8ca402

Please sign in to comment.