refactor: file to oss

This commit is contained in:
wxg0103 2025-06-06 12:31:30 +08:00
parent 448bbb3aae
commit 4d76f08b14
39 changed files with 91 additions and 90 deletions

View File

@ -44,11 +44,12 @@ mime_types = {
"dll": "application/octet-stream", "deb": "application/octet-stream", "dmg": "application/octet-stream",
"iso": "application/octet-stream", "img": "application/octet-stream", "msi": "application/octet-stream",
"msp": "application/octet-stream", "msm": "application/octet-stream", "mid": "audio/midi",
"midi": "audio/midi", "kar": "audio/midi", "mp3": "audio/mpeg", "ogg": "audio/ogg", "m4a": "audio/x-m4a",
"midi": "audio/midi", "kar": "audio/midi", "mp3": "audio/mp3", "ogg": "audio/ogg", "m4a": "audio/x-m4a",
"ra": "audio/x-realaudio", "3gpp": "video/3gpp", "3gp": "video/3gpp", "ts": "video/mp2t",
"mp4": "video/mp4", "mpeg": "video/mpeg", "mpg": "video/mpeg", "mov": "video/quicktime",
"webm": "video/webm", "flv": "video/x-flv", "m4v": "video/x-m4v", "mng": "video/x-mng",
"asx": "video/x-ms-asf", "asf": "video/x-ms-asf", "wmv": "video/x-ms-wmv", "avi": "video/x-msvideo"
"asx": "video/x-ms-asf", "asf": "video/x-ms-asf", "wmv": "video/x-ms-wmv", "avi": "video/x-msvideo",
"wav": "audio/wav", "flac": "audio/flac", "aac": "audio/aac", "opus": "audio/opus",
}
@ -77,21 +78,16 @@ class FileSerializer(serializers.Serializer):
file = QuerySet(File).filter(id=file_id).first()
if file is None:
raise NotFound404(404, _('File not found'))
# 如果是音频文件,直接返回文件流
file_type = file.file_name.split(".")[-1]
if file_type in ['mp3', 'wav', 'ogg', 'aac']:
return HttpResponse(
file.get_bytes(),
status=200,
headers={
'Content-Type': f'audio/{file_type}',
'Content-Disposition': 'attachment; filename="{}"'.format(file.file_name)
}
)
file_type = file.file_name.split(".")[-1].lower()
content_type = mime_types.get(file_type, 'application/octet-stream')
headers = {
'Content-Type': content_type,
'Content-Disposition': f'attachment; filename="{file.file_name}"'
}
return HttpResponse(
file.get_bytes(),
status=200,
headers={'Content-Type': mime_types.get(file_type, 'text/plain')}
headers=headers
)
def delete(self):

View File

