@futo-org/backups-orchestrator-ui 1.16.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/components/backups/dialogs/CancelJobModal.svelte +1 -1
  2. package/dist/components/backups/metrics-history/MetricsHistoryModal.svelte +8 -0
  3. package/dist/components/integrations/immich/ImmichManageBackupOverview.svelte +9 -6
  4. package/dist/components/integrations/immich/ImmichOnboardingSetupFlow.svelte +22 -12
  5. package/dist/components/integrations/immich/settings/ImmichSettingsBackupContents.svelte +1 -1
  6. package/dist/components/integrations/immich/settings/ImmichSettingsSchedule.svelte +14 -85
  7. package/dist/components/integrations/immich/settings/ImmichSettingsStorage.svelte +1 -1
  8. package/dist/components/onboarding/steps/OnboardingStep4FirstBackup.svelte +42 -2
  9. package/dist/components/onboarding/steps/OnboardingStep4FirstBackup.svelte.d.ts +4 -1
  10. package/dist/components/onboarding/steps/OnboardingStepBetaDisclaimer.svelte +1 -1
  11. package/dist/components/schedules/ScheduleEditor.svelte +326 -0
  12. package/dist/components/schedules/ScheduleEditor.svelte.d.ts +7 -0
  13. package/dist/components/schedules/ScheduleList.svelte +1 -1
  14. package/dist/components/schedules/dialogs/ConfigureScheduleModal.svelte +5 -22
  15. package/dist/components/schedules/dialogs/CreateScheduleModal.svelte +6 -23
  16. package/dist/fetch-client.d.ts +8 -0
  17. package/dist/locales/en-XA.js +1 -1
  18. package/dist/locales/en-XA.po +148 -24
  19. package/dist/locales/en.js +1 -1
  20. package/dist/locales/en.po +149 -25
  21. package/dist/services/immich.integration.service.js +2 -1
  22. package/dist/services/integrations.service.d.ts +1 -1
  23. package/dist/services/integrations.service.js +1 -1
  24. package/dist/services/schedule.service.d.ts +1 -1
  25. package/dist/services/schedule.service.js +14 -6
  26. package/dist/services/snapshot.service.js +2 -2
  27. package/dist/utils/cron.d.ts +15 -0
  28. package/dist/utils/cron.js +42 -0
  29. package/package.json +3 -3
