2020-07-03 20:55:33 +00:00
|
|
|
import React from 'react';
|
2020-04-04 20:24:03 +00:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2021-05-04 04:26:09 +00:00
|
|
|
import { faArchive, faEllipsisH, faLock } from '@fortawesome/free-solid-svg-icons';
|
2020-07-03 20:55:33 +00:00
|
|
|
import { format, formatDistanceToNow } from 'date-fns';
|
2020-04-04 20:24:03 +00:00
|
|
|
import Spinner from '@/components/elements/Spinner';
|
2020-04-05 02:54:59 +00:00
|
|
|
import { bytesToHuman } from '@/helpers';
|
|
|
|
import Can from '@/components/elements/Can';
|
2020-04-07 04:22:57 +00:00
|
|
|
import useWebsocketEvent from '@/plugins/useWebsocketEvent';
|
2020-04-10 05:08:09 +00:00
|
|
|
import BackupContextMenu from '@/components/server/backups/BackupContextMenu';
|
2020-07-04 23:26:07 +00:00
|
|
|
import tw from 'twin.macro';
|
|
|
|
import GreyRowBox from '@/components/elements/GreyRowBox';
|
2020-08-21 04:44:33 +00:00
|
|
|
import getServerBackups from '@/api/swr/getServerBackups';
|
|
|
|
import { ServerBackup } from '@/api/server/types';
|
2021-01-31 02:43:46 +00:00
|
|
|
import { SocketEvent } from '@/components/server/events';
|
2020-04-04 20:24:03 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
backup: ServerBackup;
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
2020-04-07 05:25:54 +00:00
|
|
|
export default ({ backup, className }: Props) => {
|
2020-08-21 04:44:33 +00:00
|
|
|
const { mutate } = getServerBackups();
|
2020-04-07 05:25:54 +00:00
|
|
|
|
2021-01-31 02:43:46 +00:00
|
|
|
useWebsocketEvent(`${SocketEvent.BACKUP_COMPLETED}:${backup.uuid}` as SocketEvent, data => {
|
2020-04-07 04:22:57 +00:00
|
|
|
try {
|
|
|
|
const parsed = JSON.parse(data);
|
2020-08-21 04:44:33 +00:00
|
|
|
|
|
|
|
mutate(data => ({
|
|
|
|
...data,
|
|
|
|
items: data.items.map(b => b.uuid !== backup.uuid ? b : ({
|
|
|
|
...b,
|
|
|
|
isSuccessful: parsed.is_successful || true,
|
2020-10-31 23:44:20 +00:00
|
|
|
checksum: (parsed.checksum_type || '') + ':' + (parsed.checksum || ''),
|
2020-08-21 04:44:33 +00:00
|
|
|
bytes: parsed.file_size || 0,
|
|
|
|
completedAt: new Date(),
|
|
|
|
})),
|
|
|
|
}), false);
|
2020-04-07 04:22:57 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-04 20:24:03 +00:00
|
|
|
return (
|
2020-12-26 17:50:09 +00:00
|
|
|
<GreyRowBox css={tw`flex-wrap md:flex-nowrap items-center`} className={className}>
|
2020-10-03 23:25:39 +00:00
|
|
|
<div css={tw`flex items-center truncate w-full md:flex-1`}>
|
|
|
|
<div css={tw`mr-4`}>
|
|
|
|
{backup.completedAt ?
|
2021-05-04 04:26:09 +00:00
|
|
|
backup.isLocked ?
|
|
|
|
<FontAwesomeIcon icon={faLock} css={tw`text-yellow-500`}/>
|
|
|
|
:
|
|
|
|
<FontAwesomeIcon icon={faArchive} css={tw`text-neutral-300`}/>
|
2020-10-03 23:25:39 +00:00
|
|
|
:
|
|
|
|
<Spinner size={'small'}/>
|
2020-08-21 04:44:33 +00:00
|
|
|
}
|
2020-10-03 23:25:39 +00:00
|
|
|
</div>
|
|
|
|
<div css={tw`flex flex-col truncate`}>
|
|
|
|
<div css={tw`flex items-center text-sm mb-1`}>
|
|
|
|
{!backup.isSuccessful &&
|
|
|
|
<span css={tw`bg-red-500 py-px px-2 rounded-full text-white text-xs uppercase border border-red-600 mr-2`}>
|
|
|
|
Failed
|
|
|
|
</span>
|
|
|
|
}
|
2020-10-11 19:34:48 +00:00
|
|
|
<p css={tw`break-words truncate`}>
|
2020-10-03 23:25:39 +00:00
|
|
|
{backup.name}
|
|
|
|
</p>
|
|
|
|
{(backup.completedAt && backup.isSuccessful) &&
|
2020-12-26 17:50:09 +00:00
|
|
|
<span css={tw`ml-3 text-neutral-300 text-xs font-extralight hidden sm:inline`}>{bytesToHuman(backup.bytes)}</span>
|
2020-10-03 23:25:39 +00:00
|
|
|
}
|
2020-10-03 18:22:37 +00:00
|
|
|
</div>
|
2020-10-03 23:25:39 +00:00
|
|
|
<p css={tw`mt-1 md:mt-0 text-xs text-neutral-400 font-mono truncate`}>
|
2021-05-04 04:26:09 +00:00
|
|
|
{backup.checksum}
|
2020-10-03 23:25:39 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2020-04-04 20:24:03 +00:00
|
|
|
</div>
|
2020-10-03 23:25:39 +00:00
|
|
|
<div css={tw`flex-1 md:flex-none md:w-48 mt-4 md:mt-0 md:ml-8 md:text-center`}>
|
2020-04-04 20:24:03 +00:00
|
|
|
<p
|
2020-07-04 23:26:07 +00:00
|
|
|
title={format(backup.createdAt, 'ddd, MMMM do, yyyy HH:mm:ss')}
|
|
|
|
css={tw`text-sm`}
|
2020-04-04 20:24:03 +00:00
|
|
|
>
|
2020-07-03 20:55:33 +00:00
|
|
|
{formatDistanceToNow(backup.createdAt, { includeSeconds: true, addSuffix: true })}
|
2020-04-04 20:24:03 +00:00
|
|
|
</p>
|
2020-07-04 23:26:07 +00:00
|
|
|
<p css={tw`text-2xs text-neutral-500 uppercase mt-1`}>Created</p>
|
2020-04-04 20:24:03 +00:00
|
|
|
</div>
|
2020-04-05 02:54:59 +00:00
|
|
|
<Can action={'backup.download'}>
|
2020-10-03 23:25:39 +00:00
|
|
|
<div css={tw`mt-4 md:mt-0 ml-6`} style={{ marginRight: '-0.5rem' }}>
|
2020-04-05 02:54:59 +00:00
|
|
|
{!backup.completedAt ?
|
2020-07-04 23:26:07 +00:00
|
|
|
<div css={tw`p-2 invisible`}>
|
2020-04-10 05:08:09 +00:00
|
|
|
<FontAwesomeIcon icon={faEllipsisH}/>
|
2020-04-05 02:54:59 +00:00
|
|
|
</div>
|
|
|
|
:
|
2020-04-10 05:08:09 +00:00
|
|
|
<BackupContextMenu backup={backup}/>
|
2020-04-05 02:54:59 +00:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</Can>
|
2020-07-04 23:26:07 +00:00
|
|
|
</GreyRowBox>
|
2020-04-04 20:24:03 +00:00
|
|
|
);
|
|
|
|
};
|