mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
refactor: use schema constants
This commit is contained in:
@@ -47,7 +47,7 @@ export type Session = typeof sessionsTable.$inferSelect;
|
||||
export const repositoriesTable = sqliteTable("repositories_table", {
|
||||
id: text().primaryKey(),
|
||||
name: text().notNull().unique(),
|
||||
backend: text().$type<RepositoryBackend>().notNull(),
|
||||
type: text().$type<RepositoryBackend>().notNull(),
|
||||
config: text("config", { mode: "json" }).$type<typeof repositoryConfigSchema.inferOut>().notNull(),
|
||||
compressionMode: text("compression_mode").$type<CompressionMode>().default("auto"),
|
||||
status: text().$type<RepositoryStatus>().default("unknown"),
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import { repositoryConfigSchema } from "@ironmount/schemas/restic";
|
||||
import {
|
||||
COMPRESSION_MODES,
|
||||
REPOSITORY_BACKENDS,
|
||||
REPOSITORY_STATUS,
|
||||
repositoryConfigSchema,
|
||||
} from "@ironmount/schemas/restic";
|
||||
import { type } from "arktype";
|
||||
import { describeRoute, resolver } from "hono-openapi";
|
||||
|
||||
const repositorySchema = type({
|
||||
id: "string",
|
||||
name: "string",
|
||||
backend: type.enumerated("local", "sftp", "s3"),
|
||||
type: type.valueOf(REPOSITORY_BACKENDS),
|
||||
config: repositoryConfigSchema,
|
||||
compressionMode: type.enumerated("off", "auto", "fastest", "better", "max").or("null"),
|
||||
status: type.enumerated("healthy", "error", "unknown").or("null"),
|
||||
compressionMode: type.valueOf(COMPRESSION_MODES).or("null"),
|
||||
status: type.valueOf(REPOSITORY_STATUS).or("null"),
|
||||
lastChecked: "number | null",
|
||||
lastError: "string | null",
|
||||
createdAt: "number",
|
||||
@@ -46,8 +51,8 @@ export const listRepositoriesDto = describeRoute({
|
||||
*/
|
||||
export const createRepositoryBody = type({
|
||||
name: "string",
|
||||
compressionMode: type.valueOf(COMPRESSION_MODES).optional(),
|
||||
config: repositoryConfigSchema,
|
||||
"compressionMode?": type.enumerated("off", "auto", "fastest", "better", "max"),
|
||||
});
|
||||
|
||||
export type CreateRepositoryBody = typeof createRepositoryBody.infer;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import crypto from "node:crypto";
|
||||
import type { CompressionMode, RepositoryConfig } from "@ironmount/schemas";
|
||||
import type { CompressionMode, RepositoryConfig } from "@ironmount/schemas/restic";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { ConflictError, InternalServerError, NotFoundError } from "http-errors-enhanced";
|
||||
import slugify from "slugify";
|
||||
@@ -15,14 +15,16 @@ const listRepositories = async () => {
|
||||
};
|
||||
|
||||
const encryptConfig = async (config: RepositoryConfig): Promise<RepositoryConfig> => {
|
||||
const encryptedConfig = { ...config };
|
||||
const encryptedConfig: Record<string, string> = { ...config };
|
||||
|
||||
switch (config.backend) {
|
||||
case "s3":
|
||||
encryptedConfig.accessKeyId = await cryptoUtils.encrypt(config.accessKeyId);
|
||||
encryptedConfig.secretAccessKey = await cryptoUtils.encrypt(config.secretAccessKey);
|
||||
break;
|
||||
}
|
||||
return encryptedConfig;
|
||||
|
||||
return encryptedConfig as RepositoryConfig;
|
||||
};
|
||||
|
||||
const createRepository = async (name: string, config: RepositoryConfig, compressionMode?: CompressionMode) => {
|
||||
@@ -45,7 +47,7 @@ const createRepository = async (name: string, config: RepositoryConfig, compress
|
||||
.values({
|
||||
id,
|
||||
name: slug,
|
||||
backend: config.backend,
|
||||
type: config.backend,
|
||||
config: encryptedConfig,
|
||||
compressionMode: compressionMode ?? "auto",
|
||||
status: "unknown",
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { volumeConfigSchema } from "@ironmount/schemas";
|
||||
import { BACKEND_STATUS, BACKEND_TYPES, volumeConfigSchema } from "@ironmount/schemas";
|
||||
import { type } from "arktype";
|
||||
import { describeRoute, resolver } from "hono-openapi";
|
||||
|
||||
const volumeSchema = type({
|
||||
name: "string",
|
||||
path: "string",
|
||||
type: type.enumerated("nfs", "smb", "directory", "webdav"),
|
||||
status: type.enumerated("mounted", "unmounted", "error", "unknown"),
|
||||
type: type.valueOf(BACKEND_TYPES),
|
||||
status: type.valueOf(BACKEND_STATUS),
|
||||
lastError: "string | null",
|
||||
createdAt: "number",
|
||||
updatedAt: "number",
|
||||
@@ -199,7 +199,7 @@ export const testConnectionDto = describeRoute({
|
||||
*/
|
||||
export const mountVolumeResponse = type({
|
||||
error: "string?",
|
||||
status: type.enumerated("mounted", "unmounted", "error"),
|
||||
status: type.valueOf(BACKEND_STATUS),
|
||||
});
|
||||
|
||||
export const mountVolumeDto = describeRoute({
|
||||
@@ -226,7 +226,7 @@ export const mountVolumeDto = describeRoute({
|
||||
*/
|
||||
export const unmountVolumeResponse = type({
|
||||
error: "string?",
|
||||
status: type.enumerated("mounted", "unmounted", "error"),
|
||||
status: type.valueOf(BACKEND_STATUS),
|
||||
});
|
||||
|
||||
export const unmountVolumeDto = describeRoute({
|
||||
@@ -250,7 +250,7 @@ export const unmountVolumeDto = describeRoute({
|
||||
|
||||
export const healthCheckResponse = type({
|
||||
error: "string?",
|
||||
status: type.enumerated("mounted", "unmounted", "error"),
|
||||
status: type.valueOf(BACKEND_STATUS),
|
||||
});
|
||||
|
||||
export const healthCheckDto = describeRoute({
|
||||
|
||||
Reference in New Issue
Block a user