mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 04: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 = (foodItemId: string): Promise<Array<ImageRaw>> => {
|
|
return fetchRequest({
|
|
endpoint: `/images/${foodItemId}`,
|
|
method: "GET"
|
|
});
|
|
};
|
|
|
|
export const addImage = async ({
|
|
foodItemId,
|
|
username,
|
|
imageUri
|
|
}: {
|
|
foodItemId: 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/${foodItemId}`,
|
|
body
|
|
});
|
|
|
|
if (!res.ok) {
|
|
throw new Error(await res.text());
|
|
}
|
|
|
|
return res.json();
|
|
};
|