Section 31 point 2: format deleteHistory.ts for prettier
This commit is contained in:
1 parent
8183be0da5
commit
55f76d0991
1 file changed
+24
-12
@@ -5,17 +5,23 @@ import { dataMountpoint, imageId, volumeId } from '../utils'
|
|||||||
const { InputSpec, Value } = sdk
|
const { InputSpec, Value } = sdk
|
||||||
|
|
||||||
// The history cannot be recovered once it is gone, so the action takes a
|
// The history cannot be recovered once it is gone, so the action takes a
|
||||||
// confirmation box, and the handler refuses to run without it (section 31
|
// confirmation box and the handler refuses to run without it (section 31
|
||||||
// point 2). A toggle has no `required` flag, so the confirmation is enforced in
|
// point 2). A toggle has no `required` flag, so the confirmation is enforced
|
||||||
// the handler.
|
// in the handler.
|
||||||
const inputSpec = InputSpec.of({
|
const inputSpec = InputSpec.of({
|
||||||
confirm: Value.toggle({
|
confirm: Value.toggle({
|
||||||
name: i18n('I confirm that the stored history will be deleted and cannot be recovered'),
|
name: i18n(
|
||||||
|
'I confirm that the stored history will be deleted and cannot be recovered',
|
||||||
|
),
|
||||||
description: null,
|
description: null,
|
||||||
default: false,
|
default: false,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const confirmationRequired = i18n(
|
||||||
|
'The confirmation is required before the history can be deleted.',
|
||||||
|
)
|
||||||
|
|
||||||
export const deleteHistory = sdk.Action.withInput(
|
export const deleteHistory = sdk.Action.withInput(
|
||||||
// ID
|
// ID
|
||||||
'delete-history',
|
'delete-history',
|
||||||
@@ -23,7 +29,9 @@ export const deleteHistory = sdk.Action.withInput(
|
|||||||
// Metadata
|
// Metadata
|
||||||
async () => ({
|
async () => ({
|
||||||
name: i18n('Delete history'),
|
name: i18n('Delete history'),
|
||||||
description: i18n('Delete every saved health check, with the follow-up it closed. The key setup and the wallet software list are kept.'),
|
description: i18n(
|
||||||
|
'Delete every saved health check, with the follow-up it closed. The key setup and the wallet software list are kept.',
|
||||||
|
),
|
||||||
warning: null,
|
warning: null,
|
||||||
allowedStatuses: 'any',
|
allowedStatuses: 'any',
|
||||||
group: null,
|
group: null,
|
||||||
@@ -38,13 +46,13 @@ export const deleteHistory = sdk.Action.withInput(
|
|||||||
// Handler
|
// Handler
|
||||||
async ({ effects, input }) => {
|
async ({ effects, input }) => {
|
||||||
if (!input.confirm) {
|
if (!input.confirm) {
|
||||||
throw new Error(i18n('The confirmation is required before the history can be deleted.'))
|
throw new Error(confirmationRequired)
|
||||||
}
|
}
|
||||||
|
|
||||||
// maintenance.py needs the volume and nothing else: the image's own
|
// maintenance.py needs the volume and nothing else: the image's own
|
||||||
// DATABASE_PATH already points at /data/vardkey.sqlite3, which is where the
|
// DATABASE_PATH already points at /data/vardkey.sqlite3, which is where
|
||||||
// volume is mounted. A temporary subcontainer is used because the command
|
// the volume is mounted. A temporary subcontainer is used, because the
|
||||||
// is a one-off, not a daemon.
|
// command is a one-off and not a daemon.
|
||||||
const mounts = sdk.Mounts.of().mountVolume({
|
const mounts = sdk.Mounts.of().mountVolume({
|
||||||
volumeId,
|
volumeId,
|
||||||
subpath: null,
|
subpath: null,
|
||||||
@@ -59,10 +67,14 @@ export const deleteHistory = sdk.Action.withInput(
|
|||||||
mounts,
|
mounts,
|
||||||
'delete-history',
|
'delete-history',
|
||||||
async (sub) => {
|
async (sub) => {
|
||||||
const result = await sub.exec(['python3', 'maintenance.py', 'delete-history'])
|
const result = await sub.exec([
|
||||||
|
'python3',
|
||||||
|
'maintenance.py',
|
||||||
|
'delete-history',
|
||||||
|
])
|
||||||
if (result.exitCode !== 0) {
|
if (result.exitCode !== 0) {
|
||||||
// exec() returns stdout/stderr as either text or bytes, so both are
|
// exec() reports stdout and stderr as either text or bytes, so both
|
||||||
// normalised before they are used.
|
// are normalised before they are used.
|
||||||
const stderr = String(result.stderr).trim()
|
const stderr = String(result.stderr).trim()
|
||||||
throw new Error(stderr || i18n('The history could not be deleted.'))
|
throw new Error(stderr || i18n('The history could not be deleted.'))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user