chore: PR feedbacks
This commit is contained in:
parent
78d16fc403
commit
2651407beb
4 changed files with 11 additions and 10 deletions
|
|
@ -14,7 +14,7 @@ import { restic } from "~/server/utils/restic";
|
||||||
import { NotFoundError, BadRequestError } from "http-errors-enhanced";
|
import { NotFoundError, BadRequestError } from "http-errors-enhanced";
|
||||||
|
|
||||||
const resticBackupMock = mock(() => Promise.resolve({ exitCode: 0, summary: generateBackupOutput(), error: "" }));
|
const resticBackupMock = mock(() => Promise.resolve({ exitCode: 0, summary: generateBackupOutput(), error: "" }));
|
||||||
const resticForgetMock = mock(() => Promise.resolve({ success: true }));
|
const resticForgetMock = mock(() => Promise.resolve({ success: true, data: null }));
|
||||||
const resticCopyMock = mock(() => Promise.resolve({ success: true, output: "" }));
|
const resticCopyMock = mock(() => Promise.resolve({ success: true, output: "" }));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ const backupMock = mock(() => Promise.resolve({ exitCode: 0, result: JSON.parse(
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
backupMock.mockClear();
|
backupMock.mockClear();
|
||||||
spyOn(restic, "backup").mockImplementation(backupMock);
|
spyOn(restic, "backup").mockImplementation(backupMock);
|
||||||
spyOn(restic, "forget").mockImplementation(mock(() => Promise.resolve({ success: true })));
|
spyOn(restic, "forget").mockImplementation(mock(() => Promise.resolve({ success: true, data: null })));
|
||||||
spyOn(context, "getOrganizationId").mockReturnValue(TEST_ORG_ID);
|
spyOn(context, "getOrganizationId").mockReturnValue(TEST_ORG_ID);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -629,7 +629,7 @@ const getRetentionCategories = async (repositoryId: string, scheduleId?: string)
|
||||||
}
|
}
|
||||||
|
|
||||||
const categories = parseRetentionCategories(dryRunResults.data);
|
const categories = parseRetentionCategories(dryRunResults.data);
|
||||||
cache.set(cacheKey, categories);
|
cache.set(cacheKey, Object.fromEntries(categories));
|
||||||
|
|
||||||
return categories;
|
return categories;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { safeSpawn, exec } from "./spawn";
|
||||||
import type { CompressionMode, RepositoryConfig, OverwriteMode, BandwidthLimit } from "~/schemas/restic";
|
import type { CompressionMode, RepositoryConfig, OverwriteMode, BandwidthLimit } from "~/schemas/restic";
|
||||||
import { ResticError } from "./errors";
|
import { ResticError } from "./errors";
|
||||||
import { db } from "../db/db";
|
import { db } from "../db/db";
|
||||||
|
import { safeJsonParse } from "./json";
|
||||||
|
|
||||||
const backupOutputSchema = type({
|
const backupOutputSchema = type({
|
||||||
message_type: "'summary'",
|
message_type: "'summary'",
|
||||||
|
|
@ -565,17 +566,17 @@ export interface ForgetGroup {
|
||||||
|
|
||||||
export interface Snapshot {
|
export interface Snapshot {
|
||||||
time: string;
|
time: string;
|
||||||
parent: string;
|
parent?: string;
|
||||||
tree: string;
|
tree: string;
|
||||||
paths: string[];
|
paths: string[];
|
||||||
hostname: string;
|
hostname: string;
|
||||||
username: string;
|
username?: string;
|
||||||
uid: number;
|
uid?: number;
|
||||||
gid: number;
|
gid?: number;
|
||||||
excludes?: string[] | null;
|
excludes?: string[] | null;
|
||||||
tags?: string[] | null;
|
tags?: string[] | null;
|
||||||
program_version: string;
|
program_version?: string;
|
||||||
summary: SnapshotSummary;
|
summary?: SnapshotSummary;
|
||||||
id: string;
|
id: string;
|
||||||
short_id: string;
|
short_id: string;
|
||||||
}
|
}
|
||||||
|
|
@ -653,7 +654,7 @@ const forget = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
const lines = res.stdout.split("\n").filter((line) => line.trim());
|
const lines = res.stdout.split("\n").filter((line) => line.trim());
|
||||||
const result = extra.dryRun ? (JSON.parse(lines.at(-1) ?? "[]") as ResticForgetResponse) : null;
|
const result = extra.dryRun ? safeJsonParse<ResticForgetResponse>(lines.at(-1) ?? "[]") : null;
|
||||||
|
|
||||||
return { success: true, data: result };
|
return { success: true, data: result };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue