mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
|
|
|
|
@Component({
|
|
selector: 'sqx-asset-text-editor',
|
|
styleUrls: ['./asset-text-editor.component.scss'],
|
|
templateUrl: './asset-text-editor.component.html',
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export class AssetTextEditorComponent implements OnInit {
|
|
@Input()
|
|
public fileSource: string;
|
|
|
|
@Input()
|
|
public fileName: string;
|
|
|
|
@Input()
|
|
public mimeType: string;
|
|
|
|
public text = '';
|
|
|
|
constructor(
|
|
private readonly changeDetector: ChangeDetectorRef,
|
|
private readonly httpClient: HttpClient,
|
|
) {
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.httpClient.get(this.fileSource, { responseType: 'text' })
|
|
.subscribe(text => {
|
|
this.text = text;
|
|
|
|
this.changeDetector.detectChanges();
|
|
});
|
|
}
|
|
|
|
public toFile(): Promise<Blob | null> {
|
|
return new Promise<Blob | null>(resolve => {
|
|
const blob = new Blob([this.text || ''], {
|
|
type: this.mimeType,
|
|
});
|
|
|
|
resolve(blob);
|
|
});
|
|
}
|
|
}
|
|
|