Skip to content

Commit 16a5e6b

Browse files
committed
Merge branch 'feat/file-type' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts # vite.config.ts
2 parents 32e30c5 + 7c12c12 commit 16a5e6b

File tree

5 files changed

+149
-1
lines changed

5 files changed

+149
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
"figlet": "^1.7.0",
158158
"figue": "^1.2.0",
159159
"flatten-anything": "^4.0.1",
160+
"file-type": "^19.0.0",
160161
"fuse.js": "^6.6.2",
161162
"hash-wasm": "^4.11.0",
162163
"generate-schema": "^2.6.0",

pnpm-lock.yaml

Lines changed: 58 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/file-type/file-type.vue

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<script setup lang="ts">
2+
import type { FileTypeResult } from 'file-type';
3+
import { fileTypeFromBuffer } from 'file-type';
4+
import InputCopyable from '../../components/InputCopyable.vue';
5+
6+
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
7+
const file = ref<File | null>(null);
8+
const type = ref<FileTypeResult | undefined>(undefined);
9+
10+
async function onFileUploaded(uploadedFile: File) {
11+
file.value = uploadedFile;
12+
const fileBuffer = await uploadedFile.arrayBuffer();
13+
14+
status.value = 'processing';
15+
try {
16+
type.value = await fileTypeFromBuffer(new Uint8Array(fileBuffer.slice(0, 4096)));
17+
status.value = 'done';
18+
}
19+
catch (e) {
20+
status.value = 'error';
21+
}
22+
}
23+
</script>
24+
25+
<template>
26+
<div>
27+
<div style="flex: 0 0 100%" mb-3>
28+
<div mx-auto max-w-600px>
29+
<c-file-upload
30+
title="Drag and drop a file here, or click to select a file"
31+
@file-upload="onFileUploaded"
32+
/>
33+
</div>
34+
</div>
35+
36+
<div mt-3 flex justify-center>
37+
<c-card v-if="status === 'done'" title="Information">
38+
<InputCopyable
39+
:value="file?.name || ''"
40+
label="File name:"
41+
label-position="left"
42+
label-width="100px"
43+
label-align="right"
44+
readonly
45+
mt-2
46+
/>
47+
48+
<InputCopyable
49+
:value="type?.ext || '<unknown>'"
50+
label="Extension:"
51+
label-position="left"
52+
label-width="100px"
53+
label-align="right"
54+
readonly
55+
mt-2
56+
/>
57+
<InputCopyable
58+
:value="type?.mime || '<unknown>'"
59+
label="MIME Type:"
60+
label-position="left"
61+
label-width="100px"
62+
label-align="right"
63+
readonly
64+
mt-2
65+
/>
66+
</c-card>
67+
<c-alert v-if="status === 'error'" type="error">
68+
An error occured processing {{ file?.name }}.
69+
</c-alert>
70+
<n-spin
71+
v-if="status === 'processing'"
72+
size="small"
73+
/>
74+
</div>
75+
</div>
76+
</template>

src/tools/file-type/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { File } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'File Type Detector',
6+
path: '/file-type',
7+
description: 'Identify the type of a file',
8+
keywords: ['file', 'type', 'identify', 'detector'],
9+
component: () => import('./file-type.vue'),
10+
icon: File,
11+
createdAt: new Date('2024-04-20'),
12+
});

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import { tool as dockerRunToKubernetesConverter } from './docker-run-to-kubernet
112112
import { tool as dockerComposeValidator } from './docker-compose-validator';
113113
import { tool as ecdsaKeyPairGenerator } from './ecdsa-key-pair-generator';
114114
import { tool as ed25519KeyPairGenerator } from './ed25519-key-pair-generator';
115+
import { tool as fileType } from './file-type';
115116
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
116117
import { tool as numeronymGenerator } from './numeronym-generator';
117118
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -383,6 +384,7 @@ export const toolsByCategory: ToolCategory[] = [
383384
regexMemo,
384385
stacktracePrettier,
385386
xpathTester,
387+
fileType,
386388
],
387389
},
388390
{

0 commit comments

Comments
 (0)