Compare commits

...

14 Commits

Author SHA1 Message Date
Nicolas Meienberger
3c2791102f refactor(backends): cleanup code 2025-11-20 06:57:31 +01:00
Nicolas Meienberger
b70f973c12 refactor(create-volume-form): move to volumes module 2025-11-19 19:25:54 +01:00
Renan Bernordi
14dadc85e7 new abstract method for volumepath 2025-11-16 17:47:23 -03:00
Renan Bernordi
ff16c6914d revert spawn 2025-11-16 17:14:53 -03:00
Renan Bernordi
b333489ae6 cleanup 2025-11-16 17:14:16 -03:00
Renan Bernordi
0efe57b62e remove sqlite 2025-11-16 17:03:20 -03:00
Renan Bernordi
0b6f64e16d update for constant 2025-11-16 16:48:19 -03:00
Renan Bernordi
eb28667d90 add mysql, mariadb, postgresql, sqlite volumes support 2025-11-15 23:32:26 -03:00
Nicolas Meienberger
c0bef7f65e chore: update versions in readme 2025-11-15 12:41:53 +01:00
Nicolas Meienberger
29c96c9fc6 ci: don't create gh release for alpha and beta versions 2025-11-15 12:28:34 +01:00
Nicolas Meienberger
2c0f22af59 fix(create-repo): don't try to load rclone remotes if the capability is disabled 2025-11-15 12:22:56 +01:00
Nicolas Meienberger
3ff6a04f8e feat(repositories): allow importing existing repos 2025-11-15 11:58:52 +01:00
Nicolas Meienberger
54ee02deb9 feat(backups): manual repository cleanup 2025-11-15 11:24:17 +01:00
Nicolas Meienberger
b83881c189 fix(backups): re-calculate next backup date before starting the backup 2025-11-15 11:13:23 +01:00
50 changed files with 5111 additions and 4029 deletions

View File

@@ -77,7 +77,8 @@ jobs:
publish-release: publish-release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [build-images] needs: [build-images, determine-release-type]
if: needs.determine-release-type.outputs.release_type == 'release'
outputs: outputs:
id: ${{ steps.create_release.outputs.id }} id: ${{ steps.create_release.outputs.id }}
steps: steps:

View File

@@ -2,8 +2,11 @@ ARG BUN_VERSION="1.3.1"
FROM oven/bun:${BUN_VERSION}-alpine AS base FROM oven/bun:${BUN_VERSION}-alpine AS base
RUN apk add --no-cache davfs2=1.6.1-r2 RUN apk add --no-cache \
davfs2=1.6.1-r2 \
mariadb-client \
mysql-client \
postgresql-client
# ------------------------------ # ------------------------------
# DEPENDENCIES # DEPENDENCIES

View File

