-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
183 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
"version": "2.0.4" | ||
"version": "2.1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/core/src/core/editor/contributions/static-resource.contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Autowired, Injectable } from '@opensumi/di'; | ||
import { AppConfig, Domain, path as paths, URI } from '@opensumi/ide-core-browser'; | ||
import { | ||
StaticResourceContribution as CoreStaticResourceContribution, | ||
StaticResourceService, | ||
} from '@opensumi/ide-core-browser/lib/static-resource'; | ||
import { IWorkspaceService } from '@opensumi/ide-workspace'; | ||
import { IPropsService } from '../../props.service'; | ||
import { fromSCMUri } from '../../utils'; | ||
import { CodeDocumentModel, EditorProps } from '../types'; | ||
|
||
const EXPRESS_SERVER_PATH = window.location.href; | ||
|
||
// file 文件资源 远程读取 | ||
@Domain(CoreStaticResourceContribution) | ||
export class EditorStaticResourceContribution implements CoreStaticResourceContribution { | ||
@Autowired(AppConfig) | ||
private readonly appConfig: AppConfig; | ||
|
||
@Autowired(IWorkspaceService) | ||
private readonly workspaceService: IWorkspaceService; | ||
|
||
@Autowired(IPropsService) | ||
propsService: IPropsService<EditorProps>; | ||
|
||
registerStaticResolver(service: StaticResourceService): void { | ||
// 用来打开 raw 文件,如 jpg | ||
service.registerStaticResourceProvider({ | ||
scheme: 'file', | ||
resolveStaticResource: (uri: URI) => { | ||
const documentModel = this.propsService.props.documentModel; | ||
|
||
if ( | ||
!(this.appConfig.staticServicePath | ||
|| (documentModel && (documentModel as CodeDocumentModel).resolveStaticResourcePath)) | ||
) { | ||
return uri; | ||
} | ||
|
||
// 将 file 协议转为代码托管平台提供的 raw 服务 | ||
const assetsUri = new URI(this.appConfig.staticServicePath!); | ||
const rootUri = new URI(this.workspaceService.workspace?.uri!); | ||
const relativePath = rootUri.relative(uri); | ||
if (!relativePath) { | ||
return uri; | ||
} | ||
|
||
// FIXME: 由于 resolveStaticResource 是同步方法,这里 hardcode 了 workspaceManagerService 的实现 | ||
let relativePathStr = relativePath.toString(); | ||
|
||
// trim leading whitespace | ||
if (relativePathStr.startsWith(paths.Path.separator)) { | ||
relativePathStr = relativePathStr.slice(1); | ||
} | ||
|
||
if (documentModel && (documentModel as CodeDocumentModel).resolveStaticResourcePath) { | ||
return (documentModel as CodeDocumentModel).resolveStaticResourcePath!( | ||
documentModel as CodeDocumentModel, | ||
); | ||
} | ||
return assetsUri.withPath(assetsUri.path.join(relativePathStr)); | ||
}, | ||
roots: [this.appConfig.staticServicePath || EXPRESS_SERVER_PATH], | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.