Skip to content

Commit 6c71882

Browse files
committed
fix: better ui to select file or paste content
1 parent 6d0b6c5 commit 6c71882

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/tools/certificate-key-parser/certificate-key-parser.vue

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
88
const inputKeyOrCertificate = ref('');
99
const passphrase = ref('');
1010
const fileInput = ref() as Ref<Buffer>;
11+
const inputType = ref<'file' | 'content'>('file');
1112
1213
async function onUpload(file: File) {
1314
if (file) {
@@ -37,11 +38,15 @@ function downloadX509DERFile() {
3738
}
3839
3940
const parsedSections = computedAsync<LabelValue[]>(async () => {
40-
const inputKeyOrCertificateValue
41-
= inputKeyOrCertificate.value !== ''
42-
? inputKeyOrCertificate.value
43-
: fileInput.value;
44-
41+
const inputContent = inputKeyOrCertificate.value;
42+
const file = fileInput.value;
43+
let inputKeyOrCertificateValue: string | Buffer = '';
44+
if (inputType.value === 'file' && file) {
45+
inputKeyOrCertificateValue = file;
46+
}
47+
else if (inputType.value === 'content' && inputContent) {
48+
inputKeyOrCertificateValue = inputContent;
49+
}
4550
const { values, certificateX509DER: certPEM } = await getKeyOrCertificateInfosAsync(inputKeyOrCertificateValue, passphrase.value);
4651
certificateX509DER.value = certPEM || '';
4752
return values;
@@ -51,16 +56,27 @@ const parsedSections = computedAsync<LabelValue[]>(async () => {
5156
<template>
5257
<div>
5358
<c-card>
54-
<c-file-upload title="Drag and drop a Certificate file here, or click to select a Certificate file" @file-upload="onUpload" />
55-
<!-- separator -->
56-
<div my-4 w-full flex items-center justify-center op-70>
57-
<div class="h-1px max-w-100px flex-1 bg-gray-300 op-50" />
58-
<div class="mx-2 text-gray-400">
59-
or
60-
</div>
61-
<div class="h-1px max-w-100px flex-1 bg-gray-300 op-50" />
62-
</div>
59+
<n-radio-group v-model:value="inputType" name="radiogroup" mb-2 flex justify-center>
60+
<n-space>
61+
<n-radio
62+
value="file"
63+
label="File"
64+
/>
65+
<n-radio
66+
value="content"
67+
label="Content"
68+
/>
69+
</n-space>
70+
</n-radio-group>
71+
72+
<c-file-upload
73+
v-if="inputType === 'file'"
74+
title="Drag and drop a Certificate file here, or click to select a Certificate file"
75+
@file-upload="onUpload"
76+
/>
77+
6378
<c-input-text
79+
v-if="inputType === 'content'"
6480
v-model:value="inputKeyOrCertificate"
6581
label="Paste your Public Key / Private Key / Signature / Fingerprint / Certificate:"
6682
placeholder="Your Public Key / Private Key / Signature / Fingerprint / Certificate..."

0 commit comments

Comments
 (0)