fix: better select between file and content

This commit is contained in:
ShareVB 2024-08-25 22:17:54 +02:00
parent 3f44fec8be
commit 099ecc8242
2 changed files with 21 additions and 3 deletions

4
components.d.ts vendored
View file

@ -144,8 +144,12 @@ declare module '@vue/runtime-core' {
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NP: typeof import('naive-ui')['NP']
NRadio: typeof import('naive-ui')['NRadio']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NStatistic: typeof import('naive-ui')['NStatistic']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']

View file

@ -4,13 +4,14 @@ import parseTorrent, { toMagnetURI } from 'parse-torrent';
import { withDefaultOnError } from '@/utils/defaults';
import { useValidation } from '@/composable/validation';
const inputType = ref<'file' | 'content'>('file');
const torrentContent = ref('');
const fileInput = ref() as Ref<File | null>;
const torrentInfosRaw = computedAsync(async () => {
const file = fileInput.value;
const content = torrentContent.value;
try {
if (file) {
if (inputType.value === 'file' && file) {
return await parseTorrent(new Uint8Array(await file.arrayBuffer()));
}
else {
@ -53,14 +54,27 @@ const { attrs: validationAttrs } = useValidation({
<template>
<div>
<n-radio-group v-model:value="inputType" name="radiogroup" mb-2 flex justify-center>
<n-space>
<n-radio
value="file"
label="File"
/>
<n-radio
value="content"
label="Content"
/>
</n-space>
</n-radio-group>
<c-file-upload
v-if="inputType === 'file'"
title="Drag and drop torrent file here, or click to select a file"
@file-upload="onUpload"
/>
<n-p text-center>OR</n-p>
<c-input-text
v-if="inputType === 'content'"
v-model:value="torrentContent"
label="Torrent/Magnet Content"
placeholder="Paste your Torrent/Magnet content here"