Skip to content

Commit

Permalink
fix: import getFileType from core
Browse files Browse the repository at this point in the history
  • Loading branch information
wushuangs committed Aug 29, 2024
1 parent e1dfcc6 commit b5ff141
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 62 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"prepare": "husky install"
},
"dependencies": {
"@bytetrade/core": "0.3.57",
"@bytetrade/core": "0.3.60",
"axios": "^0.21.1",
"uuid": "9.0.1"
},
Expand Down
10 changes: 8 additions & 2 deletions packages/frontend/src/stores/search.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { defineStore } from 'pinia';
import axios from 'axios';
import { date } from 'quasar';
import { getFileType, getFileIcon } from '@bytetrade/core';
import { useAppStore } from './app';
import { useTokenStore } from './token';
import { getFileType, sizeFormat } from './../utils/utils';
import { sizeFormat } from './../utils/utils';
import { useSocketStore } from './websocketStore';

interface ChatMsg {
Expand Down Expand Up @@ -47,6 +48,7 @@ export interface TextSearchItem {
title: string;
resource_uri?: string;
fileType: string;
fileIcon: string;
}

export enum SecondFactorMethod {
Expand Down Expand Up @@ -153,6 +155,7 @@ export const useSearchStore = defineStore('search', {

items.map((item: any) => {
item.fileType = getFileType(item.name);
item.fileIcon = getFileIcon(item.name);
item.size = sizeFormat(item.size);
item.created = date.formatDate(
item.created * 1000,
Expand Down Expand Up @@ -197,6 +200,7 @@ export const useSearchStore = defineStore('search', {
for (let i = 0; i < res.length; i++) {
const el = res[i];
el.fileType = getFileType(el.title);
el.fileIcon = getFileIcon(el.title);
el.path = await this.getPath(el.resource_uri);
newRes.push(el);
}
Expand Down Expand Up @@ -236,13 +240,15 @@ export const useSearchStore = defineStore('search', {
formatSyncToSearch(id: string, data: any) {
const name = data.path.startsWith('/') ? data.path.slice(1) : data.path;
const fileType = getFileType(name);
const fileIcon = getFileIcon(name);

const searchRes: TextSearchItem = {
id: id,
highlight: name,
highlight_field: 'title',
title: name,
fileType: fileType || 'other',
fileType: fileType || 'blob',
fileIcon: fileIcon || 'other',
meta: {
updated: new Date(data.mtime).getTime() / 1000
}
Expand Down
59 changes: 0 additions & 59 deletions packages/frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,65 +53,6 @@ export function isLocalHost(url: string): boolean {
return false;
}

export function getFileType(fileName: string) {
let suffix = '';
let result: string | undefined = '';
if (fileName) {
const fileArr = fileName.split('.');
suffix = fileArr[fileArr.length - 1];
}
if (!suffix) return false;
suffix = suffix.toLocaleLowerCase();

const imgList = ['png', 'jpg', 'jpeg', 'bmp', 'gif'];
result = imgList.find((item) => item === suffix);
if (result) return 'image';
// txt
const txtList = ['txt'];
result = txtList.find((item) => item === suffix);
if (result) return 'txt';
// excel
const excelList = ['xls', 'xlsx'];
result = excelList.find((item) => item === suffix);
if (result) return 'excel';
// word
const wordList = ['doc', 'docx'];
result = wordList.find((item) => item === suffix);
if (result) return 'word';
// pdf
const pdfList = ['pdf'];
result = pdfList.find((item) => item === suffix);
if (result) return 'pdf';
// ppt
const pptList = ['ppt', 'pptx'];
result = pptList.find((item) => item === suffix);
if (result) return 'ppt';
// zip
const zipList = ['rar', 'zip', '7z'];
result = zipList.find((item) => item === suffix);
if (result) return 'zip';
// video
const videoList = [
'mp4',
'm2v',
'mkv',
'rmvb',
'wmv',
'avi',
'flv',
'mov',
'm4v'
];
result = videoList.find((item) => item === suffix);
if (result) return 'video';
// audio
const audioList = ['mp3', 'wav', 'wmv'];
result = audioList.find((item) => item === suffix);
if (result) return 'audio';
// other
return 'other';
}

export function sizeFormat(size: number) {
let data = '';
if (size < 0.1 * 1024) {
Expand Down

0 comments on commit b5ff141

Please sign in to comment.