@@ -36,7 +36,7 @@ In order to run Ironmount, you need to have Docker and Docker Compose installed
```yaml ```yaml
services: services:
ironmount: ironmount:
image: ghcr.io/nicotsx/ironmount:v0.8 image: ghcr.io/nicotsx/ironmount:v0.9
container_name: ironmount container_name: ironmount
restart: unless-stopped restart: unless-stopped
cap_add: cap_add:
@@ -68,7 +68,7 @@ If you want to track a local directory on the same server where Ironmount is run
```diff ```diff
services: services:
ironmount: ironmount:
image: ghcr.io/nicotsx/ironmount:v0.8 image: ghcr.io/nicotsx/ironmount:v0.9
container_name: ironmount container_name: ironmount
restart: unless-stopped restart: unless-stopped
cap_add: cap_add:
@@ -133,7 +133,7 @@ Ironmount can use [rclone](https://rclone.org/) to support 40+ cloud storage pro
```diff ```diff
services: services:
ironmount: ironmount:
image: ghcr.io/nicotsx/ironmount:v0.8 image: ghcr.io/nicotsx/ironmount:v0.9
container_name: ironmount container_name: ironmount
restart: unless-stopped restart: unless-stopped
cap_add: cap_add:
@@ -189,7 +189,7 @@ In order to enable this feature, you need to change your bind mount `/var/lib/ir
```diff ```diff
services: services:
ironmount: ironmount:
image: ghcr.io/nicotsx/ironmount:v0.8 image: ghcr.io/nicotsx/ironmount:v0.9
container_name: ironmount container_name: ironmount
restart: unless-stopped restart: unless-stopped
ports: ports:
@@ -217,7 +217,7 @@ In order to enable this feature, you need to run Ironmount with several items sh
```diff ```diff
services: services:
ironmount: ironmount:
image: ghcr.io/nicotsx/ironmount:v0.8 image: ghcr.io/nicotsx/ironmount:v0.9
container_name: ironmount container_name: ironmount
restart: unless-stopped restart: unless-stopped
cap_add: cap_add:

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
import { type ClientOptions, type Config, createClient, createConfig } from "./client"; import { type ClientOptions, type Config, createClient, createConfig } from './client';
import type { ClientOptions as ClientOptions2 } from "./types.gen"; import type { ClientOptions as ClientOptions2 } from './types.gen';
/** /**
* The `createClientConfig()` function will be called on client initialization * The `createClientConfig()` function will be called on client initialization
@@ -11,12 +11,8 @@ import type { ClientOptions as ClientOptions2 } from "./types.gen";
* `setConfig()`. This is useful for example if you're using Next.js * `setConfig()`. This is useful for example if you're using Next.js
* to ensure your client always has the correct values. * to ensure your client always has the correct values.
*/ */
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = ( export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
override?: Config<ClientOptions & T>,
) => Config<Required<ClientOptions> & T>;
export const client = createClient( export const client = createClient(createConfig<ClientOptions2>({
createConfig<ClientOptions2>({ baseUrl: 'http://192.168.2.42:4096'
baseUrl: "http://192.168.2.42:4096", }));
}),
);

View File

@@ -1,9 +1,14 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
import { createSseClient } from "../core/serverSentEvents.gen"; import { createSseClient } from '../core/serverSentEvents.gen';
import type { HttpMethod } from "../core/types.gen"; import type { HttpMethod } from '../core/types.gen';
import { getValidRequestBody } from "../core/utils.gen"; import { getValidRequestBody } from '../core/utils.gen';
import type { Client, Config, RequestOptions, ResolvedRequestOptions } from "./types.gen"; import type {
Client,
Config,
RequestOptions,
ResolvedRequestOptions,
} from './types.gen';
import { import {
buildUrl, buildUrl,
createConfig, createConfig,
@@ -12,9 +17,9 @@ import {
mergeConfigs, mergeConfigs,
mergeHeaders, mergeHeaders,
setAuthParams, setAuthParams,
} from "./utils.gen"; } from './utils.gen';
type ReqInit = Omit<RequestInit, "body" | "headers"> & { type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
body?: any; body?: any;
headers: ReturnType<typeof mergeHeaders>; headers: ReturnType<typeof mergeHeaders>;
}; };
@@ -29,7 +34,12 @@ export const createClient = (config: Config = {}): Client => {
return getConfig(); return getConfig();
}; };
const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>(); const interceptors = createInterceptors<
Request,
Response,
unknown,
ResolvedRequestOptions
>();
const beforeRequest = async (options: RequestOptions) => { const beforeRequest = async (options: RequestOptions) => {
const opts = { const opts = {
@@ -56,8 +66,8 @@ export const createClient = (config: Config = {}): Client => {
} }
// remove Content-Type header if body is empty to avoid sending invalid requests // remove Content-Type header if body is empty to avoid sending invalid requests
if (opts.body === undefined || opts.serializedBody === "") { if (opts.body === undefined || opts.serializedBody === '') {
opts.headers.delete("Content-Type"); opts.headers.delete('Content-Type');
} }
const url = buildUrl(opts); const url = buildUrl(opts);
@@ -65,11 +75,11 @@ export const createClient = (config: Config = {}): Client => {
return { opts, url }; return { opts, url };
}; };
const request: Client["request"] = async (options) => { const request: Client['request'] = async (options) => {
// @ts-expect-error // @ts-expect-error
const { opts, url } = await beforeRequest(options); const { opts, url } = await beforeRequest(options);
const requestInit: ReqInit = { const requestInit: ReqInit = {
redirect: "follow", redirect: 'follow',
...opts, ...opts,
body: getValidRequestBody(opts), body: getValidRequestBody(opts),
}; };
@@ -95,7 +105,12 @@ export const createClient = (config: Config = {}): Client => {
for (const fn of interceptors.error.fns) { for (const fn of interceptors.error.fns) {
if (fn) { if (fn) {
finalError = (await fn(error, undefined as any, request, opts)) as unknown; finalError = (await fn(
error,
undefined as any,
request,
opts,
)) as unknown;
} }
} }
@@ -106,7 +121,7 @@ export const createClient = (config: Config = {}): Client => {
} }
// Return error response // Return error response
return opts.responseStyle === "data" return opts.responseStyle === 'data'
? undefined ? undefined
: { : {
error: finalError, error: finalError,
@@ -128,28 +143,33 @@ export const createClient = (config: Config = {}): Client => {
if (response.ok) { if (response.ok) {
const parseAs = const parseAs =
(opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json"; (opts.parseAs === 'auto'
? getParseAs(response.headers.get('Content-Type'))
: opts.parseAs) ?? 'json';
if (response.status === 204 || response.headers.get("Content-Length") === "0") { if (
response.status === 204 ||
response.headers.get('Content-Length') === '0'
) {
let emptyData: any; let emptyData: any;
switch (parseAs) { switch (parseAs) {
case "arrayBuffer": case 'arrayBuffer':
case "blob": case 'blob':
case "text": case 'text':
emptyData = await response[parseAs](); emptyData = await response[parseAs]();
break; break;
case "formData": case 'formData':
emptyData = new FormData(); emptyData = new FormData();
break; break;
case "stream": case 'stream':
emptyData = response.body; emptyData = response.body;
break; break;
case "json": case 'json':
default: default:
emptyData = {}; emptyData = {};
break; break;
} }
return opts.responseStyle === "data" return opts.responseStyle === 'data'
? emptyData ? emptyData
: { : {
data: emptyData, data: emptyData,
@@ -159,15 +179,15 @@ export const createClient = (config: Config = {}): Client => {
let data: any; let data: any;
switch (parseAs) { switch (parseAs) {
case "arrayBuffer": case 'arrayBuffer':
case "blob": case 'blob':
case "formData": case 'formData':
case "json": case 'json':
case "text": case 'text':
data = await response[parseAs](); data = await response[parseAs]();
break; break;
case "stream": case 'stream':
return opts.responseStyle === "data" return opts.responseStyle === 'data'
? response.body ? response.body
: { : {
data: response.body, data: response.body,
@@ -175,7 +195,7 @@ export const createClient = (config: Config = {}): Client => {
}; };
} }
if (parseAs === "json") { if (parseAs === 'json') {
if (opts.responseValidator) { if (opts.responseValidator) {
await opts.responseValidator(data); await opts.responseValidator(data);
} }
@@ -185,7 +205,7 @@ export const createClient = (config: Config = {}): Client => {
} }
} }
return opts.responseStyle === "data" return opts.responseStyle === 'data'
? data ? data
: { : {
data, data,
@@ -218,7 +238,7 @@ export const createClient = (config: Config = {}): Client => {
} }
// TODO: we probably want to return error and improve types // TODO: we probably want to return error and improve types
return opts.responseStyle === "data" return opts.responseStyle === 'data'
? undefined ? undefined
: { : {
error: finalError, error: finalError,
@@ -226,9 +246,12 @@ export const createClient = (config: Config = {}): Client => {
}; };
}; };
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) => request({ ...options, method }); const makeMethodFn =
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
request({ ...options, method });
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => { const makeSseFn =
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
const { opts, url } = await beforeRequest(options); const { opts, url } = await beforeRequest(options);
return createSseClient({ return createSseClient({
...opts, ...opts,
@@ -250,29 +273,29 @@ export const createClient = (config: Config = {}): Client => {
return { return {
buildUrl, buildUrl,
connect: makeMethodFn("CONNECT"), connect: makeMethodFn('CONNECT'),
delete: makeMethodFn("DELETE"), delete: makeMethodFn('DELETE'),
get: makeMethodFn("GET"), get: makeMethodFn('GET'),
getConfig, getConfig,
head: makeMethodFn("HEAD"), head: makeMethodFn('HEAD'),
interceptors, interceptors,
options: makeMethodFn("OPTIONS"), options: makeMethodFn('OPTIONS'),
patch: makeMethodFn("PATCH"), patch: makeMethodFn('PATCH'),
post: makeMethodFn("POST"), post: makeMethodFn('POST'),
put: makeMethodFn("PUT"), put: makeMethodFn('PUT'),
request, request,
setConfig, setConfig,
sse: { sse: {
connect: makeSseFn("CONNECT"), connect: makeSseFn('CONNECT'),
delete: makeSseFn("DELETE"), delete: makeSseFn('DELETE'),
get: makeSseFn("GET"), get: makeSseFn('GET'),
head: makeSseFn("HEAD"), head: makeSseFn('HEAD'),
options: makeSseFn("OPTIONS"), options: makeSseFn('OPTIONS'),
patch: makeSseFn("PATCH"), patch: makeSseFn('PATCH'),
post: makeSseFn("POST"), post: makeSseFn('POST'),
put: makeSseFn("PUT"), put: makeSseFn('PUT'),
trace: makeSseFn("TRACE"), trace: makeSseFn('TRACE'),
}, },
trace: makeMethodFn("TRACE"), trace: makeMethodFn('TRACE'),
} as Client; } as Client;
}; };

View File

@@ -1,15 +1,15 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
export type { Auth } from "../core/auth.gen"; export type { Auth } from '../core/auth.gen';
export type { QuerySerializerOptions } from "../core/bodySerializer.gen"; export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
export { export {
formDataBodySerializer, formDataBodySerializer,
jsonBodySerializer, jsonBodySerializer,
urlSearchParamsBodySerializer, urlSearchParamsBodySerializer,
} from "../core/bodySerializer.gen"; } from '../core/bodySerializer.gen';
export { buildClientParams } from "../core/params.gen"; export { buildClientParams } from '../core/params.gen';
export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen"; export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
export { createClient } from "./client.gen"; export { createClient } from './client.gen';
export type { export type {
Client, Client,
ClientOptions, ClientOptions,
@@ -21,5 +21,5 @@ export type {
ResolvedRequestOptions, ResolvedRequestOptions,
ResponseStyle, ResponseStyle,
TDataShape, TDataShape,
} from "./types.gen"; } from './types.gen';
export { createConfig, mergeHeaders } from "./utils.gen"; export { createConfig, mergeHeaders } from './utils.gen';

View File

@@ -1,19 +1,25 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
import type { Auth } from "../core/auth.gen"; import type { Auth } from '../core/auth.gen';
import type { ServerSentEventsOptions, ServerSentEventsResult } from "../core/serverSentEvents.gen"; import type {
import type { Client as CoreClient, Config as CoreConfig } from "../core/types.gen"; ServerSentEventsOptions,
import type { Middleware } from "./utils.gen"; ServerSentEventsResult,
} from '../core/serverSentEvents.gen';
import type {
Client as CoreClient,
Config as CoreConfig,
} from '../core/types.gen';
import type { Middleware } from './utils.gen';
export type ResponseStyle = "data" | "fields"; export type ResponseStyle = 'data' | 'fields';
export interface Config<T extends ClientOptions = ClientOptions> export interface Config<T extends ClientOptions = ClientOptions>
extends Omit<RequestInit, "body" | "headers" | "method">, extends Omit<RequestInit, 'body' | 'headers' | 'method'>,
CoreConfig { CoreConfig {
/** /**
* Base URL for all requests made by this client. * Base URL for all requests made by this client.
*/ */
baseUrl?: T["baseUrl"]; baseUrl?: T['baseUrl'];
/** /**
* Fetch API implementation. You can use this option to provide a custom * Fetch API implementation. You can use this option to provide a custom
* fetch instance. * fetch instance.
@@ -36,7 +42,14 @@ export interface Config<T extends ClientOptions = ClientOptions>
* *
* @default 'auto' * @default 'auto'
*/ */
parseAs?: "arrayBuffer" | "auto" | "blob" | "formData" | "json" | "stream" | "text"; parseAs?:
| 'arrayBuffer'
| 'auto'
| 'blob'
| 'formData'
| 'json'
| 'stream'
| 'text';
/** /**
* Should we return only data or multiple fields (data, error, response, etc.)? * Should we return only data or multiple fields (data, error, response, etc.)?
* *
@@ -48,12 +61,12 @@ export interface Config<T extends ClientOptions = ClientOptions>
* *
* @default false * @default false
*/ */
throwOnError?: T["throwOnError"]; throwOnError?: T['throwOnError'];
} }
export interface RequestOptions< export interface RequestOptions<
TData = unknown, TData = unknown,
TResponseStyle extends ResponseStyle = "fields", TResponseStyle extends ResponseStyle = 'fields',
ThrowOnError extends boolean = boolean, ThrowOnError extends boolean = boolean,
Url extends string = string, Url extends string = string,
> extends Config<{ > extends Config<{
@@ -62,7 +75,11 @@ export interface RequestOptions<
}>, }>,
Pick< Pick<
ServerSentEventsOptions<TData>, ServerSentEventsOptions<TData>,
"onSseError" | "onSseEvent" | "sseDefaultRetryDelay" | "sseMaxRetryAttempts" | "sseMaxRetryDelay" | 'onSseError'
| 'onSseEvent'
| 'sseDefaultRetryDelay'
| 'sseMaxRetryAttempts'
| 'sseMaxRetryDelay'
> { > {
/** /**
* Any body that you want to add to your request. * Any body that you want to add to your request.
@@ -80,7 +97,7 @@ export interface RequestOptions<
} }
export interface ResolvedRequestOptions< export interface ResolvedRequestOptions<
TResponseStyle extends ResponseStyle = "fields", TResponseStyle extends ResponseStyle = 'fields',
ThrowOnError extends boolean = boolean, ThrowOnError extends boolean = boolean,
Url extends string = string, Url extends string = string,
> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> { > extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
@@ -91,30 +108,40 @@ export type RequestResult<
TData = unknown, TData = unknown,
TError = unknown, TError = unknown,
ThrowOnError extends boolean = boolean, ThrowOnError extends boolean = boolean,
TResponseStyle extends ResponseStyle = "fields", TResponseStyle extends ResponseStyle = 'fields',
> = ThrowOnError extends true > = ThrowOnError extends true
? Promise< ? Promise<
TResponseStyle extends "data" TResponseStyle extends 'data'
? TData extends Record<string, unknown> ? TData extends Record<string, unknown>
? TData[keyof TData] ? TData[keyof TData]
: TData : TData
: { : {
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData; data: TData extends Record<string, unknown>
? TData[keyof TData]
: TData;
request: Request; request: Request;
response: Response; response: Response;
} }
> >
: Promise< : Promise<
TResponseStyle extends "data" TResponseStyle extends 'data'
? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined ?
| (TData extends Record<string, unknown>
? TData[keyof TData]
: TData)
| undefined
: ( : (
| { | {
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData; data: TData extends Record<string, unknown>
? TData[keyof TData]
: TData;
error: undefined; error: undefined;
} }
| { | {
data: undefined; data: undefined;
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError; error: TError extends Record<string, unknown>
? TError[keyof TError]
: TError;
} }
) & { ) & {
request: Request; request: Request;
@@ -132,28 +159,31 @@ type MethodFn = <
TData = unknown, TData = unknown,
TError = unknown, TError = unknown,
ThrowOnError extends boolean = false, ThrowOnError extends boolean = false,
TResponseStyle extends ResponseStyle = "fields", TResponseStyle extends ResponseStyle = 'fields',
>( >(
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">, options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>; ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
type SseFn = < type SseFn = <
TData = unknown, TData = unknown,
TError = unknown, TError = unknown,
ThrowOnError extends boolean = false, ThrowOnError extends boolean = false,
TResponseStyle extends ResponseStyle = "fields", TResponseStyle extends ResponseStyle = 'fields',
>( >(
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">, options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
) => Promise<ServerSentEventsResult<TData, TError>>; ) => Promise<ServerSentEventsResult<TData, TError>>;
type RequestFn = < type RequestFn = <
TData = unknown, TData = unknown,
TError = unknown, TError = unknown,
ThrowOnError extends boolean = false, ThrowOnError extends boolean = false,
TResponseStyle extends ResponseStyle = "fields", TResponseStyle extends ResponseStyle = 'fields',
>( >(
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> & options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> &
Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, "method">, Pick<
Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>,
'method'
>,
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>; ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
type BuildUrlFn = < type BuildUrlFn = <
@@ -167,7 +197,13 @@ type BuildUrlFn = <
options: TData & Options<TData>, options: TData & Options<TData>,
) => string; ) => string;
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & { export type Client = CoreClient<
RequestFn,
Config,
MethodFn,
BuildUrlFn,
SseFn
> & {
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>; interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
}; };
@@ -197,6 +233,9 @@ export type Options<
TData extends TDataShape = TDataShape, TData extends TDataShape = TDataShape,
ThrowOnError extends boolean = boolean, ThrowOnError extends boolean = boolean,
TResponse = unknown, TResponse = unknown,
TResponseStyle extends ResponseStyle = "fields", TResponseStyle extends ResponseStyle = 'fields',
> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, "body" | "path" | "query" | "url"> & > = OmitKeys<
([TData] extends [never] ? unknown : Omit<TData, "url">); RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
'body' | 'path' | 'query' | 'url'
> &
([TData] extends [never] ? unknown : Omit<TData, 'url'>);

View File

@@ -1,16 +1,23 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
import { getAuthToken } from "../core/auth.gen"; import { getAuthToken } from '../core/auth.gen';
import type { QuerySerializerOptions } from "../core/bodySerializer.gen"; import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
import { jsonBodySerializer } from "../core/bodySerializer.gen"; import { jsonBodySerializer } from '../core/bodySerializer.gen';
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer.gen"; import {
import { getUrl } from "../core/utils.gen"; serializeArrayParam,
import type { Client, ClientOptions, Config, RequestOptions } from "./types.gen"; serializeObjectParam,
serializePrimitiveParam,
} from '../core/pathSerializer.gen';
import { getUrl } from '../core/utils.gen';
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
export const createQuerySerializer = <T = unknown>({ parameters = {}, ...args }: QuerySerializerOptions = {}) => { export const createQuerySerializer = <T = unknown>({
parameters = {},
...args
}: QuerySerializerOptions = {}) => {
const querySerializer = (queryParams: T) => { const querySerializer = (queryParams: T) => {
const search: string[] = []; const search: string[] = [];
if (queryParams && typeof queryParams === "object") { if (queryParams && typeof queryParams === 'object') {
for (const name in queryParams) { for (const name in queryParams) {
const value = queryParams[name]; const value = queryParams[name];
@@ -25,17 +32,17 @@ export const createQuerySerializer = <T = unknown>({ parameters = {}, ...args }:
allowReserved: options.allowReserved, allowReserved: options.allowReserved,
explode: true, explode: true,
name, name,
style: "form", style: 'form',
value, value,
...options.array, ...options.array,
}); });
if (serializedArray) search.push(serializedArray); if (serializedArray) search.push(serializedArray);
} else if (typeof value === "object") { } else if (typeof value === 'object') {
const serializedObject = serializeObjectParam({ const serializedObject = serializeObjectParam({
allowReserved: options.allowReserved, allowReserved: options.allowReserved,
explode: true, explode: true,
name, name,
style: "deepObject", style: 'deepObject',
value: value as Record<string, unknown>, value: value as Record<string, unknown>,
...options.object, ...options.object,
}); });
@@ -50,7 +57,7 @@ export const createQuerySerializer = <T = unknown>({ parameters = {}, ...args }:
} }
} }
} }
return search.join("&"); return search.join('&');
}; };
return querySerializer; return querySerializer;
}; };
@@ -58,40 +65,49 @@ export const createQuerySerializer = <T = unknown>({ parameters = {}, ...args }:
/** /**
* Infers parseAs value from provided Content-Type header. * Infers parseAs value from provided Content-Type header.
*/ */
export const getParseAs = (contentType: string | null): Exclude<Config["parseAs"], "auto"> => { export const getParseAs = (
contentType: string | null,
): Exclude<Config['parseAs'], 'auto'> => {
if (!contentType) { if (!contentType) {
// If no Content-Type header is provided, the best we can do is return the raw response body, // If no Content-Type header is provided, the best we can do is return the raw response body,
// which is effectively the same as the 'stream' option. // which is effectively the same as the 'stream' option.
return "stream"; return 'stream';
} }
const cleanContent = contentType.split(";")[0]?.trim(); const cleanContent = contentType.split(';')[0]?.trim();
if (!cleanContent) { if (!cleanContent) {
return; return;
} }
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) { if (
return "json"; cleanContent.startsWith('application/json') ||
cleanContent.endsWith('+json')
) {
return 'json';
} }
if (cleanContent === "multipart/form-data") { if (cleanContent === 'multipart/form-data') {
return "formData"; return 'formData';
} }
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) { if (
return "blob"; ['application/', 'audio/', 'image/', 'video/'].some((type) =>
cleanContent.startsWith(type),
)
) {
return 'blob';
} }
if (cleanContent.startsWith("text/")) { if (cleanContent.startsWith('text/')) {
return "text"; return 'text';
} }
return; return;
}; };
const checkForExistence = ( const checkForExistence = (
options: Pick<RequestOptions, "auth" | "query"> & { options: Pick<RequestOptions, 'auth' | 'query'> & {
headers: Headers; headers: Headers;
}, },
name?: string, name?: string,
@@ -99,7 +115,11 @@ const checkForExistence = (
if (!name) { if (!name) {
return false; return false;
} }
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) { if (
options.headers.has(name) ||
options.query?.[name] ||
options.headers.get('Cookie')?.includes(`${name}=`)
) {
return true; return true;
} }
return false; return false;
@@ -108,8 +128,8 @@ const checkForExistence = (
export const setAuthParams = async ({ export const setAuthParams = async ({
security, security,
...options ...options
}: Pick<Required<RequestOptions>, "security"> & }: Pick<Required<RequestOptions>, 'security'> &
Pick<RequestOptions, "auth" | "query"> & { Pick<RequestOptions, 'auth' | 'query'> & {
headers: Headers; headers: Headers;
}) => { }) => {
for (const auth of security) { for (const auth of security) {
@@ -123,19 +143,19 @@ export const setAuthParams = async ({
continue; continue;
} }
const name = auth.name ?? "Authorization"; const name = auth.name ?? 'Authorization';
switch (auth.in) { switch (auth.in) {
case "query": case 'query':
if (!options.query) { if (!options.query) {
options.query = {}; options.query = {};
} }
options.query[name] = token; options.query[name] = token;
break; break;
case "cookie": case 'cookie':
options.headers.append("Cookie", `${name}=${token}`); options.headers.append('Cookie', `${name}=${token}`);
break; break;
case "header": case 'header':
default: default:
options.headers.set(name, token); options.headers.set(name, token);
break; break;
@@ -143,13 +163,13 @@ export const setAuthParams = async ({
} }
}; };
export const buildUrl: Client["buildUrl"] = (options) => export const buildUrl: Client['buildUrl'] = (options) =>
getUrl({ getUrl({
baseUrl: options.baseUrl as string, baseUrl: options.baseUrl as string,
path: options.path, path: options.path,
query: options.query, query: options.query,
querySerializer: querySerializer:
typeof options.querySerializer === "function" typeof options.querySerializer === 'function'
? options.querySerializer ? options.querySerializer
: createQuerySerializer(options.querySerializer), : createQuerySerializer(options.querySerializer),
url: options.url, url: options.url,
@@ -157,7 +177,7 @@ export const buildUrl: Client["buildUrl"] = (options) =>
export const mergeConfigs = (a: Config, b: Config): Config => { export const mergeConfigs = (a: Config, b: Config): Config => {
const config = { ...a, ...b }; const config = { ...a, ...b };
if (config.baseUrl?.endsWith("/")) { if (config.baseUrl?.endsWith('/')) {
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
} }
config.headers = mergeHeaders(a.headers, b.headers); config.headers = mergeHeaders(a.headers, b.headers);
@@ -172,14 +192,19 @@ const headersEntries = (headers: Headers): Array<[string, string]> => {
return entries; return entries;
}; };
export const mergeHeaders = (...headers: Array<Required<Config>["headers"] | undefined>): Headers => { export const mergeHeaders = (
...headers: Array<Required<Config>['headers'] | undefined>
): Headers => {
const mergedHeaders = new Headers(); const mergedHeaders = new Headers();
for (const header of headers) { for (const header of headers) {
if (!header) { if (!header) {
continue; continue;
} }
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header); const iterator =
header instanceof Headers
? headersEntries(header)
: Object.entries(header);
for (const [key, value] of iterator) { for (const [key, value] of iterator) {
if (value === null) { if (value === null) {
@@ -191,7 +216,10 @@ export const mergeHeaders = (...headers: Array<Required<Config>["headers"] | und
} else if (value !== undefined) { } else if (value !== undefined) {
// assume object headers are meant to be JSON stringified, i.e. their // assume object headers are meant to be JSON stringified, i.e. their
// content value in OpenAPI specification is 'application/json' // content value in OpenAPI specification is 'application/json'
mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : (value as string)); mergedHeaders.set(
key,
typeof value === 'object' ? JSON.stringify(value) : (value as string),
);
} }
} }
} }
@@ -205,9 +233,16 @@ type ErrInterceptor<Err, Res, Req, Options> = (
options: Options, options: Options,
) => Err | Promise<Err>; ) => Err | Promise<Err>;
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>; type ReqInterceptor<Req, Options> = (
request: Req,
options: Options,
) => Req | Promise<Req>;
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>; type ResInterceptor<Res, Req, Options> = (
response: Res,
request: Req,
options: Options,
) => Res | Promise<Res>;
class Interceptors<Interceptor> { class Interceptors<Interceptor> {
fns: Array<Interceptor | null> = []; fns: Array<Interceptor | null> = [];
@@ -229,13 +264,16 @@ class Interceptors<Interceptor> {
} }
getInterceptorIndex(id: number | Interceptor): number { getInterceptorIndex(id: number | Interceptor): number {
if (typeof id === "number") { if (typeof id === 'number') {
return this.fns[id] ? id : -1; return this.fns[id] ? id : -1;
} }
return this.fns.indexOf(id); return this.fns.indexOf(id);
} }
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false { update(
id: number | Interceptor,
fn: Interceptor,
): number | Interceptor | false {
const index = this.getInterceptorIndex(id); const index = this.getInterceptorIndex(id);
if (this.fns[index]) { if (this.fns[index]) {
this.fns[index] = fn; this.fns[index] = fn;
@@ -256,7 +294,12 @@ export interface Middleware<Req, Res, Err, Options> {
response: Interceptors<ResInterceptor<Res, Req, Options>>; response: Interceptors<ResInterceptor<Res, Req, Options>>;
} }
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<Req, Res, Err, Options> => ({ export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
Req,
Res,
Err,
Options
> => ({
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(), error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
request: new Interceptors<ReqInterceptor<Req, Options>>(), request: new Interceptors<ReqInterceptor<Req, Options>>(),
response: new Interceptors<ResInterceptor<Res, Req, Options>>(), response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
@@ -266,16 +309,16 @@ const defaultQuerySerializer = createQuerySerializer({
allowReserved: false, allowReserved: false,
array: { array: {
explode: true, explode: true,
style: "form", style: 'form',
}, },
object: { object: {
explode: true, explode: true,
style: "deepObject", style: 'deepObject',
}, },
}); });
const defaultHeaders = { const defaultHeaders = {
"Content-Type": "application/json", 'Content-Type': 'application/json',
}; };
export const createConfig = <T extends ClientOptions = ClientOptions>( export const createConfig = <T extends ClientOptions = ClientOptions>(
@@ -283,7 +326,7 @@ export const createConfig = <T extends ClientOptions = ClientOptions>(
): Config<Omit<ClientOptions, keyof T> & T> => ({ ): Config<Omit<ClientOptions, keyof T> & T> => ({
...jsonBodySerializer, ...jsonBodySerializer,
headers: defaultHeaders, headers: defaultHeaders,
parseAs: "auto", parseAs: 'auto',
querySerializer: defaultQuerySerializer, querySerializer: defaultQuerySerializer,
...override, ...override,
}); });

View File

@@ -8,32 +8,33 @@ export interface Auth {
* *
* @default 'header' * @default 'header'
*/ */
in?: "header" | "query" | "cookie"; in?: 'header' | 'query' | 'cookie';
/** /**
* Header or query parameter name. * Header or query parameter name.
* *
* @default 'Authorization' * @default 'Authorization'
*/ */
name?: string; name?: string;
scheme?: "basic" | "bearer"; scheme?: 'basic' | 'bearer';
type: "apiKey" | "http"; type: 'apiKey' | 'http';
} }
export const getAuthToken = async ( export const getAuthToken = async (
auth: Auth, auth: Auth,
callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken, callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
): Promise<string | undefined> => { ): Promise<string | undefined> => {
const token = typeof callback === "function" ? await callback(auth) : callback; const token =
typeof callback === 'function' ? await callback(auth) : callback;
if (!token) { if (!token) {
return; return;
} }
if (auth.scheme === "bearer") { if (auth.scheme === 'bearer') {
return `Bearer ${token}`; return `Bearer ${token}`;
} }
if (auth.scheme === "basic") { if (auth.scheme === 'basic') {
return `Basic ${btoa(token)}`; return `Basic ${btoa(token)}`;
} }

View File

@@ -1,6 +1,10 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer.gen"; import type {
ArrayStyle,
ObjectStyle,
SerializerOptions,
} from './pathSerializer.gen';
export type QuerySerializer = (query: Record<string, unknown>) => string; export type QuerySerializer = (query: Record<string, unknown>) => string;
@@ -20,8 +24,12 @@ export type QuerySerializerOptions = QuerySerializerOptionsObject & {
parameters?: Record<string, QuerySerializerOptionsObject>; parameters?: Record<string, QuerySerializerOptionsObject>;
}; };
const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => { const serializeFormDataPair = (
if (typeof value === "string" || value instanceof Blob) { data: FormData,
key: string,
value: unknown,
): void => {
if (typeof value === 'string' || value instanceof Blob) {
data.append(key, value); data.append(key, value);
} else if (value instanceof Date) { } else if (value instanceof Date) {
data.append(key, value.toISOString()); data.append(key, value.toISOString());
@@ -30,8 +38,12 @@ const serializeFormDataPair = (data: FormData, key: string, value: unknown): voi
} }
}; };
const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => { const serializeUrlSearchParamsPair = (
if (typeof value === "string") { data: URLSearchParams,
key: string,
value: unknown,
): void => {
if (typeof value === 'string') {
data.append(key, value); data.append(key, value);
} else { } else {
data.append(key, JSON.stringify(value)); data.append(key, JSON.stringify(value));
@@ -39,7 +51,9 @@ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value:
}; };
export const formDataBodySerializer = { export const formDataBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): FormData => { bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
body: T,
): FormData => {
const data = new FormData(); const data = new FormData();
Object.entries(body).forEach(([key, value]) => { Object.entries(body).forEach(([key, value]) => {
@@ -59,11 +73,15 @@ export const formDataBodySerializer = {
export const jsonBodySerializer = { export const jsonBodySerializer = {
bodySerializer: <T>(body: T): string => bodySerializer: <T>(body: T): string =>
JSON.stringify(body, (_key, value) => (typeof value === "bigint" ? value.toString() : value)), JSON.stringify(body, (_key, value) =>
typeof value === 'bigint' ? value.toString() : value,
),
}; };
export const urlSearchParamsBodySerializer = { export const urlSearchParamsBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => { bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
body: T,
): string => {
const data = new URLSearchParams(); const data = new URLSearchParams();
Object.entries(body).forEach(([key, value]) => { Object.entries(body).forEach(([key, value]) => {

View File

@@ -1,10 +1,10 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
type Slot = "body" | "headers" | "path" | "query"; type Slot = 'body' | 'headers' | 'path' | 'query';
export type Field = export type Field =
| { | {
in: Exclude<Slot, "body">; in: Exclude<Slot, 'body'>;
/** /**
* Field name. This is the name we want the user to see and use. * Field name. This is the name we want the user to see and use.
*/ */
@@ -16,7 +16,7 @@ export type Field =
map?: string; map?: string;
} }
| { | {
in: Extract<Slot, "body">; in: Extract<Slot, 'body'>;
/** /**
* Key isn't required for bodies. * Key isn't required for bodies.
*/ */
@@ -43,10 +43,10 @@ export interface Fields {
export type FieldsConfig = ReadonlyArray<Field | Fields>; export type FieldsConfig = ReadonlyArray<Field | Fields>;
const extraPrefixesMap: Record<string, Slot> = { const extraPrefixesMap: Record<string, Slot> = {
$body_: "body", $body_: 'body',
$headers_: "headers", $headers_: 'headers',
$path_: "path", $path_: 'path',
$query_: "query", $query_: 'query',
}; };
const extraPrefixes = Object.entries(extraPrefixesMap); const extraPrefixes = Object.entries(extraPrefixesMap);
@@ -68,14 +68,14 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
} }
for (const config of fields) { for (const config of fields) {
if ("in" in config) { if ('in' in config) {
if (config.key) { if (config.key) {
map.set(config.key, { map.set(config.key, {
in: config.in, in: config.in,
map: config.map, map: config.map,
}); });
} }
} else if ("key" in config) { } else if ('key' in config) {
map.set(config.key, { map.set(config.key, {
map: config.map, map: config.map,
}); });
@@ -96,13 +96,16 @@ interface Params {
const stripEmptySlots = (params: Params) => { const stripEmptySlots = (params: Params) => {
for (const [slot, value] of Object.entries(params)) { for (const [slot, value] of Object.entries(params)) {
if (value && typeof value === "object" && !Object.keys(value).length) { if (value && typeof value === 'object' && !Object.keys(value).length) {
delete params[slot as Slot]; delete params[slot as Slot];
} }
} }
}; };
export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsConfig) => { export const buildClientParams = (
args: ReadonlyArray<unknown>,
fields: FieldsConfig,
) => {
const params: Params = { const params: Params = {
body: {}, body: {},
headers: {}, headers: {},
@@ -123,7 +126,7 @@ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsCo
continue; continue;
} }
if ("in" in config) { if ('in' in config) {
if (config.key) { if (config.key) {
const field = map.get(config.key)!; const field = map.get(config.key)!;
const name = field.map || config.key; const name = field.map || config.key;
@@ -145,12 +148,16 @@ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsCo
params[field.map] = value; params[field.map] = value;
} }
} else { } else {
const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix)); const extra = extraPrefixes.find(([prefix]) =>
key.startsWith(prefix),
);
if (extra) { if (extra) {
const [prefix, slot] = extra; const [prefix, slot] = extra;
(params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value; (params[slot] as Record<string, unknown>)[
} else if ("allowExtra" in config && config.allowExtra) { key.slice(prefix.length)
] = value;
} else if ('allowExtra' in config && config.allowExtra) {
for (const [slot, allowed] of Object.entries(config.allowExtra)) { for (const [slot, allowed] of Object.entries(config.allowExtra)) {
if (allowed) { if (allowed) {
(params[slot as Slot] as Record<string, unknown>)[key] = value; (params[slot as Slot] as Record<string, unknown>)[key] = value;

View File

@@ -1,6 +1,8 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
interface SerializeOptions<T> extends SerializePrimitiveOptions, SerializerOptions<T> {} interface SerializeOptions<T>
extends SerializePrimitiveOptions,
SerializerOptions<T> {}
interface SerializePrimitiveOptions { interface SerializePrimitiveOptions {
allowReserved?: boolean; allowReserved?: boolean;
@@ -15,10 +17,10 @@ export interface SerializerOptions<T> {
style: T; style: T;
} }
export type ArrayStyle = "form" | "spaceDelimited" | "pipeDelimited"; export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; export type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
type MatrixStyle = "label" | "matrix" | "simple"; type MatrixStyle = 'label' | 'matrix' | 'simple';
export type ObjectStyle = "form" | "deepObject"; export type ObjectStyle = 'form' | 'deepObject';
type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; type ObjectSeparatorStyle = ObjectStyle | MatrixStyle;
interface SerializePrimitiveParam extends SerializePrimitiveOptions { interface SerializePrimitiveParam extends SerializePrimitiveOptions {
@@ -27,40 +29,40 @@ interface SerializePrimitiveParam extends SerializePrimitiveOptions {
export const separatorArrayExplode = (style: ArraySeparatorStyle) => { export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
switch (style) { switch (style) {
case "label": case 'label':
return "."; return '.';
case "matrix": case 'matrix':
return ";"; return ';';
case "simple": case 'simple':
return ","; return ',';
default: default:
return "&"; return '&';
} }
}; };
export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
switch (style) { switch (style) {
case "form": case 'form':
return ","; return ',';
case "pipeDelimited": case 'pipeDelimited':
return "|"; return '|';
case "spaceDelimited": case 'spaceDelimited':
return "%20"; return '%20';
default: default:
return ","; return ',';
} }
}; };
export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { export const separatorObjectExplode = (style: ObjectSeparatorStyle) => {
switch (style) { switch (style) {
case "label": case 'label':
return "."; return '.';
case "matrix": case 'matrix':
return ";"; return ';';
case "simple": case 'simple':
return ","; return ',';
default: default:
return "&"; return '&';
} }
}; };
@@ -74,15 +76,15 @@ export const serializeArrayParam = ({
value: unknown[]; value: unknown[];
}) => { }) => {
if (!explode) { if (!explode) {
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v as string))).join( const joinedValues = (
separatorArrayNoExplode(style), allowReserved ? value : value.map((v) => encodeURIComponent(v as string))
); ).join(separatorArrayNoExplode(style));
switch (style) { switch (style) {
case "label": case 'label':
return `.${joinedValues}`; return `.${joinedValues}`;
case "matrix": case 'matrix':
return `;${name}=${joinedValues}`; return `;${name}=${joinedValues}`;
case "simple": case 'simple':
return joinedValues; return joinedValues;
default: default:
return `${name}=${joinedValues}`; return `${name}=${joinedValues}`;
@@ -92,7 +94,7 @@ export const serializeArrayParam = ({
const separator = separatorArrayExplode(style); const separator = separatorArrayExplode(style);
const joinedValues = value const joinedValues = value
.map((v) => { .map((v) => {
if (style === "label" || style === "simple") { if (style === 'label' || style === 'simple') {
return allowReserved ? v : encodeURIComponent(v as string); return allowReserved ? v : encodeURIComponent(v as string);
} }
@@ -103,17 +105,23 @@ export const serializeArrayParam = ({
}); });
}) })
.join(separator); .join(separator);
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues; return style === 'label' || style === 'matrix'
? separator + joinedValues
: joinedValues;
}; };
export const serializePrimitiveParam = ({ allowReserved, name, value }: SerializePrimitiveParam) => { export const serializePrimitiveParam = ({
allowReserved,
name,
value,
}: SerializePrimitiveParam) => {
if (value === undefined || value === null) { if (value === undefined || value === null) {
return ""; return '';
} }
if (typeof value === "object") { if (typeof value === 'object') {
throw new Error( throw new Error(
"Deeply-nested arrays/objects arent supported. Provide your own `querySerializer()` to handle these.", 'Deeply-nested arrays/objects arent supported. Provide your own `querySerializer()` to handle these.',
); );
} }
@@ -135,18 +143,22 @@ export const serializeObjectParam = ({
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
} }
if (style !== "deepObject" && !explode) { if (style !== 'deepObject' && !explode) {
let values: string[] = []; let values: string[] = [];
Object.entries(value).forEach(([key, v]) => { Object.entries(value).forEach(([key, v]) => {
values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)]; values = [
...values,
key,
allowReserved ? (v as string) : encodeURIComponent(v as string),
];
}); });
const joinedValues = values.join(","); const joinedValues = values.join(',');
switch (style) { switch (style) {
case "form": case 'form':
return `${name}=${joinedValues}`; return `${name}=${joinedValues}`;
case "label": case 'label':
return `.${joinedValues}`; return `.${joinedValues}`;
case "matrix": case 'matrix':
return `;${name}=${joinedValues}`; return `;${name}=${joinedValues}`;
default: default:
return joinedValues; return joinedValues;
@@ -158,10 +170,12 @@ export const serializeObjectParam = ({
.map(([key, v]) => .map(([key, v]) =>
serializePrimitiveParam({ serializePrimitiveParam({
allowReserved, allowReserved,
name: style === "deepObject" ? `${name}[${key}]` : key, name: style === 'deepObject' ? `${name}[${key}]` : key,
value: v as string, value: v as string,
}), }),
) )
.join(separator); .join(separator);
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues; return style === 'label' || style === 'matrix'
? separator + joinedValues
: joinedValues;
}; };

View File

@@ -3,16 +3,26 @@
/** /**
* JSON-friendly union that mirrors what Pinia Colada can hash. * JSON-friendly union that mirrors what Pinia Colada can hash.
*/ */
export type JsonValue = null | string | number | boolean | JsonValue[] | { [key: string]: JsonValue }; export type JsonValue =
| null
| string
| number
| boolean
| JsonValue[]
| { [key: string]: JsonValue };
/** /**
* Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
*/ */
export const queryKeyJsonReplacer = (_key: string, value: unknown) => { export const queryKeyJsonReplacer = (_key: string, value: unknown) => {
if (value === undefined || typeof value === "function" || typeof value === "symbol") { if (
value === undefined ||
typeof value === 'function' ||
typeof value === 'symbol'
) {
return undefined; return undefined;
} }
if (typeof value === "bigint") { if (typeof value === 'bigint') {
return value.toString(); return value.toString();
} }
if (value instanceof Date) { if (value instanceof Date) {
@@ -40,7 +50,7 @@ export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => {
* Detects plain objects (including objects with a null prototype). * Detects plain objects (including objects with a null prototype).
*/ */
const isPlainObject = (value: unknown): value is Record<string, unknown> => { const isPlainObject = (value: unknown): value is Record<string, unknown> => {
if (value === null || typeof value !== "object") { if (value === null || typeof value !== 'object') {
return false; return false;
} }
const prototype = Object.getPrototypeOf(value as object); const prototype = Object.getPrototypeOf(value as object);
@@ -51,7 +61,9 @@ const isPlainObject = (value: unknown): value is Record<string, unknown> => {
* Turns URLSearchParams into a sorted JSON object for deterministic keys. * Turns URLSearchParams into a sorted JSON object for deterministic keys.
*/ */
const serializeSearchParams = (params: URLSearchParams): JsonValue => { const serializeSearchParams = (params: URLSearchParams): JsonValue => {
const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b)); const entries = Array.from(params.entries()).sort(([a], [b]) =>
a.localeCompare(b),
);
const result: Record<string, JsonValue> = {}; const result: Record<string, JsonValue> = {};
for (const [key, value] of entries) { for (const [key, value] of entries) {
@@ -74,20 +86,30 @@ const serializeSearchParams = (params: URLSearchParams): JsonValue => {
/** /**
* Normalizes any accepted value into a JSON-friendly shape for query keys. * Normalizes any accepted value into a JSON-friendly shape for query keys.
*/ */
export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined => { export const serializeQueryKeyValue = (
value: unknown,
): JsonValue | undefined => {
if (value === null) { if (value === null) {
return null; return null;
} }
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") { if (
typeof value === 'string' ||
typeof value === 'number' ||
typeof value === 'boolean'
) {
return value; return value;
} }
if (value === undefined || typeof value === "function" || typeof value === "symbol") { if (
value === undefined ||
typeof value === 'function' ||
typeof value === 'symbol'
) {
return undefined; return undefined;
} }
if (typeof value === "bigint") { if (typeof value === 'bigint') {
return value.toString(); return value.toString();
} }
@@ -99,7 +121,10 @@ export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined =>
return stringifyToJsonValue(value); return stringifyToJsonValue(value);
} }
if (typeof URLSearchParams !== "undefined" && value instanceof URLSearchParams) { if (
typeof URLSearchParams !== 'undefined' &&
value instanceof URLSearchParams
) {
return serializeSearchParams(value); return serializeSearchParams(value);
} }

View File

@@ -1,9 +1,12 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
import type { Config } from "./types.gen"; import type { Config } from './types.gen';
export type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, "method"> & export type ServerSentEventsOptions<TData = unknown> = Omit<
Pick<Config, "method" | "responseTransformer" | "responseValidator"> & { RequestInit,
'method'
> &
Pick<Config, 'method' | 'responseTransformer' | 'responseValidator'> & {
/** /**
* Fetch API implementation. You can use this option to provide a custom * Fetch API implementation. You can use this option to provide a custom
* fetch instance. * fetch instance.
@@ -32,7 +35,7 @@ export type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, "method
* @returns Nothing (void). * @returns Nothing (void).
*/ */
onSseEvent?: (event: StreamEvent<TData>) => void; onSseEvent?: (event: StreamEvent<TData>) => void;
serializedBody?: RequestInit["body"]; serializedBody?: RequestInit['body'];
/** /**
* Default retry delay in milliseconds. * Default retry delay in milliseconds.
* *
@@ -71,8 +74,16 @@ export interface StreamEvent<TData = unknown> {
retry?: number; retry?: number;
} }
export type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = { export type ServerSentEventsResult<
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>; TData = unknown,
TReturn = void,
TNext = unknown,
> = {
stream: AsyncGenerator<
TData extends Record<string, unknown> ? TData[keyof TData] : TData,
TReturn,
TNext
>;
}; };
export const createSseClient = <TData = unknown>({ export const createSseClient = <TData = unknown>({
@@ -90,7 +101,9 @@ export const createSseClient = <TData = unknown>({
}: ServerSentEventsOptions): ServerSentEventsResult<TData> => { }: ServerSentEventsOptions): ServerSentEventsResult<TData> => {
let lastEventId: string | undefined; let lastEventId: string | undefined;
const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); const sleep =
sseSleepFn ??
((ms: number) => new Promise((resolve) => setTimeout(resolve, ms)));
const createStream = async function* () { const createStream = async function* () {
let retryDelay: number = sseDefaultRetryDelay ?? 3000; let retryDelay: number = sseDefaultRetryDelay ?? 3000;
@@ -108,12 +121,12 @@ export const createSseClient = <TData = unknown>({
: new Headers(options.headers as Record<string, string> | undefined); : new Headers(options.headers as Record<string, string> | undefined);
if (lastEventId !== undefined) { if (lastEventId !== undefined) {
headers.set("Last-Event-ID", lastEventId); headers.set('Last-Event-ID', lastEventId);
} }
try { try {
const requestInit: RequestInit = { const requestInit: RequestInit = {
redirect: "follow", redirect: 'follow',
...options, ...options,
body: options.serializedBody, body: options.serializedBody,
headers, headers,
@@ -128,13 +141,18 @@ export const createSseClient = <TData = unknown>({
const _fetch = options.fetch ?? globalThis.fetch; const _fetch = options.fetch ?? globalThis.fetch;
const response = await _fetch(request); const response = await _fetch(request);
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`); if (!response.ok)
throw new Error(
`SSE failed: ${response.status} ${response.statusText}`,
);
if (!response.body) throw new Error("No body in SSE response"); if (!response.body) throw new Error('No body in SSE response');
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); const reader = response.body
.pipeThrough(new TextDecoderStream())
.getReader();
let buffer = ""; let buffer = '';
const abortHandler = () => { const abortHandler = () => {
try { try {
@@ -144,7 +162,7 @@ export const createSseClient = <TData = unknown>({
} }
}; };
signal.addEventListener("abort", abortHandler); signal.addEventListener('abort', abortHandler);
try { try {
while (true) { while (true) {
@@ -152,23 +170,26 @@ export const createSseClient = <TData = unknown>({
if (done) break; if (done) break;
buffer += value; buffer += value;
const chunks = buffer.split("\n\n"); const chunks = buffer.split('\n\n');
buffer = chunks.pop() ?? ""; buffer = chunks.pop() ?? '';
for (const chunk of chunks) { for (const chunk of chunks) {
const lines = chunk.split("\n"); const lines = chunk.split('\n');
const dataLines: Array<string> = []; const dataLines: Array<string> = [];
let eventName: string | undefined; let eventName: string | undefined;
for (const line of lines) { for (const line of lines) {
if (line.startsWith("data:")) { if (line.startsWith('data:')) {
dataLines.push(line.replace(/^data:\s*/, "")); dataLines.push(line.replace(/^data:\s*/, ''));
} else if (line.startsWith("event:")) { } else if (line.startsWith('event:')) {
eventName = line.replace(/^event:\s*/, ""); eventName = line.replace(/^event:\s*/, '');
} else if (line.startsWith("id:")) { } else if (line.startsWith('id:')) {
lastEventId = line.replace(/^id:\s*/, ""); lastEventId = line.replace(/^id:\s*/, '');
} else if (line.startsWith("retry:")) { } else if (line.startsWith('retry:')) {
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10); const parsed = Number.parseInt(
line.replace(/^retry:\s*/, ''),
10,
);
if (!Number.isNaN(parsed)) { if (!Number.isNaN(parsed)) {
retryDelay = parsed; retryDelay = parsed;
} }
@@ -179,7 +200,7 @@ export const createSseClient = <TData = unknown>({
let parsedJson = false; let parsedJson = false;
if (dataLines.length) { if (dataLines.length) {
const rawData = dataLines.join("\n"); const rawData = dataLines.join('\n');
try { try {
data = JSON.parse(rawData); data = JSON.parse(rawData);
parsedJson = true; parsedJson = true;
@@ -211,7 +232,7 @@ export const createSseClient = <TData = unknown>({
} }
} }
} finally { } finally {
signal.removeEventListener("abort", abortHandler); signal.removeEventListener('abort', abortHandler);
reader.releaseLock(); reader.releaseLock();
} }
@@ -220,12 +241,18 @@ export const createSseClient = <TData = unknown>({
// connection failed or aborted; retry after delay // connection failed or aborted; retry after delay
onSseError?.(error); onSseError?.(error);
if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) { if (
sseMaxRetryAttempts !== undefined &&
attempt >= sseMaxRetryAttempts
) {
break; // stop after firing error break; // stop after firing error
} }
// exponential backoff: double retry each attempt, cap at 30s // exponential backoff: double retry each attempt, cap at 30s
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000); const backoff = Math.min(
retryDelay * 2 ** (attempt - 1),
sseMaxRetryDelay ?? 30000,
);
await sleep(backoff); await sleep(backoff);
} }
} }

View File

@@ -1,11 +1,30 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
import type { Auth, AuthToken } from "./auth.gen"; import type { Auth, AuthToken } from './auth.gen';
import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from "./bodySerializer.gen"; import type {
BodySerializer,
QuerySerializer,
QuerySerializerOptions,
} from './bodySerializer.gen';
export type HttpMethod = "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace"; export type HttpMethod =
| 'connect'
| 'delete'
| 'get'
| 'head'
| 'options'
| 'patch'
| 'post'
| 'put'
| 'trace';
export type Client<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = { export type Client<
RequestFn = never,
Config = unknown,
MethodFn = never,
BuildUrlFn = never,
SseFn = never,
> = {
/** /**
* Returns the final request URL. * Returns the final request URL.
*/ */
@@ -15,7 +34,9 @@ export type Client<RequestFn = never, Config = unknown, MethodFn = never, BuildU
setConfig: (config: Config) => Config; setConfig: (config: Config) => Config;
} & { } & {
[K in HttpMethod]: MethodFn; [K in HttpMethod]: MethodFn;
} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } }); } & ([SseFn] extends [never]
? { sse?: never }
: { sse: { [K in HttpMethod]: SseFn } });
export interface Config { export interface Config {
/** /**
@@ -35,8 +56,17 @@ export interface Config {
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
*/ */
headers?: headers?:
| RequestInit["headers"] | RequestInit['headers']
| Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>; | Record<
string,
| string
| number
| boolean
| (string | number | boolean)[]
| null
| undefined
| unknown
>;
/** /**
* The request method. * The request method.
* *
@@ -82,5 +112,7 @@ type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never]
: false; : false;
export type OmitNever<T extends Record<string, unknown>> = { export type OmitNever<T extends Record<string, unknown>> = {
[K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true ? never : K]: T[K]; [K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true
? never
: K]: T[K];
}; };

View File

@@ -1,12 +1,12 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
import type { BodySerializer, QuerySerializer } from "./bodySerializer.gen"; import type { BodySerializer, QuerySerializer } from './bodySerializer.gen';
import { import {
type ArraySeparatorStyle, type ArraySeparatorStyle,
serializeArrayParam, serializeArrayParam,
serializeObjectParam, serializeObjectParam,
serializePrimitiveParam, serializePrimitiveParam,
} from "./pathSerializer.gen"; } from './pathSerializer.gen';
export interface PathSerializer { export interface PathSerializer {
path: Record<string, unknown>; path: Record<string, unknown>;
@@ -22,19 +22,19 @@ export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
for (const match of matches) { for (const match of matches) {
let explode = false; let explode = false;
let name = match.substring(1, match.length - 1); let name = match.substring(1, match.length - 1);
let style: ArraySeparatorStyle = "simple"; let style: ArraySeparatorStyle = 'simple';
if (name.endsWith("*")) { if (name.endsWith('*')) {
explode = true; explode = true;
name = name.substring(0, name.length - 1); name = name.substring(0, name.length - 1);
} }
if (name.startsWith(".")) { if (name.startsWith('.')) {
name = name.substring(1); name = name.substring(1);
style = "label"; style = 'label';
} else if (name.startsWith(";")) { } else if (name.startsWith(';')) {
name = name.substring(1); name = name.substring(1);
style = "matrix"; style = 'matrix';
} }
const value = path[name]; const value = path[name];
@@ -44,11 +44,14 @@ export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
} }
if (Array.isArray(value)) { if (Array.isArray(value)) {
url = url.replace(match, serializeArrayParam({ explode, name, style, value })); url = url.replace(
match,
serializeArrayParam({ explode, name, style, value }),
);
continue; continue;
} }
if (typeof value === "object") { if (typeof value === 'object') {
url = url.replace( url = url.replace(
match, match,
serializeObjectParam({ serializeObjectParam({
@@ -62,7 +65,7 @@ export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
continue; continue;
} }
if (style === "matrix") { if (style === 'matrix') {
url = url.replace( url = url.replace(
match, match,
`;${serializePrimitiveParam({ `;${serializePrimitiveParam({
@@ -73,7 +76,9 @@ export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
continue; continue;
} }
const replaceValue = encodeURIComponent(style === "label" ? `.${value as string}` : (value as string)); const replaceValue = encodeURIComponent(
style === 'label' ? `.${value as string}` : (value as string),
);
url = url.replace(match, replaceValue); url = url.replace(match, replaceValue);
} }
} }
@@ -93,13 +98,13 @@ export const getUrl = ({
querySerializer: QuerySerializer; querySerializer: QuerySerializer;
url: string; url: string;
}) => { }) => {
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`; const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
let url = (baseUrl ?? "") + pathUrl; let url = (baseUrl ?? '') + pathUrl;
if (path) { if (path) {
url = defaultPathSerializer({ path, url }); url = defaultPathSerializer({ path, url });
} }
let search = query ? querySerializer(query) : ""; let search = query ? querySerializer(query) : '';
if (search.startsWith("?")) { if (search.startsWith('?')) {
search = search.substring(1); search = search.substring(1);
} }
if (search) { if (search) {
@@ -117,14 +122,15 @@ export function getValidRequestBody(options: {
const isSerializedBody = hasBody && options.bodySerializer; const isSerializedBody = hasBody && options.bodySerializer;
if (isSerializedBody) { if (isSerializedBody) {
if ("serializedBody" in options) { if ('serializedBody' in options) {
const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== ""; const hasSerializedBody =
options.serializedBody !== undefined && options.serializedBody !== '';
return hasSerializedBody ? options.serializedBody : null; return hasSerializedBody ? options.serializedBody : null;
} }
// not all clients implement a serializedBody property (i.e. client-axios) // not all clients implement a serializedBody property (i.e. client-axios)
return options.body !== "" ? options.body : null; return options.body !== '' ? options.body : null;
} }
// plain/text body // plain/text body

View File

@@ -1,4 +1,4 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
export type * from "./types.gen"; export type * from './types.gen';
export * from "./sdk.gen"; export * from './sdk.gen';

View File

@@ -1,95 +1,10 @@
// This file is auto-generated by @hey-api/openapi-ts // This file is auto-generated by @hey-api/openapi-ts
import type { Client, Options as Options2, TDataShape } from "./client"; import type { Client, Options as Options2, TDataShape } from './client';
import { client } from "./client.gen"; import { client } from './client.gen';
import type { import type { BrowseFilesystemData, BrowseFilesystemResponses, ChangePasswordData, ChangePasswordResponses, CreateBackupScheduleData, CreateBackupScheduleResponses, CreateRepositoryData, CreateRepositoryResponses, CreateVolumeData, CreateVolumeResponses, DeleteBackupScheduleData, DeleteBackupScheduleResponses, DeleteRepositoryData, DeleteRepositoryResponses, DeleteVolumeData, DeleteVolumeResponses, DoctorRepositoryData, DoctorRepositoryResponses, DownloadResticPasswordData, DownloadResticPasswordResponses, GetBackupScheduleData, GetBackupScheduleForVolumeData, GetBackupScheduleForVolumeResponses, GetBackupScheduleResponses, GetContainersUsingVolumeData, GetContainersUsingVolumeErrors, GetContainersUsingVolumeResponses, GetMeData, GetMeResponses, GetRepositoryData, GetRepositoryResponses, GetSnapshotDetailsData, GetSnapshotDetailsResponses, GetStatusData, GetStatusResponses, GetSystemInfoData, GetSystemInfoResponses, GetVolumeData, GetVolumeErrors, GetVolumeResponses, HealthCheckVolumeData, HealthCheckVolumeErrors, HealthCheckVolumeResponses, ListBackupSchedulesData, ListBackupSchedulesResponses, ListFilesData, ListFilesResponses, ListRcloneRemotesData, ListRcloneRemotesResponses, ListRepositoriesData, ListRepositoriesResponses, ListSnapshotFilesData, ListSnapshotFilesResponses, ListSnapshotsData, ListSnapshotsResponses, ListVolumesData, ListVolumesResponses, LoginData, LoginResponses, LogoutData, LogoutResponses, MountVolumeData, MountVolumeResponses, RegisterData, RegisterResponses, RestoreSnapshotData, RestoreSnapshotResponses, RunBackupNowData, RunBackupNowResponses, RunForgetData, RunForgetResponses, StopBackupData, StopBackupErrors, StopBackupResponses, TestConnectionData, TestConnectionResponses, UnmountVolumeData, UnmountVolumeResponses, UpdateBackupScheduleData, UpdateBackupScheduleResponses, UpdateVolumeData, UpdateVolumeErrors, UpdateVolumeResponses } from './types.gen';
BrowseFilesystemData,
BrowseFilesystemResponses,
ChangePasswordData,
ChangePasswordResponses,
CreateBackupScheduleData,
CreateBackupScheduleResponses,
CreateRepositoryData,
CreateRepositoryResponses,
CreateVolumeData,
CreateVolumeResponses,
DeleteBackupScheduleData,
DeleteBackupScheduleResponses,
DeleteRepositoryData,
DeleteRepositoryResponses,
DeleteVolumeData,
DeleteVolumeResponses,
DoctorRepositoryData,
DoctorRepositoryResponses,
DownloadResticPasswordData,
DownloadResticPasswordResponses,
GetBackupScheduleData,
GetBackupScheduleForVolumeData,
GetBackupScheduleForVolumeResponses,
GetBackupScheduleResponses,
GetContainersUsingVolumeData,
GetContainersUsingVolumeErrors,
GetContainersUsingVolumeResponses,
GetMeData,
GetMeResponses,
GetRepositoryData,
GetRepositoryResponses,
GetSnapshotDetailsData,
GetSnapshotDetailsResponses,
GetStatusData,
GetStatusResponses,
GetSystemInfoData,
GetSystemInfoResponses,
GetVolumeData,
GetVolumeErrors,
GetVolumeResponses,
HealthCheckVolumeData,
HealthCheckVolumeErrors,
HealthCheckVolumeResponses,
ListBackupSchedulesData,
ListBackupSchedulesResponses,
ListFilesData,
ListFilesResponses,
ListRcloneRemotesData,
ListRcloneRemotesResponses,
ListRepositoriesData,
ListRepositoriesResponses,
ListSnapshotFilesData,
ListSnapshotFilesResponses,
ListSnapshotsData,
ListSnapshotsResponses,
ListVolumesData,
ListVolumesResponses,
LoginData,
LoginResponses,
LogoutData,
LogoutResponses,
MountVolumeData,
MountVolumeResponses,
RegisterData,
RegisterResponses,
RestoreSnapshotData,
RestoreSnapshotResponses,
RunBackupNowData,
RunBackupNowResponses,
StopBackupData,
StopBackupErrors,
StopBackupResponses,
TestConnectionData,
TestConnectionResponses,
UnmountVolumeData,
UnmountVolumeResponses,
UpdateBackupScheduleData,
UpdateBackupScheduleResponses,
UpdateVolumeData,
UpdateVolumeErrors,
UpdateVolumeResponses,
} from "./types.gen";
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options2< export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options2<TData, ThrowOnError> & {
TData,
ThrowOnError
> & {
/** /**
* You can provide a client instance returned by `createClient()` instead of * You can provide a client instance returned by `createClient()` instead of
* individual options. This might be also useful if you want to implement a * individual options. This might be also useful if you want to implement a
@@ -108,12 +23,12 @@ export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends
*/ */
export const register = <ThrowOnError extends boolean = false>(options?: Options<RegisterData, ThrowOnError>) => { export const register = <ThrowOnError extends boolean = false>(options?: Options<RegisterData, ThrowOnError>) => {
return (options?.client ?? client).post<RegisterResponses, unknown, ThrowOnError>({ return (options?.client ?? client).post<RegisterResponses, unknown, ThrowOnError>({
url: "/api/v1/auth/register", url: '/api/v1/auth/register',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options?.headers, ...options?.headers
}, }
}); });
}; };
@@ -122,12 +37,12 @@ export const register = <ThrowOnError extends boolean = false>(options?: Options
*/ */
export const login = <ThrowOnError extends boolean = false>(options?: Options<LoginData, ThrowOnError>) => { export const login = <ThrowOnError extends boolean = false>(options?: Options<LoginData, ThrowOnError>) => {
return (options?.client ?? client).post<LoginResponses, unknown, ThrowOnError>({ return (options?.client ?? client).post<LoginResponses, unknown, ThrowOnError>({
url: "/api/v1/auth/login", url: '/api/v1/auth/login',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options?.headers, ...options?.headers
}, }
}); });
}; };
@@ -136,8 +51,8 @@ export const login = <ThrowOnError extends boolean = false>(options?: Options<Lo
*/ */
export const logout = <ThrowOnError extends boolean = false>(options?: Options<LogoutData, ThrowOnError>) => { export const logout = <ThrowOnError extends boolean = false>(options?: Options<LogoutData, ThrowOnError>) => {
return (options?.client ?? client).post<LogoutResponses, unknown, ThrowOnError>({ return (options?.client ?? client).post<LogoutResponses, unknown, ThrowOnError>({
url: "/api/v1/auth/logout", url: '/api/v1/auth/logout',
...options, ...options
}); });
}; };
@@ -146,8 +61,8 @@ export const logout = <ThrowOnError extends boolean = false>(options?: Options<L
*/ */
export const getMe = <ThrowOnError extends boolean = false>(options?: Options<GetMeData, ThrowOnError>) => { export const getMe = <ThrowOnError extends boolean = false>(options?: Options<GetMeData, ThrowOnError>) => {
return (options?.client ?? client).get<GetMeResponses, unknown, ThrowOnError>({ return (options?.client ?? client).get<GetMeResponses, unknown, ThrowOnError>({
url: "/api/v1/auth/me", url: '/api/v1/auth/me',
...options, ...options
}); });
}; };
@@ -156,24 +71,22 @@ export const getMe = <ThrowOnError extends boolean = false>(options?: Options<Ge
*/ */
export const getStatus = <ThrowOnError extends boolean = false>(options?: Options<GetStatusData, ThrowOnError>) => { export const getStatus = <ThrowOnError extends boolean = false>(options?: Options<GetStatusData, ThrowOnError>) => {
return (options?.client ?? client).get<GetStatusResponses, unknown, ThrowOnError>({ return (options?.client ?? client).get<GetStatusResponses, unknown, ThrowOnError>({
url: "/api/v1/auth/status", url: '/api/v1/auth/status',
...options, ...options
}); });
}; };
/** /**
* Change current user password * Change current user password
*/ */
export const changePassword = <ThrowOnError extends boolean = false>( export const changePassword = <ThrowOnError extends boolean = false>(options?: Options<ChangePasswordData, ThrowOnError>) => {
options?: Options<ChangePasswordData, ThrowOnError>,
) => {
return (options?.client ?? client).post<ChangePasswordResponses, unknown, ThrowOnError>({ return (options?.client ?? client).post<ChangePasswordResponses, unknown, ThrowOnError>({
url: "/api/v1/auth/change-password", url: '/api/v1/auth/change-password',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options?.headers, ...options?.headers
}, }
}); });
}; };
@@ -182,52 +95,46 @@ export const changePassword = <ThrowOnError extends boolean = false>(
*/ */
export const listVolumes = <ThrowOnError extends boolean = false>(options?: Options<ListVolumesData, ThrowOnError>) => { export const listVolumes = <ThrowOnError extends boolean = false>(options?: Options<ListVolumesData, ThrowOnError>) => {
return (options?.client ?? client).get<ListVolumesResponses, unknown, ThrowOnError>({ return (options?.client ?? client).get<ListVolumesResponses, unknown, ThrowOnError>({
url: "/api/v1/volumes", url: '/api/v1/volumes',
...options, ...options
}); });
}; };
/** /**
* Create a new volume * Create a new volume
*/ */
export const createVolume = <ThrowOnError extends boolean = false>( export const createVolume = <ThrowOnError extends boolean = false>(options?: Options<CreateVolumeData, ThrowOnError>) => {
options?: Options<CreateVolumeData, ThrowOnError>,
) => {
return (options?.client ?? client).post<CreateVolumeResponses, unknown, ThrowOnError>({ return (options?.client ?? client).post<CreateVolumeResponses, unknown, ThrowOnError>({
url: "/api/v1/volumes", url: '/api/v1/volumes',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options?.headers, ...options?.headers
}, }
}); });
}; };
/** /**
* Test connection to backend * Test connection to backend
*/ */
export const testConnection = <ThrowOnError extends boolean = false>( export const testConnection = <ThrowOnError extends boolean = false>(options?: Options<TestConnectionData, ThrowOnError>) => {
options?: Options<TestConnectionData, ThrowOnError>,
) => {
return (options?.client ?? client).post<TestConnectionResponses, unknown, ThrowOnError>({ return (options?.client ?? client).post<TestConnectionResponses, unknown, ThrowOnError>({
url: "/api/v1/volumes/test-connection", url: '/api/v1/volumes/test-connection',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options?.headers, ...options?.headers
}, }
}); });
}; };
/** /**
* Delete a volume * Delete a volume
*/ */
export const deleteVolume = <ThrowOnError extends boolean = false>( export const deleteVolume = <ThrowOnError extends boolean = false>(options: Options<DeleteVolumeData, ThrowOnError>) => {
options: Options<DeleteVolumeData, ThrowOnError>,
) => {
return (options.client ?? client).delete<DeleteVolumeResponses, unknown, ThrowOnError>({ return (options.client ?? client).delete<DeleteVolumeResponses, unknown, ThrowOnError>({
url: "/api/v1/volumes/{name}", url: '/api/v1/volumes/{name}',
...options, ...options
}); });
}; };
@@ -236,40 +143,32 @@ export const deleteVolume = <ThrowOnError extends boolean = false>(
*/ */
export const getVolume = <ThrowOnError extends boolean = false>(options: Options<GetVolumeData, ThrowOnError>) => { export const getVolume = <ThrowOnError extends boolean = false>(options: Options<GetVolumeData, ThrowOnError>) => {
return (options.client ?? client).get<GetVolumeResponses, GetVolumeErrors, ThrowOnError>({ return (options.client ?? client).get<GetVolumeResponses, GetVolumeErrors, ThrowOnError>({
url: "/api/v1/volumes/{name}", url: '/api/v1/volumes/{name}',
...options, ...options
}); });
}; };
/** /**
* Update a volume's configuration * Update a volume's configuration
*/ */
export const updateVolume = <ThrowOnError extends boolean = false>( export const updateVolume = <ThrowOnError extends boolean = false>(options: Options<UpdateVolumeData, ThrowOnError>) => {
options: Options<UpdateVolumeData, ThrowOnError>,
) => {
return (options.client ?? client).put<UpdateVolumeResponses, UpdateVolumeErrors, ThrowOnError>({ return (options.client ?? client).put<UpdateVolumeResponses, UpdateVolumeErrors, ThrowOnError>({
url: "/api/v1/volumes/{name}", url: '/api/v1/volumes/{name}',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options.headers, ...options.headers
}, }
}); });
}; };
/** /**
* Get containers using a volume by name * Get containers using a volume by name
*/ */
export const getContainersUsingVolume = <ThrowOnError extends boolean = false>( export const getContainersUsingVolume = <ThrowOnError extends boolean = false>(options: Options<GetContainersUsingVolumeData, ThrowOnError>) => {
options: Options<GetContainersUsingVolumeData, ThrowOnError>, return (options.client ?? client).get<GetContainersUsingVolumeResponses, GetContainersUsingVolumeErrors, ThrowOnError>({
) => { url: '/api/v1/volumes/{name}/containers',
return (options.client ?? client).get< ...options
GetContainersUsingVolumeResponses,
GetContainersUsingVolumeErrors,
ThrowOnError
>({
url: "/api/v1/volumes/{name}/containers",
...options,
}); });
}; };
@@ -278,32 +177,28 @@ export const getContainersUsingVolume = <ThrowOnError extends boolean = false>(
*/ */
export const mountVolume = <ThrowOnError extends boolean = false>(options: Options<MountVolumeData, ThrowOnError>) => { export const mountVolume = <ThrowOnError extends boolean = false>(options: Options<MountVolumeData, ThrowOnError>) => {
return (options.client ?? client).post<MountVolumeResponses, unknown, ThrowOnError>({ return (options.client ?? client).post<MountVolumeResponses, unknown, ThrowOnError>({
url: "/api/v1/volumes/{name}/mount", url: '/api/v1/volumes/{name}/mount',
...options, ...options
}); });
}; };
/** /**
* Unmount a volume * Unmount a volume
*/ */
export const unmountVolume = <ThrowOnError extends boolean = false>( export const unmountVolume = <ThrowOnError extends boolean = false>(options: Options<UnmountVolumeData, ThrowOnError>) => {
options: Options<UnmountVolumeData, ThrowOnError>,
) => {
return (options.client ?? client).post<UnmountVolumeResponses, unknown, ThrowOnError>({ return (options.client ?? client).post<UnmountVolumeResponses, unknown, ThrowOnError>({
url: "/api/v1/volumes/{name}/unmount", url: '/api/v1/volumes/{name}/unmount',
...options, ...options
}); });
}; };
/** /**
* Perform a health check on a volume * Perform a health check on a volume
*/ */
export const healthCheckVolume = <ThrowOnError extends boolean = false>( export const healthCheckVolume = <ThrowOnError extends boolean = false>(options: Options<HealthCheckVolumeData, ThrowOnError>) => {
options: Options<HealthCheckVolumeData, ThrowOnError>,
) => {
return (options.client ?? client).post<HealthCheckVolumeResponses, HealthCheckVolumeErrors, ThrowOnError>({ return (options.client ?? client).post<HealthCheckVolumeResponses, HealthCheckVolumeErrors, ThrowOnError>({
url: "/api/v1/volumes/{name}/health-check", url: '/api/v1/volumes/{name}/health-check',
...options, ...options
}); });
}; };
@@ -312,240 +207,204 @@ export const healthCheckVolume = <ThrowOnError extends boolean = false>(
*/ */
export const listFiles = <ThrowOnError extends boolean = false>(options: Options<ListFilesData, ThrowOnError>) => { export const listFiles = <ThrowOnError extends boolean = false>(options: Options<ListFilesData, ThrowOnError>) => {
return (options.client ?? client).get<ListFilesResponses, unknown, ThrowOnError>({ return (options.client ?? client).get<ListFilesResponses, unknown, ThrowOnError>({
url: "/api/v1/volumes/{name}/files", url: '/api/v1/volumes/{name}/files',
...options, ...options
}); });
}; };
/** /**
* Browse directories on the host filesystem * Browse directories on the host filesystem
*/ */
export const browseFilesystem = <ThrowOnError extends boolean = false>( export const browseFilesystem = <ThrowOnError extends boolean = false>(options?: Options<BrowseFilesystemData, ThrowOnError>) => {
options?: Options<BrowseFilesystemData, ThrowOnError>,
) => {
return (options?.client ?? client).get<BrowseFilesystemResponses, unknown, ThrowOnError>({ return (options?.client ?? client).get<BrowseFilesystemResponses, unknown, ThrowOnError>({
url: "/api/v1/volumes/filesystem/browse", url: '/api/v1/volumes/filesystem/browse',
...options, ...options
}); });
}; };
/** /**
* List all repositories * List all repositories
*/ */
export const listRepositories = <ThrowOnError extends boolean = false>( export const listRepositories = <ThrowOnError extends boolean = false>(options?: Options<ListRepositoriesData, ThrowOnError>) => {
options?: Options<ListRepositoriesData, ThrowOnError>,
) => {
return (options?.client ?? client).get<ListRepositoriesResponses, unknown, ThrowOnError>({ return (options?.client ?? client).get<ListRepositoriesResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories", url: '/api/v1/repositories',
...options, ...options
}); });
}; };
/** /**
* Create a new restic repository * Create a new restic repository
*/ */
export const createRepository = <ThrowOnError extends boolean = false>( export const createRepository = <ThrowOnError extends boolean = false>(options?: Options<CreateRepositoryData, ThrowOnError>) => {
options?: Options<CreateRepositoryData, ThrowOnError>,
) => {
return (options?.client ?? client).post<CreateRepositoryResponses, unknown, ThrowOnError>({ return (options?.client ?? client).post<CreateRepositoryResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories", url: '/api/v1/repositories',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options?.headers, ...options?.headers
}, }
}); });
}; };
/** /**
* List all configured rclone remotes on the host system * List all configured rclone remotes on the host system
*/ */
export const listRcloneRemotes = <ThrowOnError extends boolean = false>( export const listRcloneRemotes = <ThrowOnError extends boolean = false>(options?: Options<ListRcloneRemotesData, ThrowOnError>) => {
options?: Options<ListRcloneRemotesData, ThrowOnError>,
) => {
return (options?.client ?? client).get<ListRcloneRemotesResponses, unknown, ThrowOnError>({ return (options?.client ?? client).get<ListRcloneRemotesResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/rclone-remotes", url: '/api/v1/repositories/rclone-remotes',
...options, ...options
}); });
}; };
/** /**
* Delete a repository * Delete a repository
*/ */
export const deleteRepository = <ThrowOnError extends boolean = false>( export const deleteRepository = <ThrowOnError extends boolean = false>(options: Options<DeleteRepositoryData, ThrowOnError>) => {
options: Options<DeleteRepositoryData, ThrowOnError>,
) => {
return (options.client ?? client).delete<DeleteRepositoryResponses, unknown, ThrowOnError>({ return (options.client ?? client).delete<DeleteRepositoryResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{name}", url: '/api/v1/repositories/{name}',
...options, ...options
}); });
}; };
/** /**
* Get a single repository by name * Get a single repository by name
*/ */
export const getRepository = <ThrowOnError extends boolean = false>( export const getRepository = <ThrowOnError extends boolean = false>(options: Options<GetRepositoryData, ThrowOnError>) => {
options: Options<GetRepositoryData, ThrowOnError>,
) => {
return (options.client ?? client).get<GetRepositoryResponses, unknown, ThrowOnError>({ return (options.client ?? client).get<GetRepositoryResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{name}", url: '/api/v1/repositories/{name}',
...options, ...options
}); });
}; };
/** /**
* List all snapshots in a repository * List all snapshots in a repository
*/ */
export const listSnapshots = <ThrowOnError extends boolean = false>( export const listSnapshots = <ThrowOnError extends boolean = false>(options: Options<ListSnapshotsData, ThrowOnError>) => {
options: Options<ListSnapshotsData, ThrowOnError>,
) => {
return (options.client ?? client).get<ListSnapshotsResponses, unknown, ThrowOnError>({ return (options.client ?? client).get<ListSnapshotsResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{name}/snapshots", url: '/api/v1/repositories/{name}/snapshots',
...options, ...options
}); });
}; };
/** /**
* Get details of a specific snapshot * Get details of a specific snapshot
*/ */
export const getSnapshotDetails = <ThrowOnError extends boolean = false>( export const getSnapshotDetails = <ThrowOnError extends boolean = false>(options: Options<GetSnapshotDetailsData, ThrowOnError>) => {
options: Options<GetSnapshotDetailsData, ThrowOnError>,
) => {
return (options.client ?? client).get<GetSnapshotDetailsResponses, unknown, ThrowOnError>({ return (options.client ?? client).get<GetSnapshotDetailsResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{name}/snapshots/{snapshotId}", url: '/api/v1/repositories/{name}/snapshots/{snapshotId}',
...options, ...options
}); });
}; };
/** /**
* List files and directories in a snapshot * List files and directories in a snapshot
*/ */
export const listSnapshotFiles = <ThrowOnError extends boolean = false>( export const listSnapshotFiles = <ThrowOnError extends boolean = false>(options: Options<ListSnapshotFilesData, ThrowOnError>) => {
options: Options<ListSnapshotFilesData, ThrowOnError>,
) => {
return (options.client ?? client).get<ListSnapshotFilesResponses, unknown, ThrowOnError>({ return (options.client ?? client).get<ListSnapshotFilesResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{name}/snapshots/{snapshotId}/files", url: '/api/v1/repositories/{name}/snapshots/{snapshotId}/files',
...options, ...options
}); });
}; };
/** /**
* Restore a snapshot to a target path on the filesystem * Restore a snapshot to a target path on the filesystem
*/ */
export const restoreSnapshot = <ThrowOnError extends boolean = false>( export const restoreSnapshot = <ThrowOnError extends boolean = false>(options: Options<RestoreSnapshotData, ThrowOnError>) => {
options: Options<RestoreSnapshotData, ThrowOnError>,
) => {
return (options.client ?? client).post<RestoreSnapshotResponses, unknown, ThrowOnError>({ return (options.client ?? client).post<RestoreSnapshotResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{name}/restore", url: '/api/v1/repositories/{name}/restore',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options.headers, ...options.headers
}, }
}); });
}; };
/** /**
* Run doctor operations on a repository to fix common issues (unlock, check, repair index). Use this when the repository is locked or has errors. * Run doctor operations on a repository to fix common issues (unlock, check, repair index). Use this when the repository is locked or has errors.
*/ */
export const doctorRepository = <ThrowOnError extends boolean = false>( export const doctorRepository = <ThrowOnError extends boolean = false>(options: Options<DoctorRepositoryData, ThrowOnError>) => {
options: Options<DoctorRepositoryData, ThrowOnError>,
) => {
return (options.client ?? client).post<DoctorRepositoryResponses, unknown, ThrowOnError>({ return (options.client ?? client).post<DoctorRepositoryResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{name}/doctor", url: '/api/v1/repositories/{name}/doctor',
...options, ...options
}); });
}; };
/** /**
* List all backup schedules * List all backup schedules
*/ */
export const listBackupSchedules = <ThrowOnError extends boolean = false>( export const listBackupSchedules = <ThrowOnError extends boolean = false>(options?: Options<ListBackupSchedulesData, ThrowOnError>) => {
options?: Options<ListBackupSchedulesData, ThrowOnError>,
) => {
return (options?.client ?? client).get<ListBackupSchedulesResponses, unknown, ThrowOnError>({ return (options?.client ?? client).get<ListBackupSchedulesResponses, unknown, ThrowOnError>({
url: "/api/v1/backups", url: '/api/v1/backups',
...options, ...options
}); });
}; };
/** /**
* Create a new backup schedule for a volume * Create a new backup schedule for a volume
*/ */
export const createBackupSchedule = <ThrowOnError extends boolean = false>( export const createBackupSchedule = <ThrowOnError extends boolean = false>(options?: Options<CreateBackupScheduleData, ThrowOnError>) => {
options?: Options<CreateBackupScheduleData, ThrowOnError>,
) => {
return (options?.client ?? client).post<CreateBackupScheduleResponses, unknown, ThrowOnError>({ return (options?.client ?? client).post<CreateBackupScheduleResponses, unknown, ThrowOnError>({
url: "/api/v1/backups", url: '/api/v1/backups',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options?.headers, ...options?.headers
}, }
}); });
}; };
/** /**
* Delete a backup schedule * Delete a backup schedule
*/ */
export const deleteBackupSchedule = <ThrowOnError extends boolean = false>( export const deleteBackupSchedule = <ThrowOnError extends boolean = false>(options: Options<DeleteBackupScheduleData, ThrowOnError>) => {
options: Options<DeleteBackupScheduleData, ThrowOnError>,
) => {
return (options.client ?? client).delete<DeleteBackupScheduleResponses, unknown, ThrowOnError>({ return (options.client ?? client).delete<DeleteBackupScheduleResponses, unknown, ThrowOnError>({
url: "/api/v1/backups/{scheduleId}", url: '/api/v1/backups/{scheduleId}',
...options, ...options
}); });
}; };
/** /**
* Get a backup schedule by ID * Get a backup schedule by ID
*/ */
export const getBackupSchedule = <ThrowOnError extends boolean = false>( export const getBackupSchedule = <ThrowOnError extends boolean = false>(options: Options<GetBackupScheduleData, ThrowOnError>) => {
options: Options<GetBackupScheduleData, ThrowOnError>,
) => {
return (options.client ?? client).get<GetBackupScheduleResponses, unknown, ThrowOnError>({ return (options.client ?? client).get<GetBackupScheduleResponses, unknown, ThrowOnError>({
url: "/api/v1/backups/{scheduleId}", url: '/api/v1/backups/{scheduleId}',
...options, ...options
}); });
}; };
/** /**
* Update a backup schedule * Update a backup schedule
*/ */
export const updateBackupSchedule = <ThrowOnError extends boolean = false>( export const updateBackupSchedule = <ThrowOnError extends boolean = false>(options: Options<UpdateBackupScheduleData, ThrowOnError>) => {
options: Options<UpdateBackupScheduleData, ThrowOnError>,
) => {
return (options.client ?? client).patch<UpdateBackupScheduleResponses, unknown, ThrowOnError>({ return (options.client ?? client).patch<UpdateBackupScheduleResponses, unknown, ThrowOnError>({
url: "/api/v1/backups/{scheduleId}", url: '/api/v1/backups/{scheduleId}',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options.headers, ...options.headers
}, }
}); });
}; };
/** /**
* Get a backup schedule for a specific volume * Get a backup schedule for a specific volume
*/ */
export const getBackupScheduleForVolume = <ThrowOnError extends boolean = false>( export const getBackupScheduleForVolume = <ThrowOnError extends boolean = false>(options: Options<GetBackupScheduleForVolumeData, ThrowOnError>) => {
options: Options<GetBackupScheduleForVolumeData, ThrowOnError>,
) => {
return (options.client ?? client).get<GetBackupScheduleForVolumeResponses, unknown, ThrowOnError>({ return (options.client ?? client).get<GetBackupScheduleForVolumeResponses, unknown, ThrowOnError>({
url: "/api/v1/backups/volume/{volumeId}", url: '/api/v1/backups/volume/{volumeId}',
...options, ...options
}); });
}; };
/** /**
* Trigger a backup immediately for a schedule * Trigger a backup immediately for a schedule
*/ */
export const runBackupNow = <ThrowOnError extends boolean = false>( export const runBackupNow = <ThrowOnError extends boolean = false>(options: Options<RunBackupNowData, ThrowOnError>) => {
options: Options<RunBackupNowData, ThrowOnError>,
) => {
return (options.client ?? client).post<RunBackupNowResponses, unknown, ThrowOnError>({ return (options.client ?? client).post<RunBackupNowResponses, unknown, ThrowOnError>({
url: "/api/v1/backups/{scheduleId}/run", url: '/api/v1/backups/{scheduleId}/run',
...options, ...options
}); });
}; };
@@ -554,35 +413,41 @@ export const runBackupNow = <ThrowOnError extends boolean = false>(
*/ */
export const stopBackup = <ThrowOnError extends boolean = false>(options: Options<StopBackupData, ThrowOnError>) => { export const stopBackup = <ThrowOnError extends boolean = false>(options: Options<StopBackupData, ThrowOnError>) => {
return (options.client ?? client).post<StopBackupResponses, StopBackupErrors, ThrowOnError>({ return (options.client ?? client).post<StopBackupResponses, StopBackupErrors, ThrowOnError>({
url: "/api/v1/backups/{scheduleId}/stop", url: '/api/v1/backups/{scheduleId}/stop',
...options, ...options
});
};
/**
* Manually apply retention policy to clean up old snapshots
*/
export const runForget = <ThrowOnError extends boolean = false>(options: Options<RunForgetData, ThrowOnError>) => {
return (options.client ?? client).post<RunForgetResponses, unknown, ThrowOnError>({
url: '/api/v1/backups/{scheduleId}/forget',
...options
}); });
}; };
/** /**
* Get system information including available capabilities * Get system information including available capabilities
*/ */
export const getSystemInfo = <ThrowOnError extends boolean = false>( export const getSystemInfo = <ThrowOnError extends boolean = false>(options?: Options<GetSystemInfoData, ThrowOnError>) => {
options?: Options<GetSystemInfoData, ThrowOnError>,
) => {
return (options?.client ?? client).get<GetSystemInfoResponses, unknown, ThrowOnError>({ return (options?.client ?? client).get<GetSystemInfoResponses, unknown, ThrowOnError>({
url: "/api/v1/system/info", url: '/api/v1/system/info',
...options, ...options
}); });
}; };
/** /**
* Download the Restic password file for backup recovery. Requires password re-authentication. * Download the Restic password file for backup recovery. Requires password re-authentication.
*/ */
export const downloadResticPassword = <ThrowOnError extends boolean = false>( export const downloadResticPassword = <ThrowOnError extends boolean = false>(options?: Options<DownloadResticPasswordData, ThrowOnError>) => {
options?: Options<DownloadResticPasswordData, ThrowOnError>,
) => {
return (options?.client ?? client).post<DownloadResticPasswordResponses, unknown, ThrowOnError>({ return (options?.client ?? client).post<DownloadResticPasswordResponses, unknown, ThrowOnError>({
url: "/api/v1/system/restic-password", url: '/api/v1/system/restic-password',
...options, ...options,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
...options?.headers, ...options?.headers
}, }
}); });
}; };

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
import { arktypeResolver } from "@hookform/resolvers/arktype"; import { arktypeResolver } from "@hookform/resolvers/arktype";
import { type } from "arktype"; import { type } from "arktype";
import { useEffect } from "react"; import { useEffect, useState } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { cn, slugify } from "~/client/lib/utils"; import { cn, slugify } from "~/client/lib/utils";
import { deepClean } from "~/utils/object"; import { deepClean } from "~/utils/object";
@@ -15,6 +15,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
import { useSystemInfo } from "~/client/hooks/use-system-info"; import { useSystemInfo } from "~/client/hooks/use-system-info";
import { COMPRESSION_MODES, repositoryConfigSchema } from "~/schemas/restic"; import { COMPRESSION_MODES, repositoryConfigSchema } from "~/schemas/restic";
import { listRcloneRemotesOptions } from "../api-client/@tanstack/react-query.gen"; import { listRcloneRemotesOptions } from "../api-client/@tanstack/react-query.gen";
import { Checkbox } from "./ui/checkbox";
export const formSchema = type({ export const formSchema = type({
name: "2<=string<=32", name: "2<=string<=32",
@@ -59,23 +60,29 @@ export const CreateRepositoryForm = ({
}, },
}); });
const { watch } = form; const { watch, setValue } = form;
const watchedBackend = watch("backend"); const watchedBackend = watch("backend");
const watchedIsExistingRepository = watch("isExistingRepository");
const [passwordMode, setPasswordMode] = useState<"default" | "custom">("default");
const { capabilities } = useSystemInfo();
const { data: rcloneRemotes, isLoading: isLoadingRemotes } = useQuery({ const { data: rcloneRemotes, isLoading: isLoadingRemotes } = useQuery({
...listRcloneRemotesOptions(), ...listRcloneRemotesOptions(),
enabled: capabilities.rclone,
}); });
useEffect(() => { useEffect(() => {
form.reset({ form.reset({
name: form.getValues().name, name: form.getValues().name,
isExistingRepository: form.getValues().isExistingRepository,
customPassword: form.getValues().customPassword,
...defaultValuesForType[watchedBackend as keyof typeof defaultValuesForType], ...defaultValuesForType[watchedBackend as keyof typeof defaultValuesForType],
}); });
}, [watchedBackend, form]); }, [watchedBackend, form]);
const { capabilities } = useSystemInfo();
return ( return (
<Form {...form}> <Form {...form}>
<form id={formId} onSubmit={form.handleSubmit(onSubmit)} className={cn("space-y-4", className)}> <form id={formId} onSubmit={form.handleSubmit(onSubmit)} className={cn("space-y-4", className)}>
@@ -163,6 +170,81 @@ export const CreateRepositoryForm = ({
)} )}
/> />
<FormField
control={form.control}
name="isExistingRepository"
render={({ field }) => (
<FormItem className="flex flex-row items-center space-x-3">
<FormControl>
<Checkbox
checked={field.value}
onCheckedChange={(checked) => {
field.onChange(checked);
if (!checked) {
setPasswordMode("default");
setValue("customPassword", undefined);
}
}}
/>
</FormControl>
<div className="space-y-1">
<FormLabel>Import existing repository</FormLabel>
<FormDescription>Check this if the repository already exists at the specified location</FormDescription>
</div>
</FormItem>
)}
/>
{watchedIsExistingRepository && (
<>
<FormItem>
<FormLabel>Repository Password</FormLabel>
<Select
onValueChange={(value) => {
setPasswordMode(value as "default" | "custom");
if (value === "default") {
setValue("customPassword", undefined);
}
}}
defaultValue={passwordMode}
value={passwordMode}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select password option" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="default">Use Ironmount's password</SelectItem>
<SelectItem value="custom">Enter password manually</SelectItem>
</SelectContent>
</Select>
<FormDescription>
Choose whether to use Ironmount's master password or enter a custom password for the existing
repository.
</FormDescription>
</FormItem>
{passwordMode === "custom" && (
<FormField
control={form.control}
name="customPassword"
render={({ field }) => (
<FormItem>
<FormLabel>Repository Password</FormLabel>
<FormControl>
<Input type="password" placeholder="Enter repository password" {...field} />
</FormControl>
<FormDescription>
The password used to encrypt this repository. It will be stored securely.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
)}
</>
)}
{watchedBackend === "s3" && ( {watchedBackend === "s3" && (
<> <>
<FormField <FormField
@@ -235,7 +317,9 @@ export const CreateRepositoryForm = ({
<FormControl> <FormControl>
<Input placeholder="<account-id>.r2.cloudflarestorage.com" {...field} /> <Input placeholder="<account-id>.r2.cloudflarestorage.com" {...field} />
</FormControl> </FormControl>
<FormDescription>R2 endpoint (without https://). Find in R2 dashboard under bucket settings.</FormDescription> <FormDescription>
R2 endpoint (without https://). Find in R2 dashboard under bucket settings.
</FormDescription>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
)} )}

View File

@@ -1,4 +1,4 @@
import { Cloud, Folder, Server, Share2 } from "lucide-react"; import { Cloud, Database, Folder, Server, Share2 } from "lucide-react";
import type { BackendType } from "~/schemas/volumes"; import type { BackendType } from "~/schemas/volumes";
type VolumeIconProps = { type VolumeIconProps = {
@@ -32,6 +32,24 @@ const getIconAndColor = (backend: BackendType) => {
color: "text-green-600 dark:text-green-400", color: "text-green-600 dark:text-green-400",
label: "WebDAV", label: "WebDAV",
}; };
case "mariadb":
return {
icon: Database,
color: "text-teal-600 dark:text-teal-400",
label: "MariaDB",
};
case "mysql":
return {
icon: Database,
color: "text-cyan-600 dark:text-cyan-400",
label: "MySQL",
};
case "postgres":
return {
icon: Database,
color: "text-indigo-600 dark:text-indigo-400",
label: "PostgreSQL",
};
default: default:
return { return {
icon: Folder, icon: Folder,

View File

@@ -1,4 +1,4 @@
import { Pencil, Play, Square, Trash2 } from "lucide-react"; import { Eraser, Pencil, Play, Square, Trash2 } from "lucide-react";
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
import { OnOff } from "~/client/components/onoff"; import { OnOff } from "~/client/components/onoff";
import { Button } from "~/client/components/ui/button"; import { Button } from "~/client/components/ui/button";
@@ -14,6 +14,10 @@ import {
} from "~/client/components/ui/alert-dialog"; } from "~/client/components/ui/alert-dialog";
import type { BackupSchedule } from "~/client/lib/types"; import type { BackupSchedule } from "~/client/lib/types";
import { BackupProgressCard } from "./backup-progress-card"; import { BackupProgressCard } from "./backup-progress-card";
import { runForgetMutation } from "~/client/api-client/@tanstack/react-query.gen";
import { useMutation } from "@tanstack/react-query";
import { toast } from "sonner";
import { parseError } from "~/client/lib/errors";
type Props = { type Props = {
schedule: BackupSchedule; schedule: BackupSchedule;
@@ -28,6 +32,17 @@ export const ScheduleSummary = (props: Props) => {
const { schedule, handleToggleEnabled, handleRunBackupNow, handleStopBackup, handleDeleteSchedule, setIsEditMode } = const { schedule, handleToggleEnabled, handleRunBackupNow, handleStopBackup, handleDeleteSchedule, setIsEditMode } =
props; props;
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
const [showForgetConfirm, setShowForgetConfirm] = useState(false);
const runForget = useMutation({
...runForgetMutation(),
onSuccess: () => {
toast.success("Retention policy applied successfully");
},
onError: (error) => {
toast.error("Failed to apply retention policy", { description: parseError(error)?.message });
},
});
const summary = useMemo(() => { const summary = useMemo(() => {
const scheduleLabel = schedule ? schedule.cronExpression : "-"; const scheduleLabel = schedule ? schedule.cronExpression : "-";
@@ -56,6 +71,11 @@ export const ScheduleSummary = (props: Props) => {
handleDeleteSchedule(); handleDeleteSchedule();
}; };
const handleConfirmForget = () => {
setShowForgetConfirm(false);
runForget.mutate({ path: { scheduleId: schedule.id.toString() } });
};
return ( return (
<div className="space-y-4"> <div className="space-y-4">
<Card> <Card>
@@ -89,6 +109,18 @@ export const ScheduleSummary = (props: Props) => {
<span className="sm:inline">Backup now</span> <span className="sm:inline">Backup now</span>
</Button> </Button>
)} )}
{schedule.retentionPolicy && (
<Button
variant="outline"
size="sm"
loading={runForget.isPending}
onClick={() => setShowForgetConfirm(true)}
className="w-full sm:w-auto"
>
<Eraser className="h-4 w-4 mr-2" />
<span className="sm:inline">Run cleanup</span>
</Button>
)}
<Button variant="outline" size="sm" onClick={() => setIsEditMode(true)} className="w-full sm:w-auto"> <Button variant="outline" size="sm" onClick={() => setIsEditMode(true)} className="w-full sm:w-auto">
<Pencil className="h-4 w-4 mr-2" /> <Pencil className="h-4 w-4 mr-2" />
<span className="sm:inline">Edit schedule</span> <span className="sm:inline">Edit schedule</span>
@@ -167,6 +199,22 @@ export const ScheduleSummary = (props: Props) => {
</div> </div>
</AlertDialogContent> </AlertDialogContent>
</AlertDialog> </AlertDialog>
<AlertDialog open={showForgetConfirm} onOpenChange={setShowForgetConfirm}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Run retention policy cleanup?</AlertDialogTitle>
<AlertDialogDescription>
This will apply the retention policy and permanently delete old snapshots according to the configured
rules ({summary.retentionLabel}). This action cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<div className="flex gap-3 justify-end">
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={handleConfirmForget}>Run cleanup</AlertDialogAction>
</div>
</AlertDialogContent>
</AlertDialog>
</div> </div>
); );
}; };

View File

@@ -6,13 +6,31 @@ import { useEffect, useState } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { cn, slugify } from "~/client/lib/utils"; import { cn, slugify } from "~/client/lib/utils";
import { deepClean } from "~/utils/object"; import { deepClean } from "~/utils/object";
import { DirectoryBrowser } from "./directory-browser";
import { Button } from "./ui/button";
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "./ui/form";
import { Input } from "./ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
import { volumeConfigSchema } from "~/schemas/volumes"; import { volumeConfigSchema } from "~/schemas/volumes";
import { testConnectionMutation } from "../api-client/@tanstack/react-query.gen"; import { testConnectionMutation } from "~/client/api-client/@tanstack/react-query.gen";
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "~/client/components/ui/form";
import { Input } from "~/client/components/ui/input";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue,
} from "~/client/components/ui/select";
import { Button } from "~/client/components/ui/button";
import { DirectoryBrowser } from "~/client/components/directory-browser";
const SUPPORTS_CONNECTION_TEST = ["nfs", "smb", "webdav", "mariadb", "mysql", "postgres"];
export const formSchema = type({ export const formSchema = type({
name: "2<=string<=32", name: "2<=string<=32",
@@ -35,6 +53,9 @@ const defaultValuesForType = {
nfs: { backend: "nfs" as const, port: 2049, version: "4.1" as const }, nfs: { backend: "nfs" as const, port: 2049, version: "4.1" as const },
smb: { backend: "smb" as const, port: 445, vers: "3.0" as const }, smb: { backend: "smb" as const, port: 445, vers: "3.0" as const },
webdav: { backend: "webdav" as const, port: 80, ssl: false }, webdav: { backend: "webdav" as const, port: 80, ssl: false },
mariadb: { backend: "mariadb" as const, port: 3306 },
mysql: { backend: "mysql" as const, port: 3306 },
postgres: { backend: "postgres" as const, port: 5432, dumpFormat: "custom" as const },
}; };
export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, formId, loading, className }: Props) => { export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, formId, loading, className }: Props) => {
@@ -81,7 +102,7 @@ export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, for
const handleTestConnection = async () => { const handleTestConnection = async () => {
const formValues = getValues(); const formValues = getValues();
if (formValues.backend === "nfs" || formValues.backend === "smb" || formValues.backend === "webdav") { if (SUPPORTS_CONNECTION_TEST.includes(formValues.backend)) {
testBackendConnection.mutate({ testBackendConnection.mutate({
body: { config: formValues }, body: { config: formValues },
}); });
@@ -121,15 +142,26 @@ export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, for
<FormLabel>Backend</FormLabel> <FormLabel>Backend</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value} value={field.value}> <Select onValueChange={field.onChange} defaultValue={field.value} value={field.value}>
<FormControl> <FormControl>
<SelectTrigger> <SelectTrigger className="w-[280px]">
<SelectValue placeholder="Select a backend" /> <SelectValue placeholder="Select a backend" />
</SelectTrigger> </SelectTrigger>
</FormControl> </FormControl>
<SelectContent> <SelectContent>
<SelectGroup>
<SelectItem value="directory">Directory</SelectItem> <SelectItem value="directory">Directory</SelectItem>
</SelectGroup>
<SelectGroup>
<SelectLabel>Network Storage</SelectLabel>
<SelectItem value="nfs">NFS</SelectItem> <SelectItem value="nfs">NFS</SelectItem>
<SelectItem value="smb">SMB</SelectItem> <SelectItem value="smb">SMB</SelectItem>
<SelectItem value="webdav">WebDAV</SelectItem> <SelectItem value="webdav">WebDAV</SelectItem>
</SelectGroup>
<SelectGroup>
<SelectLabel>Databases</SelectLabel>
<SelectItem value="mariadb">MariaDB</SelectItem>
<SelectItem value="mysql">MySQL</SelectItem>
<SelectItem value="postgres">PostgreSQL</SelectItem>
</SelectGroup>
</SelectContent> </SelectContent>
</Select> </Select>
<FormDescription>Choose the storage backend for this volume.</FormDescription> <FormDescription>Choose the storage backend for this volume.</FormDescription>
@@ -536,6 +568,258 @@ export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, for
</> </>
)} )}
{watchedBackend === "mariadb" && (
<>
<FormField
control={form.control}
name="host"
render={({ field }) => (
<FormItem>
<FormLabel>Host</FormLabel>
<FormControl>
<Input placeholder="localhost" {...field} />
</FormControl>
<FormDescription>MariaDB server hostname or IP address.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="port"
defaultValue={3306}
render={({ field }) => (
<FormItem>
<FormLabel>Port</FormLabel>
<FormControl>
<Input type="number" placeholder="3306" {...field} />
</FormControl>
<FormDescription>MariaDB server port (default: 3306).</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="username"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Input placeholder="root" {...field} />
</FormControl>
<FormDescription>Database user with backup privileges.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="password"
render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl>
<Input type="password" placeholder="••••••••" {...field} />
</FormControl>
<FormDescription>Password for database authentication.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="database"
render={({ field }) => (
<FormItem>
<FormLabel>Database</FormLabel>
<FormControl>
<Input placeholder="myapp_production" {...field} />
</FormControl>
<FormDescription>Name of the database to backup.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</>
)}
{watchedBackend === "mysql" && (
<>
<FormField
control={form.control}
name="host"
render={({ field }) => (
<FormItem>
<FormLabel>Host</FormLabel>
<FormControl>
<Input placeholder="localhost" {...field} />
</FormControl>
<FormDescription>MySQL server hostname or IP address.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="port"
defaultValue={3306}
render={({ field }) => (
<FormItem>
<FormLabel>Port</FormLabel>
<FormControl>
<Input type="number" placeholder="3306" {...field} />
</FormControl>
<FormDescription>MySQL server port (default: 3306).</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="username"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Input placeholder="root" {...field} />
</FormControl>
<FormDescription>Database user with backup privileges.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="password"
render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl>
<Input type="password" placeholder="••••••••" {...field} />
</FormControl>
<FormDescription>Password for database authentication.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="database"
render={({ field }) => (
<FormItem>
<FormLabel>Database</FormLabel>
<FormControl>
<Input placeholder="myapp_production" {...field} />
</FormControl>
<FormDescription>Name of the database to backup.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</>
)}
{watchedBackend === "postgres" && (
<>
<FormField
control={form.control}
name="host"
render={({ field }) => (
<FormItem>
<FormLabel>Host</FormLabel>
<FormControl>
<Input placeholder="localhost" {...field} />
</FormControl>
<FormDescription>PostgreSQL server hostname or IP address.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="port"
defaultValue={5432}
render={({ field }) => (
<FormItem>
<FormLabel>Port</FormLabel>
<FormControl>
<Input type="number" placeholder="5432" {...field} />
</FormControl>
<FormDescription>PostgreSQL server port (default: 5432).</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="username"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Input placeholder="postgres" {...field} />
</FormControl>
<FormDescription>Database user with backup privileges.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="password"
render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl>
<Input type="password" placeholder="••••••••" {...field} />
</FormControl>
<FormDescription>Password for database authentication.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="database"
render={({ field }) => (
<FormItem>
<FormLabel>Database</FormLabel>
<FormControl>
<Input placeholder="myapp_production" {...field} />
</FormControl>
<FormDescription>Name of the database to backup.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="dumpFormat"
defaultValue="custom"
render={({ field }) => (
<FormItem>
<FormLabel>Dump Format</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value || "custom"}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select dump format" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="custom">Custom (Compressed)</SelectItem>
<SelectItem value="plain">Plain SQL</SelectItem>
<SelectItem value="directory">Directory</SelectItem>
</SelectContent>
</Select>
<FormDescription>Format for database dumps (custom recommended).</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</>
)}
{watchedBackend !== "directory" && ( {watchedBackend !== "directory" && (
<div className="space-y-3"> <div className="space-y-3">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">

View File

@@ -4,12 +4,12 @@ import { useId } from "react";
import { useNavigate } from "react-router"; import { useNavigate } from "react-router";
import { toast } from "sonner"; import { toast } from "sonner";
import { createVolumeMutation } from "~/client/api-client/@tanstack/react-query.gen"; import { createVolumeMutation } from "~/client/api-client/@tanstack/react-query.gen";
import { CreateVolumeForm, type FormValues } from "~/client/components/create-volume-form";
import { Button } from "~/client/components/ui/button"; import { Button } from "~/client/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card"; import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card";
import { parseError } from "~/client/lib/errors"; import { parseError } from "~/client/lib/errors";
import type { Route } from "./+types/create-volume"; import type { Route } from "./+types/create-volume";
import { Alert, AlertDescription } from "~/client/components/ui/alert"; import { Alert, AlertDescription } from "~/client/components/ui/alert";
import { CreateVolumeForm, type FormValues } from "../components/create-volume-form";
export const handle = { export const handle = {
breadcrumb: () => [{ label: "Volumes", href: "/volumes" }, { label: "Create" }], breadcrumb: () => [{ label: "Volumes", href: "/volumes" }, { label: "Create" }],

View File

@@ -119,6 +119,8 @@ export default function VolumeDetails({ loaderData }: Route.ComponentProps) {
const { volume, statfs } = data; const { volume, statfs } = data;
const dockerAvailable = capabilities.docker; const dockerAvailable = capabilities.docker;
const isDatabaseVolume = ["mariadb", "mysql", "postgres"].includes(volume.config.backend);
return ( return (
<> <>
<div className="flex flex-col items-start xs:items-center xs:flex-row xs:justify-between"> <div className="flex flex-col items-start xs:items-center xs:flex-row xs:justify-between">
@@ -152,7 +154,9 @@ export default function VolumeDetails({ loaderData }: Route.ComponentProps) {
<Tabs value={activeTab} onValueChange={(value) => setSearchParams({ tab: value })} className="mt-4"> <Tabs value={activeTab} onValueChange={(value) => setSearchParams({ tab: value })} className="mt-4">
<TabsList className="mb-2"> <TabsList className="mb-2">
<TabsTrigger value="info">Configuration</TabsTrigger> <TabsTrigger value="info">Configuration</TabsTrigger>
<TabsTrigger value="files">Files</TabsTrigger> <TabsTrigger disabled={isDatabaseVolume} value="files">
Files
</TabsTrigger>
<Tooltip> <Tooltip>
<TooltipTrigger> <TooltipTrigger>
<TabsTrigger disabled={!dockerAvailable} value="docker"> <TabsTrigger disabled={!dockerAvailable} value="docker">
@@ -167,9 +171,11 @@ export default function VolumeDetails({ loaderData }: Route.ComponentProps) {
<TabsContent value="info"> <TabsContent value="info">
<VolumeInfoTabContent volume={volume} statfs={statfs} /> <VolumeInfoTabContent volume={volume} statfs={statfs} />
</TabsContent> </TabsContent>
{!isDatabaseVolume && (
<TabsContent value="files"> <TabsContent value="files">
<FilesTabContent volume={volume} /> <FilesTabContent volume={volume} />
</TabsContent> </TabsContent>
)}
{dockerAvailable && ( {dockerAvailable && (
<TabsContent value="docker"> <TabsContent value="docker">
<DockerTabContent volume={volume} /> <DockerTabContent volume={volume} />

View File

@@ -109,6 +109,10 @@ export default function Volumes({ loaderData }: Route.ComponentProps) {
<SelectItem value="directory">Directory</SelectItem> <SelectItem value="directory">Directory</SelectItem>
<SelectItem value="nfs">NFS</SelectItem> <SelectItem value="nfs">NFS</SelectItem>
<SelectItem value="smb">SMB</SelectItem> <SelectItem value="smb">SMB</SelectItem>
<SelectItem value="webdav">WebDAV</SelectItem>
<SelectItem value="mariadb">MariaDB</SelectItem>
<SelectItem value="mysql">MySQL</SelectItem>
<SelectItem value="postgres">PostgreSQL</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
{(searchQuery || statusFilter || backendFilter) && ( {(searchQuery || statusFilter || backendFilter) && (

View File

@@ -1,7 +1,6 @@
import { useMutation } from "@tanstack/react-query"; import { useMutation } from "@tanstack/react-query";
import { useState } from "react"; import { useState } from "react";
import { toast } from "sonner"; import { toast } from "sonner";
import { CreateVolumeForm, type FormValues } from "~/client/components/create-volume-form";
import { import {
AlertDialog, AlertDialog,
AlertDialogAction, AlertDialogAction,
@@ -17,6 +16,7 @@ import type { StatFs, Volume } from "~/client/lib/types";
import { HealthchecksCard } from "../components/healthchecks-card"; import { HealthchecksCard } from "../components/healthchecks-card";
import { StorageChart } from "../components/storage-chart"; import { StorageChart } from "../components/storage-chart";
import { updateVolumeMutation } from "~/client/api-client/@tanstack/react-query.gen"; import { updateVolumeMutation } from "~/client/api-client/@tanstack/react-query.gen";
import { CreateVolumeForm, type FormValues } from "../components/create-volume-form";
type Props = { type Props = {
volume: Volume; volume: Volume;

View File

@@ -11,13 +11,19 @@ export const REPOSITORY_BACKENDS = {
export type RepositoryBackend = keyof typeof REPOSITORY_BACKENDS; export type RepositoryBackend = keyof typeof REPOSITORY_BACKENDS;
// Common fields for all repository configs
const baseRepositoryConfigSchema = type({
isExistingRepository: "boolean?",
customPassword: "string?",
});
export const s3RepositoryConfigSchema = type({ export const s3RepositoryConfigSchema = type({
backend: "'s3'", backend: "'s3'",
endpoint: "string", endpoint: "string",
bucket: "string", bucket: "string",
accessKeyId: "string", accessKeyId: "string",
secretAccessKey: "string", secretAccessKey: "string",
}); }).and(baseRepositoryConfigSchema);
export const r2RepositoryConfigSchema = type({ export const r2RepositoryConfigSchema = type({
backend: "'r2'", backend: "'r2'",
@@ -25,19 +31,19 @@ export const r2RepositoryConfigSchema = type({
bucket: "string", bucket: "string",
accessKeyId: "string", accessKeyId: "string",
secretAccessKey: "string", secretAccessKey: "string",
}); }).and(baseRepositoryConfigSchema);
export const localRepositoryConfigSchema = type({ export const localRepositoryConfigSchema = type({
backend: "'local'", backend: "'local'",
name: "string", name: "string",
}); }).and(baseRepositoryConfigSchema);
export const gcsRepositoryConfigSchema = type({ export const gcsRepositoryConfigSchema = type({
backend: "'gcs'", backend: "'gcs'",
bucket: "string", bucket: "string",
projectId: "string", projectId: "string",
credentialsJson: "string", credentialsJson: "string",
}); }).and(baseRepositoryConfigSchema);
export const azureRepositoryConfigSchema = type({ export const azureRepositoryConfigSchema = type({
backend: "'azure'", backend: "'azure'",
@@ -45,13 +51,13 @@ export const azureRepositoryConfigSchema = type({
accountName: "string", accountName: "string",
accountKey: "string", accountKey: "string",
endpointSuffix: "string?", endpointSuffix: "string?",
}); }).and(baseRepositoryConfigSchema);
export const rcloneRepositoryConfigSchema = type({ export const rcloneRepositoryConfigSchema = type({
backend: "'rclone'", backend: "'rclone'",
remote: "string", remote: "string",
path: "string", path: "string",
}); }).and(baseRepositoryConfigSchema);
export const repositoryConfigSchema = s3RepositoryConfigSchema export const repositoryConfigSchema = s3RepositoryConfigSchema
.or(r2RepositoryConfigSchema) .or(r2RepositoryConfigSchema)

View File

@@ -5,6 +5,9 @@ export const BACKEND_TYPES = {
smb: "smb", smb: "smb",
directory: "directory", directory: "directory",
webdav: "webdav", webdav: "webdav",
mariadb: "mariadb",
mysql: "mysql",
postgres: "postgres",
} as const; } as const;
export type BackendType = keyof typeof BACKEND_TYPES; export type BackendType = keyof typeof BACKEND_TYPES;
@@ -47,7 +50,47 @@ export const webdavConfigSchema = type({
ssl: "boolean?", ssl: "boolean?",
}); });
export const volumeConfigSchema = nfsConfigSchema.or(smbConfigSchema).or(webdavConfigSchema).or(directoryConfigSchema); export const mariadbConfigSchema = type({
backend: "'mariadb'",
host: "string",
port: type("string.integer").or(type("number")).to("1 <= number <= 65535").default(3306),
username: "string",
password: "string",
database: "string",
dumpOptions: "string[]?",
readOnly: "false?",
});
export const mysqlConfigSchema = type({
backend: "'mysql'",
host: "string",
port: type("string.integer").or(type("number")).to("1 <= number <= 65535").default(3306),
username: "string",
password: "string",
database: "string",
dumpOptions: "string[]?",
readOnly: "false?",
});
export const postgresConfigSchema = type({
backend: "'postgres'",
host: "string",
port: type("string.integer").or(type("number")).to("1 <= number <= 65535").default(5432),
username: "string",
password: "string",
database: "string",
dumpFormat: type("'plain' | 'custom' | 'directory'").default("custom"),
dumpOptions: "string[]?",
readOnly: "false?",
});
export const volumeConfigSchema = nfsConfigSchema
.or(smbConfigSchema)
.or(webdavConfigSchema)
.or(directoryConfigSchema)
.or(mariadbConfigSchema)
.or(mysqlConfigSchema)
.or(postgresConfigSchema);
export type BackendConfig = typeof volumeConfigSchema.infer; export type BackendConfig = typeof volumeConfigSchema.infer;

View File

@@ -3,7 +3,7 @@ import path from "node:path";
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import { volumeService } from "../modules/volumes/volume.service"; import { volumeService } from "../modules/volumes/volume.service";
import { readMountInfo } from "../utils/mountinfo"; import { readMountInfo } from "../utils/mountinfo";
import { getVolumePath } from "../modules/volumes/helpers"; import { createVolumeBackend } from "../modules/backends/backend";
import { logger } from "../utils/logger"; import { logger } from "../utils/logger";
import { executeUnmount } from "../modules/backends/utils/backend-utils"; import { executeUnmount } from "../modules/backends/utils/backend-utils";
import { toMessage } from "../utils/errors"; import { toMessage } from "../utils/errors";
@@ -16,7 +16,11 @@ export class CleanupDanglingMountsJob extends Job {
for (const mount of allSystemMounts) { for (const mount of allSystemMounts) {
if (mount.mountPoint.includes("ironmount") && mount.mountPoint.endsWith("_data")) { if (mount.mountPoint.includes("ironmount") && mount.mountPoint.endsWith("_data")) {
const matchingVolume = allVolumes.find((v) => getVolumePath(v) === mount.mountPoint); const matchingVolume = allVolumes.find((v) => {
const backend = createVolumeBackend(v);
return backend.getVolumePath() === mount.mountPoint;
});
if (!matchingVolume) { if (!matchingVolume) {
logger.info(`Found dangling mount at ${mount.mountPoint}, attempting to unmount...`); logger.info(`Found dangling mount at ${mount.mountPoint}, attempting to unmount...`);
await executeUnmount(mount.mountPoint).catch((err) => { await executeUnmount(mount.mountPoint).catch((err) => {
@@ -36,7 +40,10 @@ export class CleanupDanglingMountsJob extends Job {
for (const dir of allIronmountDirs) { for (const dir of allIronmountDirs) {
const volumePath = `${VOLUME_MOUNT_BASE}/${dir}/_data`; const volumePath = `${VOLUME_MOUNT_BASE}/${dir}/_data`;
const matchingVolume = allVolumes.find((v) => getVolumePath(v) === volumePath); const matchingVolume = allVolumes.find((v) => {
const backend = createVolumeBackend(v);
return backend.getVolumePath() === volumePath;
});
if (!matchingVolume) { if (!matchingVolume) {
const fullPath = path.join(VOLUME_MOUNT_BASE, dir); const fullPath = path.join(VOLUME_MOUNT_BASE, dir);
logger.info(`Found dangling mount directory at ${fullPath}, attempting to remove...`); logger.info(`Found dangling mount directory at ${fullPath}, attempting to remove...`);

View File

@@ -1,10 +1,12 @@
import type { BackendStatus } from "~/schemas/volumes"; import type { BackendStatus } from "~/schemas/volumes";
import type { Volume } from "../../db/schema"; import type { Volume } from "../../db/schema";
import { getVolumePath } from "../volumes/helpers";
import { makeDirectoryBackend } from "./directory/directory-backend"; import { makeDirectoryBackend } from "./directory/directory-backend";
import { makeNfsBackend } from "./nfs/nfs-backend"; import { makeNfsBackend } from "./nfs/nfs-backend";
import { makeSmbBackend } from "./smb/smb-backend"; import { makeSmbBackend } from "./smb/smb-backend";
import { makeWebdavBackend } from "./webdav/webdav-backend"; import { makeWebdavBackend } from "./webdav/webdav-backend";
import { makeMariaDBBackend } from "./mariadb/mariadb-backend";
import { makeMySQLBackend } from "./mysql/mysql-backend";
import { makePostgresBackend } from "./postgres/postgres-backend";
type OperationResult = { type OperationResult = {
error?: string; error?: string;
@@ -15,23 +17,35 @@ export type VolumeBackend = {
mount: () => Promise<OperationResult>; mount: () => Promise<OperationResult>;
unmount: () => Promise<OperationResult>; unmount: () => Promise<OperationResult>;
checkHealth: () => Promise<OperationResult>; checkHealth: () => Promise<OperationResult>;
getVolumePath: () => string;
getBackupPath: () => Promise<string>;
}; };
export const createVolumeBackend = (volume: Volume): VolumeBackend => { export const createVolumeBackend = (volume: Volume): VolumeBackend => {
const path = getVolumePath(volume);
switch (volume.config.backend) { switch (volume.config.backend) {
case "nfs": { case "nfs": {
return makeNfsBackend(volume.config, path); return makeNfsBackend(volume.config, volume.name);
} }
case "smb": { case "smb": {
return makeSmbBackend(volume.config, path); return makeSmbBackend(volume.config, volume.name);
} }
case "directory": { case "directory": {
return makeDirectoryBackend(volume.config, path); return makeDirectoryBackend(volume.config, volume.name);
} }
case "webdav": { case "webdav": {
return makeWebdavBackend(volume.config, path); return makeWebdavBackend(volume.config, volume.name);
}
case "mariadb": {
return makeMariaDBBackend(volume.config);
}
case "mysql": {
return makeMySQLBackend(volume.config);
}
case "postgres": {
return makePostgresBackend(volume.config);
}
default: {
throw new Error(`Unsupported backend type: ${(volume.config as any).backend}`);
} }
} }
}; };

View File

@@ -52,8 +52,18 @@ const checkHealth = async (config: BackendConfig) => {
} }
}; };
const getVolumePath = (config: BackendConfig): string => {
if (config.backend !== "directory") {
throw new Error("Invalid backend type");
}
return config.path;
};
export const makeDirectoryBackend = (config: BackendConfig, volumePath: string): VolumeBackend => ({ export const makeDirectoryBackend = (config: BackendConfig, volumePath: string): VolumeBackend => ({
mount: () => mount(config, volumePath), mount: () => mount(config, volumePath),
unmount, unmount,
checkHealth: () => checkHealth(config), checkHealth: () => checkHealth(config),
getVolumePath: () => getVolumePath(config),
getBackupPath: async () => getVolumePath(config),
}); });

View File

@@ -0,0 +1,81 @@
import * as fs from "node:fs/promises";
import { toMessage } from "../../../utils/errors";
import { logger } from "../../../utils/logger";
import type { VolumeBackend } from "../backend";
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
import { $ } from "bun";
const checkHealth = async (config: BackendConfig) => {
if (config.backend !== "mariadb") {
return { status: BACKEND_STATUS.error, error: "Invalid backend type" };
}
try {
logger.debug(`Testing MariaDB connection to: ${config.host}:${config.port}`);
const args = [
`--host=${config.host}`,
`--port=${config.port}`,
`--user=${config.username}`,
`--database=${config.database}`,
"--skip-ssl",
"--execute=SELECT 1",
];
const env = {
MYSQL_PWD: config.password,
};
await $`mariadb ${args.join(" ")}`.env(env);
return { status: BACKEND_STATUS.mounted };
} catch (error) {
logger.error("MariaDB health check failed:", error);
return { status: BACKEND_STATUS.error, error: toMessage(error) };
}
};
const getBackupPath = async (config: BackendConfig) => {
const dumpDir = await fs.mkdtemp(`/tmp/ironmount-mariadb-`);
if (config.backend !== "mariadb") {
throw new Error("Invalid backend type for MariaDB dump");
}
logger.info(`Starting MariaDB dump for database: ${config.database}`);
const args = [
`--host=${config.host}`,
`--port=${config.port}`,
`--user=${config.username}`,
`--skip-ssl`,
`--single-transaction`,
`--quick`,
`--lock-tables=false`,
...(config.dumpOptions || []),
config.database,
];
const env = {
MYSQL_PWD: config.password,
};
const result = await $`mariadb-dump ${args}`.env(env).nothrow();
if (result.exitCode !== 0) {
throw new Error(`mariadb-dump failed with exit code ${result.exitCode}: ${result.stderr}`);
}
await fs.writeFile(`${dumpDir}/dump.sql`, result.stdout);
logger.info(`MariaDB dump completed: ${dumpDir}/dump.sql`);
return `${dumpDir}/dump.sql`;
};
export const makeMariaDBBackend = (config: BackendConfig): VolumeBackend => ({
mount: () => Promise.resolve({ status: BACKEND_STATUS.mounted }),
unmount: () => Promise.resolve({ status: BACKEND_STATUS.unmounted }),
checkHealth: () => checkHealth(config),
getVolumePath: () => "/tmp",
getBackupPath: () => getBackupPath(config),
});

View File

@@ -0,0 +1,76 @@
import { toMessage } from "../../../utils/errors";
import { logger } from "../../../utils/logger";
import type { VolumeBackend } from "../backend";
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
import { $ } from "bun";
const checkHealth = async (config: BackendConfig) => {
if (config.backend !== "mysql") {
return { status: BACKEND_STATUS.error, error: "Invalid backend type" };
}
logger.debug(`Testing MySQL connection to: ${config.host}:${config.port}`);
try {
const args = [
`--host=${config.host}`,
`--port=${config.port}`,
`--user=${config.username}`,
`--database=${config.database}`,
"--skip-ssl",
"--execute=SELECT 1",
];
const env = {
...process.env,
MYSQL_PWD: config.password,
};
await $`mysql ${args.join(" ")}`.env(env);
return { status: BACKEND_STATUS.mounted };
} catch (error) {
logger.error("MySQL health check failed:", error);
return { status: BACKEND_STATUS.error, error: toMessage(error) };
}
};
const getBackupPath = async (config: BackendConfig) => {
if (config.backend !== "mysql") {
throw new Error("Invalid backend type");
}
logger.info(`Starting MySQL dump for database: ${config.database}`);
const args = [
`--host=${config.host}`,
`--port=${config.port}`,
`--user=${config.username}`,
`--skip-ssl`,
`--single-transaction`,
`--quick`,
`--lock-tables=false`,
...(config.dumpOptions || []),
config.database,
];
const env = {
MYSQL_PWD: config.password,
};
const result = await $`mysql ${args}`.env(env).nothrow();
if (result.exitCode !== 0) {
throw new Error(`MySQL dump failed: ${result.stderr}`);
}
console.log(result.stdout);
return "Nothing for now";
};
export const makeMySQLBackend = (config: BackendConfig): VolumeBackend => ({
mount: () => Promise.resolve({ status: BACKEND_STATUS.mounted }),
unmount: () => Promise.resolve({ status: BACKEND_STATUS.unmounted }),
checkHealth: () => checkHealth(config),
getVolumePath: () => "/tmp",
getBackupPath: () => getBackupPath(config),
});

View File

@@ -1,6 +1,6 @@
import * as fs from "node:fs/promises"; import * as fs from "node:fs/promises";
import * as os from "node:os"; import * as os from "node:os";
import { OPERATION_TIMEOUT } from "../../../core/constants"; import { OPERATION_TIMEOUT, VOLUME_MOUNT_BASE } from "../../../core/constants";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "../../../utils/logger"; import { logger } from "../../../utils/logger";
import { getMountForPath } from "../../../utils/mountinfo"; import { getMountForPath } from "../../../utils/mountinfo";
@@ -9,7 +9,8 @@ import type { VolumeBackend } from "../backend";
import { createTestFile, executeMount, executeUnmount } from "../utils/backend-utils"; import { createTestFile, executeMount, executeUnmount } from "../utils/backend-utils";
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes"; import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
const mount = async (config: BackendConfig, path: string) => { const mount = async (config: BackendConfig, name: string) => {
const path = getVolumePath(name);
logger.debug(`Mounting volume ${path}...`); logger.debug(`Mounting volume ${path}...`);
if (config.backend !== "nfs") { if (config.backend !== "nfs") {
@@ -22,13 +23,13 @@ const mount = async (config: BackendConfig, path: string) => {
return { status: BACKEND_STATUS.error, error: "NFS mounting is only supported on Linux hosts." }; return { status: BACKEND_STATUS.error, error: "NFS mounting is only supported on Linux hosts." };
} }
const { status } = await checkHealth(path, config.readOnly ?? false); const { status } = await checkHealth(name, config.readOnly ?? false);
if (status === "mounted") { if (status === "mounted") {
return { status: BACKEND_STATUS.mounted }; return { status: BACKEND_STATUS.mounted };
} }
logger.debug(`Trying to unmount any existing mounts at ${path} before mounting...`); logger.debug(`Trying to unmount any existing mounts at ${path} before mounting...`);
await unmount(path); await unmount(name);
const run = async () => { const run = async () => {
await fs.mkdir(path, { recursive: true }); await fs.mkdir(path, { recursive: true });
@@ -57,7 +58,9 @@ const mount = async (config: BackendConfig, path: string) => {
} }
}; };
const unmount = async (path: string) => { const unmount = async (name: string) => {
const path = getVolumePath(name);
if (os.platform() !== "linux") { if (os.platform() !== "linux") {
logger.error("NFS unmounting is only supported on Linux hosts."); logger.error("NFS unmounting is only supported on Linux hosts.");
return { status: BACKEND_STATUS.error, error: "NFS unmounting is only supported on Linux hosts." }; return { status: BACKEND_STATUS.error, error: "NFS unmounting is only supported on Linux hosts." };
@@ -87,7 +90,9 @@ const unmount = async (path: string) => {
} }
}; };
const checkHealth = async (path: string, readOnly: boolean) => { const checkHealth = async (name: string, readOnly: boolean) => {
const path = getVolumePath(name);
const run = async () => { const run = async () => {
logger.debug(`Checking health of NFS volume at ${path}...`); logger.debug(`Checking health of NFS volume at ${path}...`);
await fs.access(path); await fs.access(path);
@@ -114,8 +119,14 @@ const checkHealth = async (path: string, readOnly: boolean) => {
} }
}; };
export const makeNfsBackend = (config: BackendConfig, path: string): VolumeBackend => ({ const getVolumePath = (name: string) => {
mount: () => mount(config, path), return `${VOLUME_MOUNT_BASE}/${name}/_data`;
unmount: () => unmount(path), };
checkHealth: () => checkHealth(path, config.readOnly ?? false),
export const makeNfsBackend = (config: BackendConfig, name: string): VolumeBackend => ({
mount: () => mount(config, name),
unmount: () => unmount(name),
checkHealth: () => checkHealth(name, config.readOnly ?? false),
getVolumePath: () => getVolumePath(name),
getBackupPath: async () => getVolumePath(name),
}); });

View File

@@ -0,0 +1,80 @@
import * as fs from "node:fs/promises";
import { toMessage } from "../../../utils/errors";
import { logger } from "../../../utils/logger";
import type { VolumeBackend } from "../backend";
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
import { $ } from "bun";
const checkHealth = async (config: BackendConfig) => {
if (config.backend !== "postgres") {
return { status: BACKEND_STATUS.error, error: "Invalid backend type" };
}
if (config.backend !== "postgres") {
throw new Error("Invalid backend type for PostgreSQL connection test");
}
logger.debug(`Testing PostgreSQL connection to: ${config.host}:${config.port}`);
const args = [
`--host=${config.host}`,
`--port=${config.port}`,
`--username=${config.username}`,
`--dbname=${config.database}`,
"--command=SELECT 1",
"--no-password",
];
const env = {
PGPASSWORD: config.password,
PGSSLMODE: "disable",
};
logger.debug(`Running psql with args: ${args.join(" ")}`);
const res = await $`psql ${args}`.env(env).nothrow();
if (res.exitCode !== 0) {
return { status: BACKEND_STATUS.error, error: res.stderr.toString() };
}
return { status: BACKEND_STATUS.mounted };
};
const getBackupPath = async (config: BackendConfig) => {
if (config.backend !== "postgres") {
throw new Error("Invalid backend type for PostgreSQL dump");
}
const dumpDir = await fs.mkdtemp(`/tmp/ironmount-postgres-`);
const outputPath = `${dumpDir}/${config.dumpFormat === "plain" ? "dump.sql" : "dump.dump"}`;
logger.info(`Starting PostgreSQL dump for database: ${config.database}`);
const args = [
`--host=${config.host}`,
`--port=${config.port}`,
`--username=${config.username}`,
`--dbname=${config.database}`,
`--format=${config.dumpFormat}`,
`--file=${outputPath}`,
"--no-password",
...(config.dumpOptions || []),
];
const env = {
PGPASSWORD: config.password,
PGSSLMODE: "disable",
};
await $`pg_dump ${args}`.env(env);
return outputPath;
};
export const makePostgresBackend = (config: BackendConfig): VolumeBackend => ({
mount: () => Promise.resolve({ status: "mounted" }),
unmount: () => Promise.resolve({ status: "unmounted" }),
checkHealth: () => checkHealth(config),
getVolumePath: () => "/tmp",
getBackupPath: () => getBackupPath(config),
});

View File

@@ -1,6 +1,6 @@
import * as fs from "node:fs/promises"; import * as fs from "node:fs/promises";
import * as os from "node:os"; import * as os from "node:os";
import { OPERATION_TIMEOUT } from "../../../core/constants"; import { OPERATION_TIMEOUT, VOLUME_MOUNT_BASE } from "../../../core/constants";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "../../../utils/logger"; import { logger } from "../../../utils/logger";
import { getMountForPath } from "../../../utils/mountinfo"; import { getMountForPath } from "../../../utils/mountinfo";
@@ -9,7 +9,8 @@ import type { VolumeBackend } from "../backend";
import { createTestFile, executeMount, executeUnmount } from "../utils/backend-utils"; import { createTestFile, executeMount, executeUnmount } from "../utils/backend-utils";
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes"; import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
const mount = async (config: BackendConfig, path: string) => { const mount = async (config: BackendConfig, name: string) => {
const path = getVolumePath(name);
logger.debug(`Mounting SMB volume ${path}...`); logger.debug(`Mounting SMB volume ${path}...`);
if (config.backend !== "smb") { if (config.backend !== "smb") {
@@ -22,13 +23,13 @@ const mount = async (config: BackendConfig, path: string) => {
return { status: BACKEND_STATUS.error, error: "SMB mounting is only supported on Linux hosts." }; return { status: BACKEND_STATUS.error, error: "SMB mounting is only supported on Linux hosts." };
} }
const { status } = await checkHealth(path, config.readOnly ?? false); const { status } = await checkHealth(name, config.readOnly ?? false);
if (status === "mounted") { if (status === "mounted") {
return { status: BACKEND_STATUS.mounted }; return { status: BACKEND_STATUS.mounted };
} }
logger.debug(`Trying to unmount any existing mounts at ${path} before mounting...`); logger.debug(`Trying to unmount any existing mounts at ${path} before mounting...`);
await unmount(path); await unmount(name);
const run = async () => { const run = async () => {
await fs.mkdir(path, { recursive: true }); await fs.mkdir(path, { recursive: true });
@@ -70,7 +71,9 @@ const mount = async (config: BackendConfig, path: string) => {
} }
}; };
const unmount = async (path: string) => { const unmount = async (name: string) => {
const path = getVolumePath(name);
if (os.platform() !== "linux") { if (os.platform() !== "linux") {
logger.error("SMB unmounting is only supported on Linux hosts."); logger.error("SMB unmounting is only supported on Linux hosts.");
return { status: BACKEND_STATUS.error, error: "SMB unmounting is only supported on Linux hosts." }; return { status: BACKEND_STATUS.error, error: "SMB unmounting is only supported on Linux hosts." };
@@ -100,7 +103,9 @@ const unmount = async (path: string) => {
} }
}; };
const checkHealth = async (path: string, readOnly: boolean) => { const checkHealth = async (name: string, readOnly: boolean) => {
const path = getVolumePath(name);
const run = async () => { const run = async () => {
logger.debug(`Checking health of SMB volume at ${path}...`); logger.debug(`Checking health of SMB volume at ${path}...`);
await fs.access(path); await fs.access(path);
@@ -127,8 +132,14 @@ const checkHealth = async (path: string, readOnly: boolean) => {
} }
}; };
export const makeSmbBackend = (config: BackendConfig, path: string): VolumeBackend => ({ const getVolumePath = (name: string) => {
mount: () => mount(config, path), return `${VOLUME_MOUNT_BASE}/${name}/_data`;
unmount: () => unmount(path), };
checkHealth: () => checkHealth(path, config.readOnly ?? false),
export const makeSmbBackend = (config: BackendConfig, name: string): VolumeBackend => ({
mount: () => mount(config, name),
unmount: () => unmount(name),
checkHealth: () => checkHealth(name, config.readOnly ?? false),
getVolumePath: () => getVolumePath(name),
getBackupPath: async () => getVolumePath(name),
}); });

View File

@@ -2,7 +2,7 @@ import { execFile as execFileCb } from "node:child_process";
import * as fs from "node:fs/promises"; import * as fs from "node:fs/promises";
import * as os from "node:os"; import * as os from "node:os";
import { promisify } from "node:util"; import { promisify } from "node:util";
import { OPERATION_TIMEOUT } from "../../../core/constants"; import { OPERATION_TIMEOUT, VOLUME_MOUNT_BASE } from "../../../core/constants";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "../../../utils/logger"; import { logger } from "../../../utils/logger";
import { getMountForPath } from "../../../utils/mountinfo"; import { getMountForPath } from "../../../utils/mountinfo";
@@ -13,7 +13,8 @@ import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
const execFile = promisify(execFileCb); const execFile = promisify(execFileCb);
const mount = async (config: BackendConfig, path: string) => { const mount = async (config: BackendConfig, name: string) => {
const path = getVolumePath(name);
logger.debug(`Mounting WebDAV volume ${path}...`); logger.debug(`Mounting WebDAV volume ${path}...`);
if (config.backend !== "webdav") { if (config.backend !== "webdav") {
@@ -104,7 +105,8 @@ const mount = async (config: BackendConfig, path: string) => {
} }
}; };
const unmount = async (path: string) => { const unmount = async (name: string) => {
const path = getVolumePath(name);
if (os.platform() !== "linux") { if (os.platform() !== "linux") {
logger.error("WebDAV unmounting is only supported on Linux hosts."); logger.error("WebDAV unmounting is only supported on Linux hosts.");
return { status: BACKEND_STATUS.error, error: "WebDAV unmounting is only supported on Linux hosts." }; return { status: BACKEND_STATUS.error, error: "WebDAV unmounting is only supported on Linux hosts." };
@@ -134,7 +136,9 @@ const unmount = async (path: string) => {
} }
}; };
const checkHealth = async (path: string, readOnly: boolean) => { const checkHealth = async (name: string, readOnly: boolean) => {
const path = getVolumePath(name);
const run = async () => { const run = async () => {
logger.debug(`Checking health of WebDAV volume at ${path}...`); logger.debug(`Checking health of WebDAV volume at ${path}...`);
await fs.access(path); await fs.access(path);
@@ -161,8 +165,14 @@ const checkHealth = async (path: string, readOnly: boolean) => {
} }
}; };
export const makeWebdavBackend = (config: BackendConfig, path: string): VolumeBackend => ({ const getVolumePath = (name: string) => {
mount: () => mount(config, path), return `${VOLUME_MOUNT_BASE}/${name}/_data`;
unmount: () => unmount(path), };
checkHealth: () => checkHealth(path, config.readOnly ?? false),
export const makeWebdavBackend = (config: BackendConfig, name: string): VolumeBackend => ({
mount: () => mount(config, name),
unmount: () => unmount(name),
checkHealth: () => checkHealth(name, config.readOnly ?? false),
getVolumePath: () => getVolumePath(name),
getBackupPath: async () => getVolumePath(name),
}); });

View File

@@ -8,6 +8,7 @@ import {
getBackupScheduleForVolumeDto, getBackupScheduleForVolumeDto,
listBackupSchedulesDto, listBackupSchedulesDto,
runBackupNowDto, runBackupNowDto,
runForgetDto,
stopBackupDto, stopBackupDto,
updateBackupScheduleDto, updateBackupScheduleDto,
updateBackupScheduleBody, updateBackupScheduleBody,
@@ -17,6 +18,7 @@ import {
type GetBackupScheduleForVolumeResponseDto, type GetBackupScheduleForVolumeResponseDto,
type ListBackupSchedulesResponseDto, type ListBackupSchedulesResponseDto,
type RunBackupNowDto, type RunBackupNowDto,
type RunForgetDto,
type StopBackupDto, type StopBackupDto,
type UpdateBackupScheduleDto, type UpdateBackupScheduleDto,
} from "./backups.dto"; } from "./backups.dto";
@@ -78,4 +80,11 @@ export const backupScheduleController = new Hono()
await backupsService.stopBackup(Number(scheduleId)); await backupsService.stopBackup(Number(scheduleId));
return c.json<StopBackupDto>({ success: true }, 200); return c.json<StopBackupDto>({ success: true }, 200);
})
.post("/:scheduleId/forget", runForgetDto, async (c) => {
const scheduleId = c.req.param("scheduleId");
await backupsService.runForget(Number(scheduleId));
return c.json<RunForgetDto>({ success: true }, 200);
}); });

View File

@@ -251,3 +251,28 @@ export const stopBackupDto = describeRoute({
}, },
}, },
}); });
/**
* Run retention policy (forget) manually
*/
export const runForgetResponse = type({
success: "boolean",
});
export type RunForgetDto = typeof runForgetResponse.infer;
export const runForgetDto = describeRoute({
description: "Manually apply retention policy to clean up old snapshots",
operationId: "runForget",
tags: ["Backups"],
responses: {
200: {
description: "Retention policy applied successfully",
content: {
"application/json": {
schema: resolver(runForgetResponse),
},
},
},
},
});

View File

@@ -6,7 +6,7 @@ import { db } from "../../db/db";
import { backupSchedulesTable, repositoriesTable, volumesTable } from "../../db/schema"; import { backupSchedulesTable, repositoriesTable, volumesTable } from "../../db/schema";
import { restic } from "../../utils/restic"; import { restic } from "../../utils/restic";
import { logger } from "../../utils/logger"; import { logger } from "../../utils/logger";
import { getVolumePath } from "../volumes/helpers"; import { createVolumeBackend } from "../backends/backend";
import type { CreateBackupScheduleBody, UpdateBackupScheduleBody } from "./backups.dto"; import type { CreateBackupScheduleBody, UpdateBackupScheduleBody } from "./backups.dto";
import { toMessage } from "../../utils/errors"; import { toMessage } from "../../utils/errors";
import { serverEvents } from "../../core/events"; import { serverEvents } from "../../core/events";
@@ -195,16 +195,19 @@ const executeBackup = async (scheduleId: number, manual = false) => {
repositoryName: repository.name, repositoryName: repository.name,
}); });
const nextBackupAt = calculateNextRun(schedule.cronExpression);
await db await db
.update(backupSchedulesTable) .update(backupSchedulesTable)
.set({ lastBackupStatus: "in_progress", updatedAt: Date.now(), lastBackupError: null }) .set({ lastBackupStatus: "in_progress", updatedAt: Date.now(), lastBackupError: null, nextBackupAt })
.where(eq(backupSchedulesTable.id, scheduleId)); .where(eq(backupSchedulesTable.id, scheduleId));
const abortController = new AbortController(); const abortController = new AbortController();
runningBackups.set(scheduleId, abortController); runningBackups.set(scheduleId, abortController);
try { try {
const volumePath = getVolumePath(volume); const backend = createVolumeBackend(volume);
const backupPath = await backend.getBackupPath();
const backupOptions: { const backupOptions: {
exclude?: string[]; exclude?: string[];
@@ -224,7 +227,7 @@ const executeBackup = async (scheduleId: number, manual = false) => {
backupOptions.include = schedule.includePatterns; backupOptions.include = schedule.includePatterns;
} }
await restic.backup(repository.config, volumePath, { await restic.backup(repository.config, backupPath, {
...backupOptions, ...backupOptions,
onProgress: (progress) => { onProgress: (progress) => {
serverEvents.emit("backup:progress", { serverEvents.emit("backup:progress", {
@@ -340,6 +343,32 @@ const stopBackup = async (scheduleId: number) => {
abortController.abort(); abortController.abort();
}; };
const runForget = async (scheduleId: number) => {
const schedule = await db.query.backupSchedulesTable.findFirst({
where: eq(backupSchedulesTable.id, scheduleId),
});
if (!schedule) {
throw new NotFoundError("Backup schedule not found");
}
if (!schedule.retentionPolicy) {
throw new BadRequestError("No retention policy configured for this schedule");
}
const repository = await db.query.repositoriesTable.findFirst({
where: eq(repositoriesTable.id, schedule.repositoryId),
});
if (!repository) {
throw new NotFoundError("Repository not found");
}
logger.info(`Manually running retention policy (forget) for schedule ${scheduleId}`);
await restic.forget(repository.config, schedule.retentionPolicy, { tag: schedule.id.toString() });
logger.info(`Retention policy applied successfully for schedule ${scheduleId}`);
};
export const backupsService = { export const backupsService = {
listSchedules, listSchedules,
getSchedule, getSchedule,
@@ -350,4 +379,5 @@ export const backupsService = {
getSchedulesToExecute, getSchedulesToExecute,
getScheduleForVolume, getScheduleForVolume,
stopBackup, stopBackup,
runForget,
}; };

View File

@@ -1,6 +1,6 @@
import { Hono } from "hono"; import { Hono } from "hono";
import { volumeService } from "../volumes/volume.service"; import { volumeService } from "../volumes/volume.service";
import { getVolumePath } from "../volumes/helpers"; import { createVolumeBackend } from "../backends/backend";
export const driverController = new Hono() export const driverController = new Hono()
.post("/VolumeDriver.Capabilities", (c) => { .post("/VolumeDriver.Capabilities", (c) => {
@@ -31,9 +31,11 @@ export const driverController = new Hono()
} }
const volumeName = body.Name.replace(/^im-/, ""); const volumeName = body.Name.replace(/^im-/, "");
const { volume } = await volumeService.getVolume(volumeName);
const backend = createVolumeBackend(volume);
return c.json({ return c.json({
Mountpoint: getVolumePath(volumeName), Mountpoint: backend.getVolumePath(),
}); });
}) })
.post("/VolumeDriver.Unmount", (c) => { .post("/VolumeDriver.Unmount", (c) => {
@@ -49,9 +51,10 @@ export const driverController = new Hono()
} }
const { volume } = await volumeService.getVolume(body.Name.replace(/^im-/, "")); const { volume } = await volumeService.getVolume(body.Name.replace(/^im-/, ""));
const backend = createVolumeBackend(volume);
return c.json({ return c.json({
Mountpoint: getVolumePath(volume), Mountpoint: backend.getVolumePath(),
}); });
}) })
.post("/VolumeDriver.Get", async (c) => { .post("/VolumeDriver.Get", async (c) => {
@@ -62,11 +65,12 @@ export const driverController = new Hono()
} }
const { volume } = await volumeService.getVolume(body.Name.replace(/^im-/, "")); const { volume } = await volumeService.getVolume(body.Name.replace(/^im-/, ""));
const backend = createVolumeBackend(volume);
return c.json({ return c.json({
Volume: { Volume: {
Name: `im-${volume.name}`, Name: `im-${volume.name}`,
Mountpoint: getVolumePath(volume), Mountpoint: backend.getVolumePath(),
Status: {}, Status: {},
}, },
Err: "", Err: "",
@@ -75,11 +79,16 @@ export const driverController = new Hono()
.post("/VolumeDriver.List", async (c) => { .post("/VolumeDriver.List", async (c) => {
const volumes = await volumeService.listVolumes(); const volumes = await volumeService.listVolumes();
const res = volumes.map((volume) => ({ let res = [];
for (const volume of volumes) {
const backend = createVolumeBackend(volume);
res.push({
Name: `im-${volume.name}`, Name: `im-${volume.name}`,
Mountpoint: getVolumePath(volume), Mountpoint: backend.getVolumePath(),
Status: {}, Status: {},
})); });
}
return c.json({ return c.json({
Volumes: res, Volumes: res,

View File

@@ -7,7 +7,6 @@ import { repositoriesTable } from "../../db/schema";
import { toMessage } from "../../utils/errors"; import { toMessage } from "../../utils/errors";
import { restic } from "../../utils/restic"; import { restic } from "../../utils/restic";
import { cryptoUtils } from "../../utils/crypto"; import { cryptoUtils } from "../../utils/crypto";
import { logger } from "../../utils/logger";
import type { CompressionMode, RepositoryConfig } from "~/schemas/restic"; import type { CompressionMode, RepositoryConfig } from "~/schemas/restic";
const listRepositories = async () => { const listRepositories = async () => {
@@ -16,7 +15,11 @@ const listRepositories = async () => {
}; };
const encryptConfig = async (config: RepositoryConfig): Promise<RepositoryConfig> => { const encryptConfig = async (config: RepositoryConfig): Promise<RepositoryConfig> => {
const encryptedConfig: Record<string, string> = { ...config }; const encryptedConfig: Record<string, string | boolean> = { ...config };
if (config.customPassword) {
encryptedConfig.customPassword = await cryptoUtils.encrypt(config.customPassword);
}
switch (config.backend) { switch (config.backend) {
case "s3": case "s3":
@@ -66,23 +69,30 @@ const createRepository = async (name: string, config: RepositoryConfig, compress
throw new InternalServerError("Failed to create repository"); throw new InternalServerError("Failed to create repository");
} }
const { success, error } = await restic.init(encryptedConfig); let error: string | null = null;
if (success) { if (config.isExistingRepository) {
const result = await restic
.snapshots(encryptedConfig)
.then(() => ({ error: null }))
.catch((error) => ({ error }));
error = result.error;
} else {
const initResult = await restic.init(encryptedConfig);
error = initResult.error;
}
if (!error) {
await db await db
.update(repositoriesTable) .update(repositoriesTable)
.set({ .set({ status: "healthy", lastChecked: Date.now(), lastError: null })
status: "healthy",
lastChecked: Date.now(),
lastError: null,
})
.where(eq(repositoriesTable.id, id)); .where(eq(repositoriesTable.id, id));
return { repository: created, status: 201 }; return { repository: created, status: 201 };
} }
const errorMessage = toMessage(error); const errorMessage = toMessage(error);
await db.delete(repositoriesTable).where(eq(repositoriesTable.id, id)); await db.delete(repositoriesTable).where(eq(repositoriesTable.id, id));
throw new InternalServerError(`Failed to initialize repository: ${errorMessage}`); throw new InternalServerError(`Failed to initialize repository: ${errorMessage}`);

View File

@@ -1,10 +0,0 @@
import { VOLUME_MOUNT_BASE } from "../../core/constants";
import type { Volume } from "../../db/schema";
export const getVolumePath = (volume: Volume) => {
if (volume.config.backend === "directory") {
return volume.config.path;
}
return `${VOLUME_MOUNT_BASE}/${volume.name}/_data`;
};

View File

@@ -25,7 +25,7 @@ import {
type BrowseFilesystemDto, type BrowseFilesystemDto,
} from "./volume.dto"; } from "./volume.dto";
import { volumeService } from "./volume.service"; import { volumeService } from "./volume.service";
import { getVolumePath } from "./helpers"; import { createVolumeBackend } from "../backends/backend";
export const volumeController = new Hono() export const volumeController = new Hono()
.get("/", listVolumesDto, async (c) => { .get("/", listVolumesDto, async (c) => {
@@ -37,9 +37,10 @@ export const volumeController = new Hono()
const body = c.req.valid("json"); const body = c.req.valid("json");
const res = await volumeService.createVolume(body.name, body.config); const res = await volumeService.createVolume(body.name, body.config);
const backend = createVolumeBackend(res.volume);
const response = { const response = {
...res.volume, ...res.volume,
path: getVolumePath(res.volume), path: backend.getVolumePath(),
}; };
return c.json<CreateVolumeDto>(response, 201); return c.json<CreateVolumeDto>(response, 201);
@@ -60,10 +61,11 @@ export const volumeController = new Hono()
const { name } = c.req.param(); const { name } = c.req.param();
const res = await volumeService.getVolume(name); const res = await volumeService.getVolume(name);
const backend = createVolumeBackend(res.volume);
const response = { const response = {
volume: { volume: {
...res.volume, ...res.volume,
path: getVolumePath(res.volume), path: backend.getVolumePath(),
}, },
statfs: { statfs: {
total: res.statfs.total ?? 0, total: res.statfs.total ?? 0,
@@ -85,9 +87,10 @@ export const volumeController = new Hono()
const body = c.req.valid("json"); const body = c.req.valid("json");
const res = await volumeService.updateVolume(name, body); const res = await volumeService.updateVolume(name, body);
const backend = createVolumeBackend(res.volume);
const response = { const response = {
...res.volume, ...res.volume,
path: getVolumePath(res.volume), path: backend.getVolumePath(),
}; };
return c.json<UpdateVolumeDto>(response, 200); return c.json<UpdateVolumeDto>(response, 200);

View File

@@ -13,7 +13,6 @@ import { getStatFs, type StatFs } from "../../utils/mountinfo";
import { withTimeout } from "../../utils/timeout"; import { withTimeout } from "../../utils/timeout";
import { createVolumeBackend } from "../backends/backend"; import { createVolumeBackend } from "../backends/backend";
import type { UpdateVolumeBody } from "./volume.dto"; import type { UpdateVolumeBody } from "./volume.dto";
import { getVolumePath } from "./helpers";
import { logger } from "../../utils/logger"; import { logger } from "../../utils/logger";
import { serverEvents } from "../../core/events"; import { serverEvents } from "../../core/events";
import type { BackendConfig } from "~/schemas/volumes"; import type { BackendConfig } from "~/schemas/volumes";
@@ -129,7 +128,9 @@ const getVolume = async (name: string) => {
let statfs: Partial<StatFs> = {}; let statfs: Partial<StatFs> = {};
if (volume.status === "mounted") { if (volume.status === "mounted") {
statfs = await withTimeout(getStatFs(getVolumePath(volume)), 1000, "getStatFs").catch((error) => { const backend = createVolumeBackend(volume);
const volumePath = backend.getVolumePath();
statfs = await withTimeout(getStatFs(volumePath), 1000, "getStatFs").catch((error) => {
logger.warn(`Failed to get statfs for volume ${name}: ${toMessage(error)}`); logger.warn(`Failed to get statfs for volume ${name}: ${toMessage(error)}`);
return {}; return {};
}); });
@@ -203,7 +204,16 @@ const testConnection = async (backendConfig: BackendConfig) => {
}; };
const backend = createVolumeBackend(mockVolume); const backend = createVolumeBackend(mockVolume);
const { error } = await backend.mount(); let error: string | null = null;
const mount = await backend.mount();
if (mount.error) {
error = mount.error;
} else {
const health = await backend.checkHealth();
if (health.error) {
error = health.error;
}
}
await backend.unmount(); await backend.unmount();
@@ -295,8 +305,8 @@ const listFiles = async (name: string, subPath?: string) => {
throw new InternalServerError("Volume is not mounted"); throw new InternalServerError("Volume is not mounted");
} }
// For directory volumes, use the configured path directly const backend = createVolumeBackend(volume);
const volumePath = getVolumePath(volume); const volumePath = backend.getVolumePath();
const requestedPath = subPath ? path.join(volumePath, subPath) : volumePath; const requestedPath = subPath ? path.join(volumePath, subPath) : volumePath;

View File

@@ -75,7 +75,7 @@ const buildRepoUrl = (config: RepositoryConfig): string => {
case "s3": case "s3":
return `s3:${config.endpoint}/${config.bucket}`; return `s3:${config.endpoint}/${config.bucket}`;
case "r2": { case "r2": {
const endpoint = config.endpoint.replace(/^https?:\/\//, ''); const endpoint = config.endpoint.replace(/^https?:\/\//, "");
return `s3:${endpoint}/${config.bucket}`; return `s3:${endpoint}/${config.bucket}`;
} }
case "gcs": case "gcs":
@@ -93,10 +93,19 @@ const buildRepoUrl = (config: RepositoryConfig): string => {
const buildEnv = async (config: RepositoryConfig) => { const buildEnv = async (config: RepositoryConfig) => {
const env: Record<string, string> = { const env: Record<string, string> = {
RESTIC_CACHE_DIR: "/var/lib/ironmount/restic/cache", RESTIC_CACHE_DIR: "/var/lib/ironmount/restic/cache",
RESTIC_PASSWORD_FILE: RESTIC_PASS_FILE,
PATH: process.env.PATH || "/usr/local/bin:/usr/bin:/bin", PATH: process.env.PATH || "/usr/local/bin:/usr/bin:/bin",
}; };
if (config.isExistingRepository && config.customPassword) {
const decryptedPassword = await cryptoUtils.decrypt(config.customPassword);
const passwordFilePath = path.join("/tmp", `ironmount-pass-${crypto.randomBytes(8).toString("hex")}.txt`);
await fs.writeFile(passwordFilePath, decryptedPassword, { mode: 0o600 });
env.RESTIC_PASSWORD_FILE = passwordFilePath;
} else {
env.RESTIC_PASSWORD_FILE = RESTIC_PASS_FILE;
}
switch (config.backend) { switch (config.backend) {
case "s3": case "s3":
env.AWS_ACCESS_KEY_ID = await cryptoUtils.decrypt(config.accessKeyId); env.AWS_ACCESS_KEY_ID = await cryptoUtils.decrypt(config.accessKeyId);
@@ -110,7 +119,7 @@ const buildEnv = async (config: RepositoryConfig) => {
break; break;
case "gcs": { case "gcs": {
const decryptedCredentials = await cryptoUtils.decrypt(config.credentialsJson); const decryptedCredentials = await cryptoUtils.decrypt(config.credentialsJson);
const credentialsPath = path.join("/tmp", `gcs-credentials-${crypto.randomBytes(8).toString("hex")}.json`); const credentialsPath = path.join("/tmp", `ironmount-gcs-${crypto.randomBytes(8).toString("hex")}.json`);
await fs.writeFile(credentialsPath, decryptedCredentials, { mode: 0o600 }); await fs.writeFile(credentialsPath, decryptedCredentials, { mode: 0o600 });
env.GOOGLE_PROJECT_ID = config.projectId; env.GOOGLE_PROJECT_ID = config.projectId;
env.GOOGLE_APPLICATION_CREDENTIALS = credentialsPath; env.GOOGLE_APPLICATION_CREDENTIALS = credentialsPath;
@@ -139,7 +148,7 @@ const init = async (config: RepositoryConfig) => {
if (res.exitCode !== 0) { if (res.exitCode !== 0) {
logger.error(`Restic init failed: ${res.stderr}`); logger.error(`Restic init failed: ${res.stderr}`);
return { success: false, error: res.stderr }; return { success: false, error: res.stderr.toString() };
} }
logger.info(`Restic repository initialized: ${repoUrl}`); logger.info(`Restic repository initialized: ${repoUrl}`);

View File

@@ -3,6 +3,10 @@
* This removes passwords and credentials from logs and error messages * This removes passwords and credentials from logs and error messages
*/ */
export const sanitizeSensitiveData = (text: string): string => { export const sanitizeSensitiveData = (text: string): string => {
if (process.env.NODE_ENV === "development") {
return text;
}
let sanitized = text.replace(/\b(pass|password)=([^\s,]+)/gi, "$1=***"); let sanitized = text.replace(/\b(pass|password)=([^\s,]+)/gi, "$1=***");
sanitized = sanitized.replace(/\/\/([^:@\s]+):([^@\s]+)@/g, "//$1:***@"); sanitized = sanitized.replace(/\/\/([^:@\s]+):([^@\s]+)@/g, "//$1:***@");

View File

@@ -5,6 +5,8 @@ interface Params {
args: string[]; args: string[];
env?: NodeJS.ProcessEnv; env?: NodeJS.ProcessEnv;
signal?: AbortSignal; signal?: AbortSignal;
stdin?: string;
timeout?: number;
onStdout?: (data: string) => void; onStdout?: (data: string) => void;
onStderr?: (error: string) => void; onStderr?: (error: string) => void;
onError?: (error: Error) => Promise<void> | void; onError?: (error: Error) => Promise<void> | void;
@@ -19,17 +21,26 @@ type SpawnResult = {
}; };
export const safeSpawn = (params: Params) => { export const safeSpawn = (params: Params) => {
const { command, args, env = {}, signal, ...callbacks } = params; const { command, args, env = {}, signal, stdin, timeout, ...callbacks } = params;
return new Promise<SpawnResult>((resolve) => { return new Promise<SpawnResult>((resolve, reject) => {
let stdoutData = ""; let stdoutData = "";
let stderrData = ""; let stderrData = "";
let timeoutId: NodeJS.Timeout | undefined;
const child = spawn(command, args, { const child = spawn(command, args, {
env: { ...process.env, ...env }, env: { ...process.env, ...env },
signal: signal, signal: signal,
}); });
// Handle timeout if specified
if (timeout) {
timeoutId = setTimeout(() => {
child.kill("SIGTERM");
reject(new Error(`Command timed out after ${timeout}ms`));
}, timeout);
}
child.stdout.on("data", (data) => { child.stdout.on("data", (data) => {
if (callbacks.onStdout) { if (callbacks.onStdout) {
callbacks.onStdout(data.toString()); callbacks.onStdout(data.toString());
@@ -47,6 +58,7 @@ export const safeSpawn = (params: Params) => {
}); });
child.on("error", async (error) => { child.on("error", async (error) => {
if (timeoutId) clearTimeout(timeoutId);
if (callbacks.onError) { if (callbacks.onError) {
await callbacks.onError(error); await callbacks.onError(error);
} }
@@ -62,6 +74,7 @@ export const safeSpawn = (params: Params) => {
}); });
child.on("close", async (code) => { child.on("close", async (code) => {
if (timeoutId) clearTimeout(timeoutId);
if (callbacks.onClose) { if (callbacks.onClose) {
await callbacks.onClose(code); await callbacks.onClose(code);
} }
@@ -69,11 +82,15 @@ export const safeSpawn = (params: Params) => {
await callbacks.finally(); await callbacks.finally();
} }
if (code !== 0 && code !== null) {
reject(new Error(`Command failed with exit code ${code}: ${stderrData || stdoutData}`));
} else {
resolve({ resolve({
exitCode: code === null ? -1 : code, exitCode: code === null ? -1 : code,
stdout: stdoutData, stdout: stdoutData,
stderr: stderrData, stderr: stderrData,
}); });
}
}); });
}); });
}; };