Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add missing type for file-service #1611

Merged
merged 5 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class DiskFsProviderClient extends CoreFileServiceProviderClient implemen
return this.fileServiceProvider.copy(source, destination, options);
}

access(uri: Uri, mode) {
access(uri: Uri, mode: number) {
return this.fileServiceProvider.access(uri, mode);
}

Expand Down
25 changes: 25 additions & 0 deletions packages/file-service/src/common/file-ext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const EXT_LIST_VIDEO = ['mp4', 'webm', 'mkv', 'mov', 'mts', 'flv', 'avi', 'wmv'];

export const EXT_LIST_IMAGE = [
'png',
'gif',
'jpg',
'jpeg',
'svg',
'bmp',
'avif',
'cr2',
'cr3',
'dng',
'flif',
'heic',
'icns',
'jxl',
'jpm',
'jpx',
'nef',
'raf',
'rw2',
'tif',
'orf',
];
1 change: 1 addition & 0 deletions packages/file-service/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './file-service-client';
export * from './files';
export * from './watcher';
export * from './file-ext';

export const FileServicePath = 'FileService';
export const DiskFileServicePath = 'DiskFileService';
Expand Down
10 changes: 5 additions & 5 deletions packages/file-service/src/node/disk-file-system.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
IDiskFileProvider,
FileAccess,
FileSystemProviderCapabilities,
EXT_LIST_VIDEO,
EXT_LIST_IMAGE,
} from '../common/';

import { ParcelWatcherServer } from './file-service-watcher';
Expand All @@ -58,8 +60,6 @@ export interface IWatcher {

@Injectable({ multiple: true })
export class DiskFileSystemProvider extends RPCService<IRPCDiskFileSystemProvider> implements IDiskFileProvider {
static readonly H5VideoExtList = ['mp4', 'ogg', 'webm'];

private fileChangeEmitter = new Emitter<FileChangeEvent>();
private watcherServer: ParcelWatcherServer;
readonly onDidChangeFile: Event<FileChangeEvent> = this.fileChangeEmitter.event;
Expand Down Expand Up @@ -664,12 +664,12 @@ export class DiskFileSystemProvider extends RPCService<IRPCDiskFileSystemProvide
}
}

private _getFileType(ext) {
private _getFileType(ext: string) {
let type = 'text';

if (['png', 'gif', 'jpg', 'jpeg', 'svg'].indexOf(ext) !== -1) {
if (EXT_LIST_IMAGE.indexOf(ext) !== -1) {
type = 'image';
} else if (DiskFileSystemProvider.H5VideoExtList.indexOf(ext) !== -1) {
} else if (EXT_LIST_VIDEO.indexOf(ext) !== -1) {
type = 'video';
} else if (ext && ['xml'].indexOf(ext) === -1) {
type = 'binary';
Expand Down
6 changes: 3 additions & 3 deletions packages/file-service/src/node/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
match,
} from '@opensumi/ide-core-node';

import { FileChangeEvent, TextDocumentContentChangeEvent } from '../common';
import { FileChangeEvent, EXT_LIST_IMAGE, TextDocumentContentChangeEvent } from '../common';
import {
FileSystemError,
FileStat,
Expand Down Expand Up @@ -589,10 +589,10 @@ export class FileService implements IFileService {
return true;
}

private _getFileType(ext) {
private _getFileType(ext: string) {
let type = 'text';

if (['png', 'gif', 'jpg', 'jpeg', 'svg'].indexOf(ext) !== -1) {
if (EXT_LIST_IMAGE.indexOf(ext) !== -1) {
type = 'image';
} else if (ext && ['xml'].indexOf(ext) === -1) {
type = 'binary';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
FileSystemError,
notEmpty,
isErrnoException,
EXT_LIST_IMAGE,
EXT_LIST_VIDEO,
} from '@opensumi/ide-file-service';

import { HttpTreeList } from './http-file.service';
Expand All @@ -27,8 +29,6 @@ export const BROWSER_HOME_DIR = FileUri.create('/home');
// 预览模式下,文件改动仅同步到本地;常规场景直接同步远端,本地不做文件存储
// 利用storage来记录文件已加载的信息,dispose时记得清楚
export class BrowserFsProvider implements IDiskFileProvider {
static H5VideoExtList = ['mp4', 'ogg', 'webm'];

static binaryExtList = [
'aac',
'avi',
Expand Down Expand Up @@ -447,9 +447,9 @@ export class BrowserFsProvider implements IDiskFileProvider {
private _getFileType(ext: string) {
let type = 'text';

if (['png', 'gif', 'jpg', 'jpeg', 'svg'].indexOf(ext) > -1) {
if (EXT_LIST_IMAGE.indexOf(ext) > -1) {
type = 'image';
} else if (BrowserFsProvider.H5VideoExtList.indexOf(ext) > -1) {
} else if (EXT_LIST_VIDEO.indexOf(ext) > -1) {
type = 'video';
} else if (BrowserFsProvider.binaryExtList.indexOf(ext) > -1) {
type = 'binary';
Expand Down