-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor-content): working on preview for text files #29872
- Loading branch information
Showing
10 changed files
with
302 additions
and
177 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
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
3 changes: 2 additions & 1 deletion
3
...ent/src/lib/fields/dot-edit-content-file-field/dot-edit-content-file-field.component.html
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
48 changes: 48 additions & 0 deletions
48
...nt/src/lib/fields/dot-edit-content-file-field/services/upload-file/upload-file.service.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,48 @@ | ||
import { of } from 'rxjs'; | ||
|
||
import { HttpClient } from '@angular/common/http'; | ||
import { inject, Injectable } from '@angular/core'; | ||
|
||
import { map, switchMap } from 'rxjs/operators'; | ||
|
||
import { DotUploadFileService } from '@dotcms/data-access'; | ||
import { DotCMSContentlet } from '@dotcms/dotcms-models'; | ||
|
||
import { DotEditContentService } from '../../../../services/dot-edit-content.service'; | ||
import { getFileMetadata, getFileVersion } from '../../utils'; | ||
|
||
@Injectable() | ||
export class DotFileFieldUploadService { | ||
readonly #fileService = inject(DotUploadFileService); | ||
readonly #contentService = inject(DotEditContentService); | ||
readonly #httpClient = inject(HttpClient); | ||
|
||
uploadDotAsset(file: File) { | ||
return this.#fileService | ||
.uploadDotAsset(file) | ||
.pipe(switchMap((contentlet) => this.#addContent(contentlet))); | ||
} | ||
|
||
getContentById(identifier: string) { | ||
return this.#contentService | ||
.getContentById(identifier) | ||
.pipe(switchMap((contentlet) => this.#addContent(contentlet))); | ||
} | ||
|
||
#addContent(contentlet: DotCMSContentlet) { | ||
const { editableAsText } = getFileMetadata(contentlet); | ||
const contentURL = getFileVersion(contentlet); | ||
|
||
if (editableAsText && contentURL) { | ||
return this.#getContentFile(contentURL).pipe( | ||
map((content) => ({ ...contentlet, content })) | ||
); | ||
} | ||
|
||
return of(contentlet); | ||
} | ||
|
||
#getContentFile(contentURL: string) { | ||
return this.#httpClient.get(contentURL, { responseType: 'text' }); | ||
} | ||
} |
Oops, something went wrong.