This commit is contained in:
sharevb 2024-08-07 14:11:28 +02:00 committed by GitHub
commit 3feb8bb16b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 848 additions and 14 deletions

2
components.d.ts vendored
View File

@ -143,6 +143,7 @@ declare module '@vue/runtime-core' {
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NP: typeof import('naive-ui')['NP']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSpin: typeof import('naive-ui')['NSpin']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
@ -178,6 +179,7 @@ declare module '@vue/runtime-core' {
TomlToYaml: typeof import('./src/tools/toml-to-yaml/toml-to-yaml.vue')['default']
'Tool.layout': typeof import('./src/layouts/tool.layout.vue')['default']
ToolCard: typeof import('./src/components/ToolCard.vue')['default']
TorrentToMagnet: typeof import('./src/tools/torrent-to-magnet/torrent-to-magnet.vue')['default']
UlidGenerator: typeof import('./src/tools/ulid-generator/ulid-generator.vue')['default']
UrlEncoder: typeof import('./src/tools/url-encoder/url-encoder.vue')['default']
UrlParser: typeof import('./src/tools/url-parser/url-parser.vue')['default']

View File

@ -77,6 +77,7 @@
"netmask": "^2.0.2",
"node-forge": "^1.3.1",
"oui-data": "^1.0.10",
"parse-torrent": "^11.0.17",
"pdf-signature-reader": "^1.4.2",
"pinia": "^2.0.34",
"plausible-tracker": "^0.3.8",
@ -132,6 +133,7 @@
"unplugin-icons": "^0.17.0",
"unplugin-vue-components": "^0.25.0",
"vite": "^4.4.9",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-plugin-pwa": "^0.16.0",
"vite-plugin-vue-markdown": "^0.23.5",
"vite-svg-loader": "^4.0.0",

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as torrentToMagnet } from './torrent-to-magnet';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@ -128,6 +129,7 @@ export const toolsByCategory: ToolCategory[] = [
httpStatusCodes,
jsonDiff,
safelinkDecoder,
torrentToMagnet,
],
},
{

View File

@ -0,0 +1,12 @@
import { Bookmarks } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Torrent to Magnet',
path: '/torrent-to-magnet',
description: 'Convert a torrent file to a Magnet url',
keywords: ['torrent', 'magnet', 'url', 'link'],
component: () => import('./torrent-to-magnet.vue'),
icon: Bookmarks,
createdAt: new Date('2024-04-20'),
});

View File

@ -0,0 +1,4 @@
declare module 'parse-torrent'{
export default function parseTorrent(content: string | ArrayBufferView): Promise<object>;
export function toMagnetURI(parsedTorrent: object): string;
}

View File

@ -0,0 +1,101 @@
<script setup lang="ts">
import type { Ref } from 'vue';
import parseTorrent, { toMagnetURI } from 'parse-torrent';
import { withDefaultOnError } from '@/utils/defaults';
import { useValidation } from '@/composable/validation';
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) {
return await parseTorrent(new Uint8Array(await file.arrayBuffer()));
}
else {
return await parseTorrent(content);
}
}
catch (e: any) {
return {
error: e.toString(),
};
}
});
const torrentInfos = computed(() => withDefaultOnError(() => {
return Object.entries(torrentInfosRaw.value).map(([k, v]) => {
return {
label: k?.toString() || '',
value: JSON.stringify(v),
};
});
}, []));
const magnetURI = computed(() => withDefaultOnError(() => toMagnetURI(torrentInfosRaw.value), []));
async function onUpload(file: File) {
if (file) {
fileInput.value = file;
}
}
watch(torrentContent, (_, newValue) => {
if (newValue !== '') {
fileInput.value = null;
}
});
const { attrs: validationAttrs } = useValidation({
source: torrentInfos,
rules: [{ message: 'Invalid torrent content', validator: torrent => torrent?.length > 0 }],
});
</script>
<template>
<div>
<c-file-upload
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-model:value="torrentContent"
label="Torrent/Magnet Content"
placeholder="Paste your Torrent/Magnet content here"
multiline
mb-2
/>
<n-divider />
<input-copyable
label="Magnet URI"
label-position="left"
label-width="100px"
label-align="right"
mb-2
:value="validationAttrs.validationStatus === 'error' ? '' : magnetURI"
placeholder="Please use a correct torrent"
/>
<input-copyable
v-for="{ label, value } of torrentInfos"
:key="label"
:label="label"
label-position="left"
label-width="100px"
label-align="right"
mb-2
:value="validationAttrs.validationStatus === 'error' ? '' : value"
placeholder="Please use a correct torrent"
/>
</div>
</template>
<style lang="less" scoped>
::v-deep(.n-upload-trigger) {
width: 100%;
}
</style>

View File

@ -15,6 +15,7 @@ import { VitePWA } from 'vite-plugin-pwa';
import markdown from 'vite-plugin-vue-markdown';
import svgLoader from 'vite-svg-loader';
import { configDefaults } from 'vitest/config';
import { nodePolyfills } from 'vite-plugin-node-polyfills'
const baseUrl = process.env.BASE_URL ?? '/';
@ -97,6 +98,7 @@ export default defineConfig({
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
}),
Unocss(),
nodePolyfills(),
],
base: baseUrl,
resolve: {