Merge branch 'develop' into feature/file-uploads
This commit is contained in:
commit
54f9c5f187
136 changed files with 2178 additions and 971 deletions
|
@ -1,8 +1,8 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (email: string): Promise<string> => {
|
||||
export default (email: string, recaptchaData?: string): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post('/auth/password', { email })
|
||||
http.post('/auth/password', { email, 'g-recaptcha-response': recaptchaData })
|
||||
.then(response => resolve(response.data.status || ''))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
import { rawDataToServerObject, Server } from '@/api/server/getServer';
|
||||
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
|
||||
export default (query?: string, includeAdmin?: boolean): Promise<PaginatedResult<Server>> => {
|
||||
interface QueryParams {
|
||||
query?: string;
|
||||
page?: number;
|
||||
onlyAdmin?: boolean;
|
||||
}
|
||||
|
||||
export default ({ query, page = 1, onlyAdmin = false }: QueryParams): Promise<PaginatedResult<Server>> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/client', {
|
||||
params: {
|
||||
include: [ 'allocation' ],
|
||||
type: includeAdmin ? 'all' : undefined,
|
||||
type: onlyAdmin ? 'admin' : undefined,
|
||||
'filter[name]': query,
|
||||
page,
|
||||
},
|
||||
})
|
||||
.then(({ data }) => resolve({
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { rawDataToServerBackup, ServerBackup } from '@/api/server/backups/getServerBackups';
|
||||
import http from '@/api/http';
|
||||
import { ServerBackup } from '@/api/server/types';
|
||||
import { rawDataToServerBackup } from '@/api/transformers';
|
||||
|
||||
export default (uuid: string, name?: string, ignored?: string): Promise<ServerBackup> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
|
||||
export interface ServerBackup {
|
||||
uuid: string;
|
||||
name: string;
|
||||
ignoredFiles: string;
|
||||
sha256Hash: string;
|
||||
bytes: number;
|
||||
createdAt: Date;
|
||||
completedAt: Date | null;
|
||||
}
|
||||
|
||||
export const rawDataToServerBackup = ({ attributes }: FractalResponseData): ServerBackup => ({
|
||||
uuid: attributes.uuid,
|
||||
name: attributes.name,
|
||||
ignoredFiles: attributes.ignored_files,
|
||||
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);
|
||||
});
|
||||
};
|
|
@ -4,8 +4,8 @@ import { rawDataToFileObject } from '@/api/transformers';
|
|||
|
||||
export default async (uuid: string, directory: string, files: string[]): Promise<FileObject> => {
|
||||
const { data } = await http.post(`/api/client/servers/${uuid}/files/compress`, { root: directory, files }, {
|
||||
timeout: 300000,
|
||||
timeoutErrorMessage: 'It looks like this archive is taking a long time to generate. It will appear when completed.',
|
||||
timeout: 60000,
|
||||
timeoutErrorMessage: 'It looks like this archive is taking a long time to generate. It will appear once completed.',
|
||||
});
|
||||
|
||||
return rawDataToFileObject(data);
|
||||
|
|
8
resources/scripts/api/server/files/decompressFiles.ts
Normal file
8
resources/scripts/api/server/files/decompressFiles.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default async (uuid: string, directory: string, file: string): Promise<void> => {
|
||||
await http.post(`/api/client/servers/${uuid}/files/decompress`, { root: directory, file }, {
|
||||
timeout: 300000,
|
||||
timeoutErrorMessage: 'It looks like this archive is taking a long time to be unarchived. Once completed the unarchived files will appear.',
|
||||
});
|
||||
};
|
|
@ -2,7 +2,7 @@ import http from '@/api/http';
|
|||
import { rawDataToFileObject } from '@/api/transformers';
|
||||
|
||||
export interface FileObject {
|
||||
uuid: string;
|
||||
key: string;
|
||||
name: string;
|
||||
mode: string;
|
||||
size: number;
|
||||
|
@ -12,6 +12,7 @@ export interface FileObject {
|
|||
mimetype: string;
|
||||
createdAt: Date;
|
||||
modifiedAt: Date;
|
||||
isArchiveType: () => boolean;
|
||||
}
|
||||
|
||||
export default async (uuid: string, directory?: string): Promise<FileObject[]> => {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import http, { FractalResponseData, FractalResponseList } from '@/api/http';
|
||||
import { rawDataToServerAllocation } from '@/api/transformers';
|
||||
import { rawDataToServerAllocation, rawDataToServerEggVariable } from '@/api/transformers';
|
||||
import { ServerEggVariable } from '@/api/server/types';
|
||||
|
||||
export interface Allocation {
|
||||
id: number;
|
||||
|
@ -19,8 +20,8 @@ export interface Server {
|
|||
ip: string;
|
||||
port: number;
|
||||
};
|
||||
invocation: string;
|
||||
description: string;
|
||||
allocations: Allocation[];
|
||||
limits: {
|
||||
memory: number;
|
||||
swap: number;
|
||||
|
@ -36,6 +37,8 @@ export interface Server {
|
|||
};
|
||||
isSuspended: boolean;
|
||||
isInstalling: boolean;
|
||||
variables: ServerEggVariable[];
|
||||
allocations: Allocation[];
|
||||
}
|
||||
|
||||
export const rawDataToServerObject = ({ attributes: data }: FractalResponseData): Server => ({
|
||||
|
@ -43,6 +46,7 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData)
|
|||
uuid: data.uuid,
|
||||
name: data.name,
|
||||
node: data.node,
|
||||
invocation: data.invocation,
|
||||
sftpDetails: {
|
||||
ip: data.sftp_details.ip,
|
||||
port: data.sftp_details.port,
|
||||
|
@ -52,6 +56,7 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData)
|
|||
featureLimits: { ...data.feature_limits },
|
||||
isSuspended: data.is_suspended,
|
||||
isInstalling: data.is_installing,
|
||||
variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(rawDataToServerEggVariable),
|
||||
allocations: ((data.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(rawDataToServerAllocation),
|
||||
});
|
||||
|
||||
|
|
20
resources/scripts/api/server/types.d.ts
vendored
Normal file
20
resources/scripts/api/server/types.d.ts
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
export interface ServerBackup {
|
||||
uuid: string;
|
||||
isSuccessful: boolean;
|
||||
name: string;
|
||||
ignoredFiles: string;
|
||||
sha256Hash: string;
|
||||
bytes: number;
|
||||
createdAt: Date;
|
||||
completedAt: Date | null;
|
||||
}
|
||||
|
||||
export interface ServerEggVariable {
|
||||
name: string;
|
||||
description: string;
|
||||
envVariable: string;
|
||||
defaultValue: string;
|
||||
serverValue: string;
|
||||
isEditable: boolean;
|
||||
rules: string[];
|
||||
}
|
9
resources/scripts/api/server/updateStartupVariable.ts
Normal file
9
resources/scripts/api/server/updateStartupVariable.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import http from '@/api/http';
|
||||
import { ServerEggVariable } from '@/api/server/types';
|
||||
import { rawDataToServerEggVariable } from '@/api/transformers';
|
||||
|
||||
export default async (uuid: string, key: string, value: string): Promise<ServerEggVariable> => {
|
||||
const { data } = await http.put(`/api/client/servers/${uuid}/startup/variable`, { key, value });
|
||||
|
||||
return rawDataToServerEggVariable(data);
|
||||
};
|
18
resources/scripts/api/swr/getServerBackups.ts
Normal file
18
resources/scripts/api/swr/getServerBackups.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import useSWR from 'swr';
|
||||
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import { ServerBackup } from '@/api/server/types';
|
||||
import { rawDataToServerBackup } from '@/api/transformers';
|
||||
import useServer from '@/plugins/useServer';
|
||||
|
||||
export default (page?: number | string) => {
|
||||
const { uuid } = useServer();
|
||||
|
||||
return useSWR<PaginatedResult<ServerBackup>>([ 'server:backups', uuid, page ], async () => {
|
||||
const { data } = await http.get(`/api/client/servers/${uuid}/backups`, { params: { page } });
|
||||
|
||||
return ({
|
||||
items: (data.data || []).map(rawDataToServerBackup),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
import { Allocation } from '@/api/server/getServer';
|
||||
import { FractalResponseData } from '@/api/http';
|
||||
import { FileObject } from '@/api/server/files/loadDirectory';
|
||||
import v4 from 'uuid/v4';
|
||||
import { ServerBackup, ServerEggVariable } from '@/api/server/types';
|
||||
|
||||
export const rawDataToServerAllocation = (data: FractalResponseData): Allocation => ({
|
||||
id: data.attributes.id,
|
||||
|
@ -13,7 +13,7 @@ export const rawDataToServerAllocation = (data: FractalResponseData): Allocation
|
|||
});
|
||||
|
||||
export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({
|
||||
uuid: v4(),
|
||||
key: `${data.attributes.is_file ? 'file' : 'dir'}_${data.attributes.name}`,
|
||||
name: data.attributes.name,
|
||||
mode: data.attributes.mode,
|
||||
size: Number(data.attributes.size),
|
||||
|
@ -23,4 +23,41 @@ export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({
|
|||
mimetype: data.attributes.mimetype,
|
||||
createdAt: new Date(data.attributes.created_at),
|
||||
modifiedAt: new Date(data.attributes.modified_at),
|
||||
|
||||
isArchiveType: function () {
|
||||
return this.isFile && [
|
||||
'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
|
||||
].indexOf(this.mimetype) >= 0;
|
||||
},
|
||||
});
|
||||
|
||||
export const rawDataToServerBackup = ({ attributes }: FractalResponseData): ServerBackup => ({
|
||||
uuid: attributes.uuid,
|
||||
isSuccessful: attributes.is_successful,
|
||||
name: attributes.name,
|
||||
ignoredFiles: attributes.ignored_files,
|
||||
sha256Hash: attributes.sha256_hash,
|
||||
bytes: attributes.bytes,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
completedAt: attributes.completed_at ? new Date(attributes.completed_at) : null,
|
||||
});
|
||||
|
||||
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('|'),
|
||||
});
|
||||
|
|
Reference in a new issue