Skip to content

Commit a00098c

Browse files
author
guqiankun.gqk
committed
feat: 增加文件类型判断
1 parent 6f9745c commit a00098c

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

packages/alex/src/core/editor/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export interface EditorConfig {
7171
* scrollbar 配置,参考 monaco 的 scrollbar 配置项,[文档链接](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditorscrollbaroptions.html)
7272
*/
7373
scrollbar?: Record<string, any>;
74+
/**
75+
* 去除编辑器缓存,此时没有缓存打开会重新请求
76+
*/
77+
disableCache?: boolean;
7478
}
7579

7680
export interface EditorProps {

packages/core/src/common/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ export interface RuntimeConfig {
180180
* 空白页自定义内容
181181
*/
182182
EditorEmpty?: React.FC;
183+
/**
184+
* 当文件后缀名判断格式 不满足条件时,可通过此配置项进行自定义
185+
* 优先会从语法服务中获取类型
186+
* https://aone.alipay.com/v2/project/1158176/bug/100102353
187+
*/
188+
resolveFileType?: (path: string) => 'image' | 'text' | 'video' | undefined;
183189
}
184190

185191
export type SearchMode = Boolean | 'local';

packages/core/src/server/file-service/disk-file-system.provider.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RuntimeConfig } from '@alipay/alex-core';
12
import {
23
Event,
34
IDisposable,
@@ -23,7 +24,7 @@ import {
2324
FileAccess,
2425
FileSystemProviderCapabilities,
2526
} from '@opensumi/ide-file-service/lib/common';
26-
import { Injectable } from '@opensumi/di';
27+
import { Autowired, Injectable } from '@opensumi/di';
2728
import * as path from 'path';
2829
import { HOME_ROOT } from '../../common';
2930
import { IDiskFileProvider } from './base';
@@ -47,6 +48,9 @@ export class DiskFileSystemProvider extends FCService implements IDiskFileProvid
4748
protected watchFileExcludes: string[] = [];
4849
protected watchFileExcludesMatcherList: ParsedPattern[] = [];
4950

51+
@Autowired(RuntimeConfig)
52+
private runtimeConfig: RuntimeConfig;
53+
5054
static H5VideoExtList = ['mp4', 'ogg', 'webm'];
5155

5256
static BinaryExtList = [
@@ -576,6 +580,10 @@ export class DiskFileSystemProvider extends FCService implements IDiskFileProvid
576580
ext = ext.slice(1);
577581
}
578582
}
583+
// 使用路径判断文件格式存在问题
584+
if (typeof this.runtimeConfig.resolveFileType === 'function') {
585+
return this.runtimeConfig.resolveFileType(uri.slice(7));
586+
}
579587
return this._getFileType(ext);
580588
}
581589
return 'directory';

packages/integrations/src/editor/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const fileOptions = (function transform(obj) {
4545
'ide-s/TypeScript-Node-Starter': {
4646
'feat/123123': ['gbk.ts'],
4747
},
48+
'zoloz_common/zoloz-api-test': {
49+
master: ['integration/saas/src/test/resources/images/doc/VN/id/cover_face_vnid2.jpg'],
50+
},
4851
});
4952

5053
const App = () => {
@@ -179,6 +182,9 @@ const App = () => {
179182
scenario: null,
180183
startupEditor: 'none',
181184
// hideEditorTab: true,
185+
resolveFileType(path) {
186+
return 'text';
187+
},
182188
}}
183189
editorConfig={{
184190
adjustFindWidgetTop: true,

0 commit comments

Comments
 (0)