@@ -0,0 +1,326 @@
1
+ <script lang="ts">
2
+ import { useSchedules } from "../../services/schedule.service";
3
+ import {
4
+ describeSchedule,
5
+ formatTime,
6
+ isValidCron,
7
+ resolveCron,
8
+ runsMoreThanHourly,
9
+ toDefaultWindow,
10
+ toSchedulePreset,
11
+ type SchedulePreset,
12
+ } from "../../utils/cron";
13
+ import { CronTime } from "cron";
14
+ import { DateTime } from "luxon";
15
+ import {
16
+ Button,
17
+ Field,
18
+ HelperText,
19
+ HStack,
20
+ Input,
21
+ LoadingSpinner,
22
+ Select,
23
+ Stack,
24
+ Text,
25
+ } from "@immich/ui";
26
+ import { msg, t } from "svelte-i18n-lingui";
27
+
28
+ type Props = {
29
+ cron: string;
30
+ disabled?: boolean;
31
+ };
32
+
33
+ let {
34
+ cron = $bindable(),
35
+ disabled = false,
36
+ }: Props = $props();
37
+
38
+ const frequencies = [
39
+ { value: "daily", label: msg`Daily` },
40
+ { value: "weekly", label: msg`Weekly` },
41
+ { value: "monthly", label: msg`Monthly` },
42
+ { value: "custom", label: msg`Custom` },
43
+ ] as const;
44
+ const weekdays = [
45
+ msg`Sunday`,
46
+ msg`Monday`,
47
+ msg`Tuesday`,
48
+ msg`Wednesday`,
49
+ msg`Thursday`,
50
+ msg`Friday`,
51
+ msg`Saturday`,
52
+ ];
53
+ const monthDays = Array.from({ length: 31 }, (_, index) => ({
54
+ value: String(index + 1),
55
+ label: String(index + 1),
56
+ }));
57
+ const isNumber = (field: string | undefined) => /^\d+$/.test(field ?? "");
58
+
59
+ const schedules = useSchedules();
60
+ const nextRunsId = $props.id();
61
+ let editingCustom = $state(false);
62
+
63
+ const preset = $derived(toSchedulePreset(cron));
64
+ const effectiveCron = $derived(resolveCron(cron, schedules.data?.defaults));
65
+ const fields = $derived(effectiveCron.trim().split(/\s+/));
66
+ const pattern = $derived.by((): SchedulePreset | undefined => {
67
+ const [minute, hour, day, month, weekday] = fields;
68
+ if (fields.length !== 5 || !isNumber(minute) || !isNumber(hour) || month !== "*") {
69
+ return undefined;
70
+ }
71
+
72
+ if (day === "*") {
73
+ return weekday === "*" ? "daily" : isNumber(weekday) ? "weekly" : undefined;
74
+ }
75
+
76
+ return isNumber(day) && weekday === "*" ? "monthly" : undefined;
77
+ });
78
+ const frequency = $derived(
79
+ editingCustom ? "custom" : (preset ?? pattern ?? "custom"),
80
+ );
81
+ const cronInvalid = $derived(!isValidCron(cron));
82
+ const tz = $derived(schedules.data?.tz);
83
+ const nextRuns = $derived.by(() => {
84
+ if (cronInvalid || !tz) {
85
+ return [];
86
+ }
87
+
88
+ let from: DateTime<boolean> = DateTime.now().setZone(tz);
89
+ if (!from.isValid) {
90
+ return undefined;
91
+ }
92
+
93
+ const time = new CronTime(effectiveCron, tz);
94
+ const runs: DateTime<boolean>[] = [];
95
+ while (runs.length < 3) {
96
+ try {
97
+ from = time.getNextDateFrom(from);
98
+ } catch {
99
+ break;
100
+ }
101
+
102
+ runs.push(from);
103
+ }
104
+
105
+ return runs;
106
+ });
107
+ const inLocalTz = $derived(tz === DateTime.local().zoneName);
108
+ const runFormat = $derived(
109
+ inLocalTz
110
+ ? DateTime.DATETIME_MED_WITH_WEEKDAY
111
+ : { ...DateTime.DATETIME_MED_WITH_WEEKDAY, timeZoneName: "short" as const },
112
+ );
113
+ const defaultExpression = $derived(
114
+ frequency === "custom" ? undefined : schedules.data?.defaults[frequency],
115
+ );
116
+ const dayOptions = $derived.by(() => {
117
+ const options =
118
+ frequency === "weekly"
119
+ ? weekdays.map((label, index) => ({
120
+ value: String(index),
121
+ label: $t(label),
122
+ }))
123
+ : monthDays;
124
+ const defaultDay =
125
+ defaultExpression?.split(" ")[frequency === "weekly" ? 4 : 2];
126
+ return options.flatMap((option) =>
127
+ option.value === defaultDay
128
+ ? [
129
+ option,
130
+ {
131
+ value: "default",
132
+ label: $t({
133
+ message: "{day} (at default time)",
134
+ values: { day: option.label },
135
+ }),
136
+ },
137
+ ]
138
+ : [option],
139
+ );
140
+ });
141
+ const startTime = $derived(`${Number(fields[1])}:${Number(fields[0])}`);
142
+ const defaultStartTime = $derived.by(() => {
143
+ const [minute, hour] = defaultExpression?.split(" ") ?? [];
144
+ return defaultExpression ? `${Number(hour)}:${Number(minute)}` : undefined;
145
+ });
146
+ const defaultWindow = $derived(
147
+ defaultExpression ? toDefaultWindow(defaultExpression) : undefined,
148
+ );
149
+ const startTimes = $derived(
150
+ [
151
+ ...new Set([
152
+ ...Array.from({ length: 24 }, (_, hour) => `${hour}:0`),
153
+ startTime,
154
+ ...(frequency === "daily" && defaultStartTime
155
+ ? [defaultStartTime]
156
+ : []),
157
+ ]),
158
+ ]
159
+ .map((time) => time.split(":").map(Number))
160
+ .toSorted(([a = 0, b = 0], [c = 0, d = 0]) => a * 60 + b - (c * 60 + d))
161
+ .flatMap(([hour = 0, minute = 0]) => {
162
+ const value = `${hour}:${minute}`;
163
+ const options =
164
+ minute === 0 || (!preset && value === startTime)
165
+ ? [{ value, label: formatTime(hour, minute) }]
166
+ : [];
167
+ if (
168
+ frequency === "daily" &&
169
+ value === defaultStartTime &&
170
+ defaultWindow
171
+ ) {
172
+ options.push({
173
+ value: "default",
174
+ label: $t({
175
+ message: "Between {start} and {end} (default)",
176
+ values: defaultWindow,
177
+ }),
178
+ });
179
+ }
180
+
181
+ return options;
182
+ }),
183
+ );
184
+
185
+ const setFields = (changes: Record<number, string>) => {
186
+ cron = fields.map((field, index) => changes[index] ?? field).join(" ");
187
+ };
188
+ </script>
189
+
190
+ <Field label={$t`Frequency`} disabled={disabled || schedules.isLoading || schedules.isError}>
191
+ <Select
192
+ options={frequencies.map((option) => ({
193
+ ...option,
194
+ label: $t(option.label),
195
+ }))}
196
+ value={frequency}
197
+ onChange={(value) => {
198
+ editingCustom = value === "custom";
199
+ cron = value === "custom" ? effectiveCron : `@${value}`;
200
+ }}
201
+ />
202
+ </Field>
203
+
204
+ {#if !schedules.data}
205
+ {#if schedules.isError}
206
+ <Text size="small" color="danger">{$t`Failed to load default schedule`}</Text>
207
+ {:else}
208
+ <LoadingSpinner />
209
+ {/if}
210
+ {:else if frequency === "custom"}
211
+ <Field
212
+ label={$t`Schedule`}
213
+ description={$t`Uses cron syntax`}
214
+ invalid={cronInvalid}
215
+ {disabled}
216
+ >
217
+ <Input bind:value={cron} />
218
+ {#if cronInvalid}
219
+ <HelperText color="danger"
220
+ >{$t`Enter a valid cron expression, for example 0 3 * * *`}</HelperText
221
+ >
222
+ {:else if runsMoreThanHourly(cron)}
223
+ <HelperText color="warning"
224
+ >{$t`This schedule runs more than once an hour. A * in the minute field runs a backup every minute.`}</HelperText
225
+ >
226
+ {/if}
227
+ </Field>
228
+ {:else}
229
+ {#if frequency === "weekly" || frequency === "monthly"}
230
+ <Field
231
+ label={frequency === "weekly" ? $t`Day of week` : $t`Day of month`}
232
+ {disabled}
233
+ >
234
+ <Select
235
+ options={dayOptions}
236
+ value={preset
237
+ ? "default"
238
+ : frequency === "weekly"
239
+ ? String(Number(fields[4]) % 7)
240
+ : String(Number(fields[2]))}
241
+ onChange={(value) => {
242
+ if (value === "default") {
243
+ cron = `@${frequency}`;
244
+ return;
245
+ }
246
+
247
+ setFields({
248
+ 0: preset ? "0" : fields[0],
249
+ [frequency === "weekly" ? 4 : 2]: value,
250
+ });
251
+ }}
252
+ />
253
+ </Field>
254
+ {/if}
255
+
256
+ {#if frequency === "daily" || !preset}
257
+ <Field label={$t`Start time`} {disabled}>
258
+ <Select
259
+ options={startTimes}
260
+ value={preset ? "default" : startTime}
261
+ onChange={(value) => {
262
+ if (value === "default") {
263
+ cron = "@daily";
264
+ return;
265
+ }
266
+
267
+ const [hour = "0", minute = "0"] = value.split(":");
268
+ setFields({ 0: minute, 1: hour });
269
+ }}
270
+ />
271
+ </Field>
272
+ {/if}
273
+ {/if}
274
+
275
+ {#if schedules.data && !cronInvalid}
276
+ <HStack gap={2} class="items-center justify-between">
277
+ <Text size="small" color="muted">
278
+ {$t`Backups will run`}
279
+ {describeSchedule(cron, schedules.data.defaults, schedules.data.tz)}.
280
+ {#if frequency === "monthly" && Number(fields[2]) > 28}
281
+ {$t`Days 29, 30 and 31 only run in months that have that day.`}
282
+ {/if}
283
+ </Text>
284
+ {#if frequency !== "custom" && !preset}
285
+ <Button
286
+ size="small"
287
+ shape="round"
288
+ variant="outline"
289
+ class="shrink-0"
290
+ {disabled}
291
+ onclick={() => (cron = `@${frequency}`)}>{$t`Use default`}</Button
292
+ >
293
+ {/if}
294
+ </HStack>
295
+
296
+ {#if !preset && tz}
297
+ <Stack gap={1}>
298
+ <Text id={nextRunsId} size="small" color="muted" fontWeight="bold"
299
+ >{$t`Next runs`}</Text
300
+ >
301
+ {#if nextRuns === undefined}
302
+ <Text size="small" color="muted"
303
+ >{$t({
304
+ message:
305
+ "Run times can't be shown because this browser doesn't recognise the {tz} time zone.",
306
+ values: { tz },
307
+ })}</Text
308
+ >
309
+ {:else if nextRuns.length === 0}
310
+ <Text size="small" color="warning"
311
+ >{$t`This schedule never runs. Check the day and month.`}</Text
312
+ >
313
+ {:else}
314
+ <ul aria-labelledby={nextRunsId}>
315
+ {#each nextRuns as run (run.toMillis())}
316
+ <li>
317
+ <Text size="small" color="muted"
318
+ >{run.toLocal().toLocaleString(runFormat)}</Text
319
+ >
320
+ </li>
321
+ {/each}
322
+ </ul>
323
+ {/if}
324
+ </Stack>
325
+ {/if}
326
+ {/if}
@@ -0,0 +1,7 @@
1
+ type Props = {
2
+ cron: string;
3
+ disabled?: boolean;
4
+ };
5
+ declare const ScheduleEditor: import("svelte").Component<Props, {}, "cron">;
6
+ type ScheduleEditor = ReturnType<typeof ScheduleEditor>;
7
+ export default ScheduleEditor;
@@ -38,7 +38,7 @@
38
38
  {#snippet title()}{$t`Schedules`}{/snippet}
39
39
 
40
40
  <Suspense query={schedulesQuery}>
41
- {#snippet children(schedules)}
41
+ {#snippet children({ schedules })}
42
42
  {#each schedules as schedule (schedule.id)}
43
43
  <ScheduleItem {schedule} {repositoryNames} />
44
44
  {/each}
@@ -1,9 +1,9 @@
1
1
  <script lang="ts">
2
2
  import type { ScheduleDto } from "../../../fetch-client";
3
3
  import { useUpdateSchedule } from "../../../services/schedule.service";
4
- import { runsMoreThanHourly } from "../../../utils/cron";
5
- import { Field, FormModal, HelperText, Input, Stack } from "@immich/ui";
6
- import validate from "cron-validate";
4
+ import { isValidCron } from "../../../utils/cron";
5
+ import { Field, FormModal, Input, Stack } from "@immich/ui";
6
+ import ScheduleEditor from "../ScheduleEditor.svelte";
7
7
  import RepositoryPicker from "../RepositoryPicker.svelte";
8
8
  import { t } from "svelte-i18n-lingui";
9
9
 
@@ -21,8 +21,6 @@
21
21
  // svelte-ignore state_referenced_locally
22
22
  let repositories = $state([...schedule.repositories]);
23
23
 
24
- const cronInvalid = $derived(validate(cron).isError());
25
-
26
24
  const mutation = useUpdateSchedule();
27
25
 
28
26
  const onSubmit = () =>
@@ -36,7 +34,7 @@
36
34
  title={$t({ message: "Edit {name}", values: { name: schedule.name } })}
37
35
  size="large"
38
36
  disabled={name.length === 0 ||
39
- cronInvalid ||
37
+ !isValidCron(cron) ||
40
38
  repositories.length === 0 ||
41
39
  mutation.isPending}
42
40
  {onSubmit}
@@ -46,22 +44,7 @@
46
44
  <Field label={$t`Name`}>
47
45
  <Input bind:value={name} />
48
46
  </Field>
49
- <Field
50
- label={$t`Schedule`}
51
- description={$t`Uses cron syntax`}
52
- invalid={cronInvalid}
53
- >
54
- <Input bind:value={cron} />
55
- {#if cronInvalid}
56
- <HelperText color="danger"
57
- >{$t`Enter a valid cron expression, for example 0 3 * * *`}</HelperText
58
- >
59
- {:else if runsMoreThanHourly(cron)}
60
- <HelperText color="warning"
61
- >{$t`This schedule runs more than once an hour. A * in the minute field runs a backup every minute.`}</HelperText
62
- >
63
- {/if}
64
- </Field>
47
+ <ScheduleEditor bind:cron />
65
48
 
66
49
  <RepositoryPicker bind:repositories />
67
50
  </Stack>
@@ -1,8 +1,8 @@
1
1
  <script lang="ts">
2
2
  import { useCreateSchedule } from "../../../services/schedule.service";
3
- import { runsMoreThanHourly } from "../../../utils/cron";
4
- import { Field, FormModal, HelperText, Input, Stack } from "@immich/ui";
5
- import validate from "cron-validate";
3
+ import { isValidCron } from "../../../utils/cron";
4
+ import { Field, FormModal, Input, Stack } from "@immich/ui";
5
+ import ScheduleEditor from "../ScheduleEditor.svelte";
6
6
  import RepositoryPicker from "../RepositoryPicker.svelte";
7
7
  import { t } from "svelte-i18n-lingui";
8
8
 
@@ -13,11 +13,9 @@
13
13
  const { onClose }: Props = $props();
14
14
 
15
15
  let name = $state("");
16
- let cron = $state("0 3 * * *");
16
+ let cron = $state("@daily");
17
17
  let repositories = $state<string[]>([]);
18
18
 
19
- const cronInvalid = $derived(validate(cron).isError());
20
-
21
19
  const mutation = useCreateSchedule();
22
20
 
23
21
  const onSubmit = () =>
@@ -31,7 +29,7 @@
31
29
  title={$t`Create A New Schedule`}
32
30
  size="large"
33
31
  disabled={name.length === 0 ||
34
- cronInvalid ||
32
+ !isValidCron(cron) ||
35
33
  repositories.length === 0 ||
36
34
  mutation.isPending}
37
35
  {onSubmit}
@@ -44,22 +42,7 @@
44
42
  >
45
43
  <Input bind:value={name} />
46
44
  </Field>
47
- <Field
48
- label={$t`Schedule`}
49
- description={$t`Uses cron syntax`}
50
- invalid={cronInvalid}
51
- >
52
- <Input bind:value={cron} />
53
- {#if cronInvalid}
54
- <HelperText color="danger"
55
- >{$t`Enter a valid cron expression, for example 0 3 * * *`}</HelperText
56
- >
57
- {:else if runsMoreThanHourly(cron)}
58
- <HelperText color="warning"
59
- >{$t`This schedule runs more than once an hour. A * in the minute field runs a backup every minute.`}</HelperText
60
- >
61
- {/if}
62
- </Field>
45
+ <ScheduleEditor bind:cron />
63
46
 
64
47
  <RepositoryPicker bind:repositories />
65
48
  </Stack>
@@ -252,6 +252,7 @@ export type ImmichBackupStatusDto = {
252
252
  latestBackupJob?: JobDto;
253
253
  databaseDump?: ImmichDatabaseDumpConfigDto;
254
254
  databaseDumpWarningIgnored?: boolean;
255
+ databaseDumpWarningEnabled?: boolean;
255
256
  resticAvailable: boolean;
256
257
  };
257
258
  export type ConfigureImmichIntegrationRequestDto = {
@@ -391,8 +392,15 @@ export type ScheduleCreateRequestDto = {
391
392
  export type ScheduleCreateResponseDto = {
392
393
  schedule: ScheduleDto;
393
394
  };
395
+ export type ScheduleDefaultsDto = {
396
+ daily: string;
397
+ weekly: string;
398
+ monthly: string;
399
+ };
394
400
  export type ScheduleListResponseDto = {
395
401
  schedules: ScheduleDto[];
402
+ defaults: ScheduleDefaultsDto;
403
+ tz: string;
396
404
  };
397
405
  export type ScheduleUpdateRequestDto = {
398
406
  name?: string;