Files
photos/frontend/src/redux/api/photos.ts

57 lines
1.6 KiB
TypeScript

import { IPhotoReqJSON } from "~/src/shared/types";
import {
IPhotosByIDGetRespBody,
IPhotosDeleteRespBody,
IPhotosListRespBody,
IPhotosNewRespBody,
IPhotosUploadRespBody,
} from "~/src/shared/types";
import { apiRoot } from "~src/env";
import { fetchJSONAuth } from "./utils";
export function getPhotoImgPath(photo: IPhotoReqJSON): string {
return `${apiRoot}/photos/showByID/${photo.id}/${photo.accessToken}`;
}
export function getPhotoThumbPath(photo: IPhotoReqJSON, size: number): string {
return `${apiRoot}/photos/showByID/${photo.id}/${
photo.accessToken
}?size=${size.toString()}`;
}
export async function fetchPhotosList(
skip: number,
num: number,
): Promise<IPhotosListRespBody> {
const params = new URLSearchParams({
skip: skip.toString(),
num: num.toString(),
});
return fetchJSONAuth(`/photos/list?${params.toString()}`, "GET");
}
export async function fetchPhoto(id: number): Promise<IPhotosByIDGetRespBody> {
return fetchJSONAuth(`/photos/byID/${id}`, "GET");
}
export async function createPhoto(
hash: string,
size: string,
format: string,
): Promise<IPhotosNewRespBody> {
return fetchJSONAuth("/photos/new", "POST", { hash, size, format });
}
export async function uploadPhoto(
file: File,
id: number,
): Promise<IPhotosUploadRespBody> {
return fetchJSONAuth(`/photos/upload/${id}`, "POST", file);
}
export async function deletePhotos(
photos: IPhotoReqJSON[],
): Promise<IPhotosDeleteRespBody> {
return fetchJSONAuth(`/photos/delete`, "POST", { photos });
}