32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
|
|
|
|
export interface ServerBackup {
|
|
uuid: string;
|
|
name: string;
|
|
contents: string;
|
|
sha256Hash: string;
|
|
bytes: number;
|
|
createdAt: Date;
|
|
completedAt: Date | null;
|
|
}
|
|
|
|
export const rawDataToServerBackup = ({ attributes }: FractalResponseData): ServerBackup => ({
|
|
uuid: attributes.uuid,
|
|
name: attributes.name,
|
|
contents: attributes.contents,
|
|
sha256Hash: attributes.sha256_hash,
|
|
bytes: attributes.bytes,
|
|
createdAt: new Date(attributes.created_at),
|
|
completedAt: attributes.completed_at ? new Date(attributes.completed_at) : null,
|
|
});
|
|
|
|
export default (uuid: string, page?: number | string): Promise<PaginatedResult<ServerBackup>> => {
|
|
return new Promise((resolve, reject) => {
|
|
http.get(`/api/client/servers/${uuid}/backups`, { params: { page } })
|
|
.then(({ data }) => resolve({
|
|
items: (data.data || []).map(rawDataToServerBackup),
|
|
pagination: getPaginationSet(data.meta.pagination),
|
|
}))
|
|
.catch(reject);
|
|
});
|
|
};
|