refactor: code readability
This commit is contained in:
parent
5a7c56a67e
commit
47fe2f8f0a
1 changed files with 16 additions and 27 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
|
||||||
import mime from 'mime'
|
import mime from 'mime'
|
||||||
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
|
||||||
const { mimeFileMapping } = useFileInfoStore()
|
const { mimeFileMapping } = useFileInfoStore()
|
||||||
|
|
||||||
|
|
@ -11,44 +11,33 @@ defineProps<{
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
function getIcon(mimeType: string | undefined, fileName: string | undefined) {
|
function getIcon(mimeType: string | undefined, fileName: string | undefined) {
|
||||||
if (mimeType === undefined) {
|
if (!mimeType) return 'mdi-file-question-outline'
|
||||||
return 'mdi-file-question-outline'
|
|
||||||
}
|
const extension = mime.getExtension(mimeType)
|
||||||
|
|
||||||
|
if (extension) return mimeFileMapping[mimeType].icon
|
||||||
|
if (fileName && fileName.includes('.')) return 'mdi-file-outline'
|
||||||
|
|
||||||
const extFomMime = mime.getExtension(mimeType)
|
|
||||||
if (extFomMime) {
|
|
||||||
return mimeFileMapping[mimeType].icon
|
|
||||||
}
|
|
||||||
if (fileName && fileName.includes('.')) {
|
|
||||||
return 'mdi-file-outline'
|
|
||||||
}
|
|
||||||
return 'mdi-file-question-outline'
|
return 'mdi-file-question-outline'
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColor(mimeType: string | undefined, fileName: string | undefined) {
|
function getColor(mimeType: string | undefined, fileName: string | undefined) {
|
||||||
if (mimeType === undefined) {
|
if (mimeType === undefined) return 'grey-5'
|
||||||
return 'grey-5'
|
|
||||||
}
|
const extension = mime.getExtension(mimeType)
|
||||||
|
|
||||||
|
if (extension) return mimeFileMapping[mimeType].color
|
||||||
|
if (fileName && fileName.includes('.')) return 'blue-11'
|
||||||
|
|
||||||
const extFomMime = mime.getExtension(mimeType)
|
|
||||||
if (extFomMime) {
|
|
||||||
return mimeFileMapping[mimeType].color
|
|
||||||
}
|
|
||||||
if (fileName && fileName.includes('.')) {
|
|
||||||
return 'blue-11'
|
|
||||||
}
|
|
||||||
return 'grey-5'
|
return 'grey-5'
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIconSize(s: string) {
|
function getIconSize(size: string) {
|
||||||
type SizeMapping = {
|
const sizeMapping = {
|
||||||
[key: string]: string
|
|
||||||
}
|
|
||||||
const sizeMapping: SizeMapping = {
|
|
||||||
preview: '6em',
|
preview: '6em',
|
||||||
list: '2em',
|
list: '2em',
|
||||||
}
|
}
|
||||||
return sizeMapping[s]
|
return sizeMapping[size as keyof typeof sizeMapping]
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue