mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 07:24:56 -06:00
42 lines
821 B
JavaScript
42 lines
821 B
JavaScript
// @flow
|
|
import type { ImageRaw } from '../records/ImageRecord';
|
|
import { fetchRequest, fetchRequestBinary } from './FetchApi';
|
|
|
|
export const getImages = (productId: string): Promise<Array<ImageRaw>> => {
|
|
return fetchRequest({
|
|
endpoint: `/images/${productId}`,
|
|
method: 'GET',
|
|
});
|
|
};
|
|
|
|
export const addImage = async ({
|
|
productId,
|
|
username,
|
|
imageUri,
|
|
}: {
|
|
productId: string,
|
|
username: string,
|
|
imageUri: string,
|
|
}) => {
|
|
const body = new FormData();
|
|
|
|
// $FlowFixMe - react-native does different stuff with FormData
|
|
body.append('photo', {
|
|
uri: imageUri,
|
|
type: 'image/jpeg',
|
|
name: 'photo.jpg',
|
|
});
|
|
|
|
body.append('username', username);
|
|
|
|
const res = await fetchRequestBinary({
|
|
endpoint: `/images/${productId}`,
|
|
body,
|
|
});
|
|
|
|
if (!res.ok) {
|
|
throw new Error(await res.text());
|
|
}
|
|
|
|
return res.json();
|
|
};
|