Skip to content

Commit

Permalink
refactor: change filename and fileSize to name and size respectively …
Browse files Browse the repository at this point in the history
…for Asset type
  • Loading branch information
khushal87 committed Nov 23, 2023
1 parent c9d7d4e commit f8f4d14
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package/expo-package/src/handlers/getPhotos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export const getPhotos = async ({
});
const assets = results.assets.map((asset) => ({
duration: asset.duration,
filename: asset.filename,
height: asset.height,
id: asset.id,
name: asset.filename,
source: 'picker' as const,
type: asset.mediaType,
uri: asset.uri,
Expand Down
4 changes: 2 additions & 2 deletions package/native-package/src/handlers/getPhotos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export const getPhotos = async ({
...edge.node.image,
duration: edge.node.image.playableDuration,
// since we include filename, fileSize in the query, we can safely assume it will be defined
filename: edge.node.image.filename as string,
fileSize: edge.node.image.fileSize as number,
name: edge.node.image.filename as string,
size: edge.node.image.fileSize as number,
source: 'picker' as const,
type: edge.node.type,
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
const localAssetURI = Platform.OS === 'ios' && asset.id && (await getLocalAssetUri(asset.id));
const uri = localAssetURI || asset.uri || '';
// We need a mime-type to upload a video file.
const mimeType = lookup(asset.filename) || 'multipart/form-data';
const mimeType = lookup(asset.name) || 'multipart/form-data';
return [
...files,
{
duration: durationLabel,
id: asset.id,
mimeType,
name: asset.filename,
size: asset.fileSize,
name: asset.name,
size: asset.size,
uri,
},
];
Expand Down
2 changes: 1 addition & 1 deletion package/src/components/MessageInput/MessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ const MessageInputWithContext = <
// Check if the file size of the image exceeds the threshold of 100MB
if (
imageToUpload &&
Number(imageToUpload.fileSize) / MEGA_BYTES_TO_BYTES > MAX_FILE_SIZE_TO_UPLOAD_IN_MB
Number(imageToUpload.size) / MEGA_BYTES_TO_BYTES > MAX_FILE_SIZE_TO_UPLOAD_IN_MB
) {
Alert.alert(
t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ describe('MessageInput', () => {
selectedImages: [
generateImageAttachment({
file: { height: 100, uri: 'https://picsum.photos/200/300', width: 100 },
fileSize: 500000000,
size: 500000000,
uri: 'https://picsum.photos/200/300',
}),
generateImageAttachment({
file: { height: 100, uri: 'https://picsum.photos/200/300', width: 100 },
fileSize: 600000000,
size: 600000000,
uri: 'https://picsum.photos/200/300',
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ export const MessageInputProvider = <
};

const mapImageUploadToAttachment = (image: ImageUpload) => {
const mime_type: string | boolean = lookup(image.file.filename as string);
const mime_type: string | boolean = lookup(image.file.name as string);
return {
fallback: image.file.name,
image_url: image.url,
Expand Down Expand Up @@ -1006,7 +1006,7 @@ export const MessageInputProvider = <
uri,
width: file.width,
}));
const filename = file.filename ?? uri.replace(/^(file:\/\/|content:\/\/)/, '');
const filename = file.name ?? uri.replace(/^(file:\/\/|content:\/\/)/, '');
const contentType = lookup(filename) || 'multipart/form-data';
if (value.doImageUploadRequest) {
response = await value.doImageUploadRequest(file, channel);
Expand Down
18 changes: 7 additions & 11 deletions package/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,28 @@ import type { ExtendableGenerics, LiteralStringForUnion } from 'stream-chat';

export type Asset = {
duration: number | null;
filename: string;
height: number;
name: string;
source: 'camera' | 'picker';
type: string;
uri: string;
width: number;
fileSize?: number;
id?: string;
size?: number | string;
size?: number;
};

export type FileAssetType = {
export type File = {
name: string;
duration?: string | null;
id?: string;
mimeType?: string;
size?: number | string;
size?: number;
// The uri should be of type `string`. But is `string|undefined` because the same type is used for the response from Stream's Attachment. This shall be fixed.
uri?: string;
};

export type File = FileAssetType & {
duration?: string | null;
id?: string;
};

export type DefaultAttachmentType = UnknownType & {
file_size?: number | string;
file_size?: number;
mime_type?: string;
originalFile?: File;
};
Expand Down

0 comments on commit f8f4d14

Please sign in to comment.