mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
fix #629: use new mini browser endpoint to preview local images
This commit is contained in:
parent
227b1328bb
commit
278117fb36
@ -4,18 +4,26 @@
|
||||
* See License-AGPL.txt in the project root for license information.
|
||||
*/
|
||||
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { PreviewLinkNormalizer } from "@theia/preview/lib/browser/preview-link-normalizer";
|
||||
import URI from "@theia/core/lib/common/uri";
|
||||
import { MiniBrowserEnvironment } from '../mini-browser/mini-browser-environment';
|
||||
|
||||
|
||||
@injectable()
|
||||
export class GitpodPreviewLinkNormalizer extends PreviewLinkNormalizer {
|
||||
|
||||
@inject(MiniBrowserEnvironment)
|
||||
private readonly miniBrowserEnvironment: MiniBrowserEnvironment;
|
||||
|
||||
normalizeLink(documentUri: URI, link: string): string {
|
||||
try {
|
||||
if (documentUri.scheme === 'file') {
|
||||
return super.normalizeLink(documentUri, link);
|
||||
if (documentUri.scheme !== 'file') {
|
||||
return documentUri.parent.resolve(link).toString();
|
||||
}
|
||||
if (!this.urlScheme.test(link)) {
|
||||
const location = documentUri.parent.resolve(link).path.toString();
|
||||
return this.miniBrowserEnvironment.getEndpoint('normalized-link').getRestUrl().resolve(location).toString();
|
||||
}
|
||||
return documentUri.parent.resolve(link).toString();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user