2020-07-10 02:56:46 +00:00
|
|
|
import { Allocation } from '@/api/server/getServer';
|
|
|
|
import { FractalResponseData } from '@/api/http';
|
2020-07-11 20:38:49 +00:00
|
|
|
import { FileObject } from '@/api/server/files/loadDirectory';
|
2020-08-23 01:13:59 +00:00
|
|
|
import { ServerBackup, ServerEggVariable } from '@/api/server/types';
|
2020-07-10 02:56:46 +00:00
|
|
|
|
|
|
|
export const rawDataToServerAllocation = (data: FractalResponseData): Allocation => ({
|
2020-07-10 03:36:08 +00:00
|
|
|
id: data.attributes.id,
|
2020-07-10 02:56:46 +00:00
|
|
|
ip: data.attributes.ip,
|
|
|
|
alias: data.attributes.ip_alias,
|
|
|
|
port: data.attributes.port,
|
2020-07-10 03:36:08 +00:00
|
|
|
notes: data.attributes.notes,
|
2020-07-10 02:56:46 +00:00
|
|
|
isDefault: data.attributes.is_default,
|
|
|
|
});
|
2020-07-11 20:38:49 +00:00
|
|
|
|
|
|
|
export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({
|
2020-08-02 01:48:58 +00:00
|
|
|
key: `${data.attributes.is_file ? 'file' : 'dir'}_${data.attributes.name}`,
|
2020-07-11 20:38:49 +00:00
|
|
|
name: data.attributes.name,
|
|
|
|
mode: data.attributes.mode,
|
|
|
|
size: Number(data.attributes.size),
|
|
|
|
isFile: data.attributes.is_file,
|
|
|
|
isSymlink: data.attributes.is_symlink,
|
|
|
|
isEditable: data.attributes.is_editable,
|
|
|
|
mimetype: data.attributes.mimetype,
|
|
|
|
createdAt: new Date(data.attributes.created_at),
|
|
|
|
modifiedAt: new Date(data.attributes.modified_at),
|
2020-07-15 04:16:49 +00:00
|
|
|
|
|
|
|
isArchiveType: function () {
|
|
|
|
return this.isFile && [
|
2020-07-15 19:09:45 +00:00
|
|
|
'application/vnd.rar', // .rar
|
|
|
|
'application/x-rar-compressed', // .rar (2)
|
|
|
|
'application/x-tar', // .tar
|
|
|
|
'application/x-br', // .tar.br
|
|
|
|
'application/x-bzip2', // .tar.bz2, .bz2
|
|
|
|
'application/gzip', // .tar.gz, .gz
|
|
|
|
'application/x-lzip', // .tar.lz4, .lz4 (not sure if this mime type is correct)
|
|
|
|
'application/x-sz', // .tar.sz, .sz (not sure if this mime type is correct)
|
|
|
|
'application/x-xz', // .tar.xz, .xz
|
|
|
|
'application/zstd', // .tar.zst, .zst
|
|
|
|
'application/zip', // .zip
|
2020-07-15 04:16:49 +00:00
|
|
|
].indexOf(this.mimetype) >= 0;
|
|
|
|
},
|
2020-07-11 20:38:49 +00:00
|
|
|
});
|
2020-08-22 22:46:13 +00:00
|
|
|
|
|
|
|
export const rawDataToServerBackup = ({ attributes }: FractalResponseData): ServerBackup => ({
|
|
|
|
uuid: attributes.uuid,
|
|
|
|
isSuccessful: attributes.is_successful,
|
|
|
|
name: attributes.name,
|
|
|
|
ignoredFiles: attributes.ignored_files,
|
2020-08-24 01:06:47 +00:00
|
|
|
checksum: attributes.checksum,
|
2020-08-22 22:46:13 +00:00
|
|
|
bytes: attributes.bytes,
|
|
|
|
createdAt: new Date(attributes.created_at),
|
|
|
|
completedAt: attributes.completed_at ? new Date(attributes.completed_at) : null,
|
|
|
|
});
|
2020-08-23 01:13:59 +00:00
|
|
|
|
|
|
|
export const rawDataToServerEggVariable = ({ attributes }: FractalResponseData): ServerEggVariable => ({
|
|
|
|
name: attributes.name,
|
|
|
|
description: attributes.description,
|
|
|
|
envVariable: attributes.env_variable,
|
|
|
|
defaultValue: attributes.default_value,
|
|
|
|
serverValue: attributes.server_value,
|
|
|
|
isEditable: attributes.is_editable,
|
|
|
|
rules: attributes.rules.split('|'),
|
|
|
|
});
|