@ -32,8 +32,8 @@ const postAPIKey: (application_id: string, loading?: Ref<boolean>) => Promise<Re
* @param application_id api_key_id
*/
const delAPIKey: (
application_id: String,
api_key_id: String,
application_id: string,
api_key_id: string,
loading?: Ref<boolean>
) => Promise<Result<boolean>> = (application_id, api_key_id, loading) => {
return del(`${prefix}/${application_id}/api_key/${api_key_id}`, undefined, undefined, loading)
@ -48,7 +48,7 @@ const delAPIKey: (
*/
const putAPIKey: (
application_id: string,
api_key_id: String,
api_key_id: string,
data: any,
loading?: Ref<boolean>
) => Promise<Result<any>> = (application_id, api_key_id, data, loading) => {

View File

@ -49,7 +49,7 @@ const postApplication: (
* @param
*/
const putApplication: (
application_id: String,
application_id: string,
data: ApplicationFormType,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
@ -61,7 +61,7 @@ const putApplication: (
* @param application_id
*/
const delApplication: (
application_id: String,
application_id: string,
loading?: Ref<boolean>,
) => Promise<Result<boolean>> = (application_id, loading) => {
return del(`${prefix}/${application_id}`, undefined, {}, loading)
@ -177,7 +177,7 @@ const postWorkflowChatOpen: (data: ApplicationFormType) => Promise<Result<any>>
]
}
*/
const getChatOpen: (application_id: String) => Promise<Result<any>> = (application_id) => {
const getChatOpen: (application_id: string) => Promise<Result<any>> = (application_id) => {
return get(`${prefix}/${application_id}/chat/open`)
}
/**
@ -305,7 +305,7 @@ const getApplicationTTIModel: (
* @param
*/
const putPublishApplication: (
application_id: String,
application_id: string,
data: ApplicationFormType,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
@ -317,7 +317,7 @@ const putPublishApplication: (
* @param loading
* @returns
*/
const listFunctionLib: (application_id: String, loading?: Ref<boolean>) => Promise<Result<any>> = (
const listFunctionLib: (application_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
application_id,
loading,
) => {
@ -343,8 +343,8 @@ export const getApplicationList: (
* @returns
*/
const getFunctionLib: (
application_id: String,
function_lib_id: String,
application_id: string,
function_lib_id: string,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, function_lib_id, loading) => {
return get(`${prefix}/${application_id}/function_lib/${function_lib_id}`, undefined, loading)
@ -358,8 +358,8 @@ const getMcpTools: (data: any, loading?: Ref<boolean>) => Promise<Result<any>> =
}
const getApplicationById: (
application_id: String,
app_id: String,
application_id: string,
app_id: string,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, app_id, loading) => {
return get(`${prefix}/${application_id}/application/${app_id}`, undefined, loading)
@ -372,8 +372,8 @@ const getApplicationById: (
* @returns
*/
const getModelParamsForm: (
application_id: String,
model_id: String,
application_id: string,
model_id: string,
loading?: Ref<boolean>,
) => Promise<Result<Array<FormField>>> = (application_id, model_id, loading) => {
return get(`${prefix}/${application_id}/model_params_form/${model_id}`, undefined, loading)
@ -383,8 +383,8 @@ const getModelParamsForm: (
*
*/
const uploadFile: (
application_id: String,
chat_id: String,
application_id: string,
chat_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, chat_id, data, loading) => {
@ -395,7 +395,7 @@ const uploadFile: (
*
*/
const postSpeechToText: (
application_id: String,
application_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
@ -406,7 +406,7 @@ const postSpeechToText: (
*
*/
const postTextToSpeech: (
application_id: String,
application_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {
@ -417,7 +417,7 @@ const postTextToSpeech: (
*
*/
const playDemoText: (
application_id: String,
application_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, data, loading) => {

View File

@ -70,7 +70,7 @@ const putTool: (
* @returns
*/
const getToolById: (
tool_id: String,
tool_id: string,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (tool_id, loading) => {
return get(`${prefix}/tool/${tool_id}`, undefined, loading)

View File

@ -45,7 +45,7 @@ interface chatType {
id: string
problem_text: string
answer_text: string
buffer: Array<String>
buffer: Array<string>
answer_text_list: Array<
Array<{
content: string

View File

@ -1,8 +1,8 @@
interface knowledgeData {
name: String
folder_id?: String
desc: String
embedding?: String
name: string
folder_id?: string
desc: string
embedding?: string
documents?: Array<any>
}

View File

@ -1,13 +1,13 @@
interface toolData {
id?: String
name?: String
icon?: String
desc?: String
code?: String
id?: string
name?: string
icon?: string
desc?: string
code?: string
input_field_list?: Array<any>
init_field_list?: Array<any>
is_active?: Boolean
folder_id?: String
is_active?: boolean
folder_id?: string
}
export type { toolData }

View File

@ -49,7 +49,7 @@ import ToolApi from '@/api/tool/tool'
defineOptions({name: 'CodemirrorEditor'})
const props = defineProps<{
title: String
title: string
modelValue: any
}>()
const emit = defineEmits(['update:modelValue', 'submitDialog'])
@ -73,7 +73,7 @@ function getRangeFromLineAndColumn(state: any, line: number, column: number, end
}
const regexpLinter = linter(async (view) => {
let diagnostics: Diagnostic[] = []
const diagnostics: Diagnostic[] = []
await ToolApi.postPylint(view.state.doc.toString()).then((ok) => {
ok.data.forEach((element: any) => {
const range = getRangeFromLineAndColumn(

View File

@ -36,7 +36,7 @@ const props = withDefaults(
},
)
const current = ref<Number | String>(0)
const current = ref<number | string>(0)
watch(
() => props.defaultActive,

View File

@ -114,7 +114,7 @@ const errMsg = computed(() => {
*/
const to_rule = (rule: any) => {
if (rule.validator) {
let validator = (rule: any, value: string, callback: any) => {}
const validator = (rule: any, value: string, callback: any) => {}
eval(rule.validator)
return { ...rule, validator }
}

View File

@ -74,12 +74,12 @@ const formFieldRef = ref<Array<InstanceType<typeof FormItem>>>([])
*/
const show = (field: FormField) => {
if (field.relation_show_field_dict) {
let keys = Object.keys(field.relation_show_field_dict)
const keys = Object.keys(field.relation_show_field_dict)
for (const index in keys) {
const key = keys[index]
let v = _.get(formValue.value, key)
const v = _.get(formValue.value, key)
if (v && v !== undefined && v !== null) {
let values = field.relation_show_field_dict[key]
const values = field.relation_show_field_dict[key]
if (values && values.length > 0) {
return values.includes(v)
} else {

View File

@ -125,7 +125,7 @@ function deleteApiKey(row: any) {
.catch(() => {})
}
function changeState(bool: Boolean, row: any) {
function changeState(bool: boolean, row: any) {
const obj = {
is_active: bool
}

View File

@ -96,7 +96,7 @@ const open = () => {
}
const onChange = (file: any) => {
let fd = new FormData()
const fd = new FormData()
fd.append('license_file', file.raw)
licenseApi.putLicense(fd, loading).then((res: any) => {
getLicenseInfo()

View File

@ -5,13 +5,13 @@ import {createI18n} from 'vue-i18n'
// 导入语言文件
const langModules = import.meta.glob('./lang/*/index.ts', {eager: true}) as Record<
string,
() => Promise<{ default: Object }>
() => Promise<{ default: object }>
>
// 定义 Recordable 类型
type Recordable<T = any> = Record<string, T>
const langModuleMap = new Map<string, Object>()
const langModuleMap = new Map<string, object>()
export const langCode: Array<string> = []

View File

@ -10,7 +10,7 @@ const useLoginStore = defineStore('login', {
userAccessToken: '',
}),
actions: {
getToken(): String | null {
getToken(): string | null {
if (this.token) {
return this.token
}

View File

@ -65,7 +65,7 @@ const useLoginStore = defineStore('user', {
this.XPACK_LICENSE_IS_VALID = true
if (this.isEnterprise()) {
// await this.theme()
// await this.theme()
} else {
this.themeInfo = {
...defaultPlatformSetting

View File

@ -63,6 +63,6 @@ export function filesize(size: number) {
// 头像
export const defaultIcon = '/ui/favicon.ico'
export function isAppIcon(url: String | undefined) {
export function isAppIcon(url: string | undefined) {
return url === defaultIcon ? '' : url
}

View File

@ -38,7 +38,7 @@ export const MsgError = (message: string) => {
}
export const MsgAlert = (title: string, description: string, options?: any) => {
const defaultOptions: Object = {
const defaultOptions: object = {
confirmButtonText: t('common.confirm'),
...options
}
@ -51,7 +51,7 @@ export const MsgAlert = (title: string, description: string, options?: any) => {
*/
export const MsgConfirm = (title: string, description: string, options?: any) => {
const defaultOptions: Object = {
const defaultOptions: object = {
showCancelButton: true,
confirmButtonText: t('common.confirm'),
cancelButtonText: t('common.cancel'),

View File

@ -50,7 +50,7 @@ class Status {
}
status = status.split('').reverse().join('')
this.task_status = {}
for (let key in TaskType) {
for (const key in TaskType) {
const value = TaskType[key as keyof TaskTypeInterface]
const index = value - 1
this.task_status[value] = status[index] ? status[index] : 'n'
@ -58,7 +58,7 @@ class Status {
}
toString() {
const r = []
for (let key in TaskType) {
for (const key in TaskType) {
const value = TaskType[key as keyof TaskTypeInterface]
r.push(this.task_status[value])
}

View File

@ -120,7 +120,7 @@ function submit() {
dialogVisible.value = false
})
} else if (radioType.value === 'custom' && iconFile.value) {
let fd = new FormData()
const fd = new FormData()
fd.append('file', iconFile.value.raw)
overviewApi.putAppIcon(id as string, fd, loading).then((res: any) => {
emit('refresh')

View File

@ -573,7 +573,7 @@ const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid, fields) => {
if (valid) {
let fd = new FormData()
const fd = new FormData()
Object.keys(xpackForm.value).map((item) => {
if (['custom_theme', 'float_location'].includes(item)) {
fd.append(item, JSON.stringify(xpackForm.value[item]))

View File

@ -334,7 +334,7 @@ function refreshAccessToken() {
})
.catch(() => {})
}
function changeState(bool: Boolean) {
function changeState(bool: boolean) {
const obj = {
is_active: !bool
}

View File

@ -278,7 +278,7 @@ async function publicHandle() {
MsgError(e.toString())
return
}
applicationApi.putPublishApplication(id as String, obj, loading).then(() => {
applicationApi.putPublishApplication(id as string, obj, loading).then(() => {
application.asyncGetApplicationDetail(id, loading).then((res: any) => {
detail.value.name = res.data.name

View File

@ -154,7 +154,7 @@ const open = async (platform: Platform) => {
Object.assign(currentPlatform, platform)
// callback_url
let defaultCallbackUrl = window.location.origin
const defaultCallbackUrl = window.location.origin
switch (platform.key) {
case 'wecom':
if (currentPlatform.config.app_key) {

View File

@ -82,7 +82,7 @@ async function next() {
disabled.value = true
if (await UploadComponentRef.value.validate()) {
if (documentsType.value === 'QA') {
let fd = new FormData()
const fd = new FormData()
documentsFiles.value.forEach((item: any) => {
if (item?.raw) {
fd.append('file', item?.raw)
@ -97,7 +97,7 @@ async function next() {
})
}
} else if (documentsType.value === 'table') {
let fd = new FormData()
const fd = new FormData()
documentsFiles.value.forEach((item: any) => {
if (item?.raw) {
fd.append('file', item?.raw)

View File

@ -168,7 +168,7 @@ function changeHandle(val: boolean) {
}
function splitDocument() {
loading.value = true
let fd = new FormData()
const fd = new FormData()
documentsFiles.value.forEach((item) => {
if (item?.raw) {
fd.append('file', item?.raw)

View File

@ -440,7 +440,7 @@ function deleteParam(index: any) {
function refresh(data: any, index: any) {
for (let i = 0; i < base_form_data.value.model_params_form.length; i++) {
let field = base_form_data.value.model_params_form[i].field
const field = base_form_data.value.model_params_form[i].field
let label = base_form_data.value.model_params_form[i].label
if (label && label.input_type === 'TooltipLabel') {
label = label.label

View File

@ -124,7 +124,7 @@ function deleteParam(index: any) {
function refresh(data: any, index: any) {
for (let i = 0; i < modelParamsForm.value.length; i++) {
let field = modelParamsForm.value[i].field
const field = modelParamsForm.value[i].field
let label = modelParamsForm.value[i].label
if (label && label.input_type === 'TooltipLabel') {
label = label.label

View File

@ -131,13 +131,13 @@ const loading = ref(false)
const documentList = ref<any[]>([])
const cloneDocumentList = ref<any[]>([])
const paragraphList = ref<any[]>([])
const currentProblemId = ref<String>('')
const currentProblemId = ref<string>('')
const currentMulProblemId = ref<string[]>([])
//
const associationParagraph = ref<any[]>([])
const currentDocument = ref<String>('')
const currentDocument = ref<string>('')
const search = ref('')
const searchType = ref('title')
const filterDoc = ref('')
@ -222,7 +222,7 @@ function getDocument() {
})
}
function getParagraphList(documentId: String) {
function getParagraphList(documentId: string) {
paragraphApi
.getParagraph(
id,
@ -238,16 +238,16 @@ function getParagraphList(documentId: String) {
}
//
function getRecord(problemId: String) {
function getRecord(problemId: string) {
problemApi.getDetailProblems(id as string, problemId as string, loading).then((res) => {
associationParagraph.value = res.data
})
}
function associationCount(documentId: String) {
function associationCount(documentId: string) {
return associationParagraph.value.filter((item) => item.document_id === documentId).length
}
function isAssociation(paragraphId: String) {
function isAssociation(paragraphId: string) {
return associationParagraph.value.some((option) => option.id === paragraphId)
}

View File

@ -305,12 +305,12 @@ const nextChatRecord = () => {
}
}
const pre_disable = computed(() => {
let index = problemIndexMap.value[currentClickId.value] - 1
const index = problemIndexMap.value[currentClickId.value] - 1
return index < 0 && paginationConfig.current_page <= 1
})
const next_disable = computed(() => {
let index = problemIndexMap.value[currentClickId.value] + 1
const index = problemIndexMap.value[currentClickId.value] + 1
return (
index >= problemData.value.length &&
index + (paginationConfig.current_page - 1) * paginationConfig.page_size >=

View File

@ -82,7 +82,7 @@ const submitMember = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid, fields) => {
if (valid) {
let idsArray = memberForm.value.users.map((obj: any) => obj.id)
const idsArray = memberForm.value.users.map((obj: any) => obj.id)
AuthorizationApi.postCreatTeamMember(idsArray, loading).then((res) => {
MsgSuccess(t('common.submitSuccess'))
emit('refresh', idsArray)

View File

@ -108,7 +108,7 @@ watch(filterText, (val: any) => {
}
})
function isManage(type: String) {
function isManage(type: string) {
return type === 'manage'
}

View File

@ -109,7 +109,7 @@ function submit() {
emit('refresh', '/ui/favicon.ico')
dialogVisible.value = false
} else if (radioType.value === 'custom' && iconFile.value) {
let fd = new FormData()
const fd = new FormData()
fd.append('file', iconFile.value.raw)
toolApi.putToolIcon(detail.value.id, fd, loading).then((res: any) => {
emit('refresh', res.data)

View File

@ -25,7 +25,7 @@ import { t } from '@/locales'
const props = defineProps<{
nodeModel: any
modelValue: Array<any>
global?: Boolean
global?: boolean
}>()
const emit = defineEmits(['update:modelValue'])
const data = computed({

View File

@ -94,7 +94,7 @@ function refreshFieldList(data: any) {
}
}
// list
let arr = props.nodeModel.properties.user_input_field_list
const arr = props.nodeModel.properties.user_input_field_list
for (let i = 0; i < arr.length; i++) {
if (arr[i].field === data.variable) {
MsgError(t('views.applicationWorkflow.tip.paramErrorMessage') + data.variable)

View File

@ -149,7 +149,7 @@ function refreshFieldList(data: any, index: any) {
}
}
// list
let arr = props.nodeModel.properties.api_input_field_list
const arr = props.nodeModel.properties.api_input_field_list
for (let i = 0; i < arr.length; i++) {
if (arr[i].variable === data.field) {
MsgError(t('views.applicationWorkflow.tip.paramErrorMessage') + data.field)

View File

@ -284,7 +284,7 @@ function changeTool() {
)[0].args_schema
form_data.value.tool_form_field = []
for (const item in args_schema.properties) {
let params = args_schema.properties[item].properties
const params = args_schema.properties[item].properties
if (params) {
form_data.value.params_nested = item
for (const item2 in params) {

View File

@ -86,7 +86,7 @@ const refreshFileUploadConfig = () => {
set(props.nodeModel.properties.config, 'fields', fields)
return
}
let fileUploadFields = []
const fileUploadFields = []
if (form_data[0].document) {
fileUploadFields.push({ label: t('common.fileUpload.document'), value: 'document' })
}

View File

@ -16,6 +16,11 @@ export default defineConfig(({ mode }) => {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
rewrite: (path) => path.replace(ENV.VITE_BASE_PATH, '/'),
}
proxyConf['/oss'] = {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
rewrite: (path) => path.replace(ENV.VITE_BASE_PATH, '/'),
}
proxyConf['/doc'] = {
target: 'http://127.0.0.1:8080',