import { getHeaders } from './utils';

export const fetchImage = async (project: string,
                                 id: string,
                                 maxWidth: number,
                                 maxHeight: number,
                                 token: string): Promise<string> => {

    const response = await fetch(getImageUrl(project, id, maxWidth, maxHeight), { headers: getHeaders(token) });
    if (response.ok) return URL.createObjectURL(await response.blob());
    else throw (await response.json());
};


const getImageUrl = (project: string, id: string, maxWidth: number, maxHeight: number) =>
    `/api/images/${project}/${id}${false /* if production */ ? '.jp2' : ''}/full%2F!${maxWidth},${maxHeight}%2F0%2Fdefault.jpg?q=hallo`;

export const fetchImage = async (project: string,
                                 id: string,
                                 maxWidth: number,
                                 maxHeight: number,
                                 token: string): Promise<string> => {

    const imageUrl = getImageUrl(project, id, maxWidth, maxHeight, token);
    const response = await fetch(imageUrl);
    if (response.ok) return URL.createObjectURL(await response.blob());
    else throw (await response.json());
};


const getImageUrl = (project: string, id: string, maxWidth: number, maxHeight: number, token: string) =>
    `/api/images/${project}/${id}${false /* if production */ ? '.jp2' : ''}/${token}/full/!${maxWidth},${maxHeight}/0/default.jpg`;

Make links work in frontend
Make links work in frontend
