OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#46150] remove old upload services
Eric Schubert0b0d5a60b246
diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.tsindex cd7e2803d41..b8dbaf7799b 100644--- a/frontend/src/app/app.module.ts+++ b/frontend/src/app/app.module.ts@@ -76,7 +76,6 @@ import { OpenprojectModalModule } from 'core-app/shared/components/modal/modal.mimport {RevitAddInSettingsButtonService,} from 'core-app/features/bim/revit_add_in/revit-add-in-settings-button.service';-import { OpenProjectFileUploadService } from 'core-app/core/file-upload/op-file-upload.service';import { OpenprojectEnterpriseModule } from 'core-app/features/enterprise/openproject-enterprise.module';import { MainMenuToggleComponent } from 'core-app/core/main-menu/main-menu-toggle.component';import { MainMenuNavigationService } from 'core-app/core/main-menu/main-menu-navigation.service';@@ -109,7 +108,6 @@ import {OpenProjectInAppNotificationsModule,} from 'core-app/features/in-app-notifications/in-app-notifications.module';import { OpenProjectBackupService } from './core/backup/op-backup.service';-import { OpenProjectDirectFileUploadService } from './core/file-upload/op-direct-file-upload.service';import { OpenProjectStateModule } from 'core-app/core/state/openproject-state.module';import {OpenprojectContentLoaderModule,@@ -239,8 +237,6 @@ export function initializeServices(injector:Injector) {},PaginationService,OpenProjectBackupService,- OpenProjectFileUploadService,- OpenProjectDirectFileUploadService,ConfirmDialogService,RevitAddInSettingsButtonService,],diff --git a/frontend/src/app/core/file-upload/op-direct-file-upload.service.ts b/frontend/src/app/core/file-upload/op-direct-file-upload.service.tsdeleted file mode 100644index 8ac621e5768..00000000000--- a/frontend/src/app/core/file-upload/op-direct-file-upload.service.ts+++ /dev/null@@ -1,156 +0,0 @@-// -- copyright-// OpenProject is an open source project management software.-// Copyright (C) 2012-2023 the OpenProject GmbH-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License version 3.-//-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-// Copyright (C) 2006-2013 Jean-Philippe Lang-// Copyright (C) 2010-2013 the ChiliProject Team-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License-// as published by the Free Software Foundation; either version 2-// of the License, or (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-//-// See COPYRIGHT and LICENSE files for more details.-//++--import { getType } from 'mime';-import { Injectable } from '@angular/core';-import { HttpEvent, HttpResponse } from '@angular/common/http';-import { from, Observable, of } from 'rxjs';-import { share, switchMap } from 'rxjs/operators';--import { HalResource } from 'core-app/features/hal/resources/hal-resource';-import { EXTERNAL_REQUEST_HEADER } from 'core-app/features/hal/http/openproject-header-interceptor';-import {- OpenProjectFileUploadService, UploadBlob, UploadFile, UploadInProgress,-} from './op-file-upload.service';--interface PrepareUploadResult {- url:string;- form:FormData;- response:{- _links:{- completeUpload:{- href:string;- };- };- };-}--@Injectable()-export class OpenProjectDirectFileUploadService extends OpenProjectFileUploadService {- /**- * Upload a single file, get an UploadResult observable- */- public uploadSingle(url:string, file:UploadFile|UploadBlob, method = 'post') {- const observable = from(this.getDirectUploadFormFrom(url, file))- .pipe(- switchMap(this.uploadToExternal(file, method)),- share(),- );-- return [file, observable] as UploadInProgress;- }-- private uploadToExternal(file:UploadFile|UploadBlob, method:string):(result:PrepareUploadResult) => Observable<HttpEvent<unknown>> {- return (result) => {- result.form.append('file', file, file.customName || file.name);-- return this.http.request(- method,- result.url,- {- body: result.form,- // Observe the response, not the body- observe: 'events',- // This is important as the CORS policy for the bucket is * and you can't use credentials then,- // besides we don't need them here anyway.- headers: {- [EXTERNAL_REQUEST_HEADER]: 'true',- },- responseType: 'text',- // Subscribe to progress events. subscribe() will fire multiple times!- reportProgress: true,- },- ).pipe(- switchMap(this.finishUpload(result)),- );- };- }-- private finishUpload(result:PrepareUploadResult):(result:HttpEvent<unknown>) => Observable<HttpEvent<unknown>> {- return (event) => {- if (event instanceof HttpResponse) {- return this- .http- .get(- result.response?._links?.completeUpload?.href,- { observe: 'response' },- );- }-- // Return as new observable due to switchMap- return of(event);- };- }-- public async getDirectUploadFormFrom(url:string, file:UploadFile|UploadBlob):Promise<PrepareUploadResult> {- const fileName = file.customName || file.name;- const contentType = (file.type || (fileName && getType(fileName)) || '' as string);-- const formData = new FormData();- const metadata = {- fileName,- contentType,- description: file.description,- fileSize: file.size,- };-- /*- * @TODO We could calculate the MD5 hash here too and pass that.- * The MD5 hash can be used as the `content-md5` option during the upload to S3 for instance.- * This way S3 can verify the integrity of the file which we currently don't do.- */-- // add the metadata object- formData.append(- 'metadata',- JSON.stringify(metadata),- );-- const result = await this.http.request<HalResource>(- 'post',- url,- {- body: formData,- withCredentials: true,- responseType: 'json',- },- ).toPromise();-- const form = new FormData();-- _.each(result._links.addAttachment.form_fields, (value, key) => {- form.append(key, value);- });-- return {- form,- url: result._links.addAttachment.href,- response: result as any,- };- }-}diff --git a/frontend/src/app/core/file-upload/op-file-upload.service.spec.ts b/frontend/src/app/core/file-upload/op-file-upload.service.spec.tsdeleted file mode 100644index 5d6684444d1..00000000000--- a/frontend/src/app/core/file-upload/op-file-upload.service.spec.ts+++ /dev/null@@ -1,86 +0,0 @@-// -- copyright-// OpenProject is an open source project management software.-// Copyright (C) 2012-2023 the OpenProject GmbH-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License version 3.-//-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-// Copyright (C) 2006-2013 Jean-Philippe Lang-// Copyright (C) 2010-2013 the ChiliProject Team-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License-// as published by the Free Software Foundation; either version 2-// of the License, or (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-//-// See COPYRIGHT and LICENSE files for more details.-//++--import { OpenProjectDirectFileUploadService } from 'core-app/core/file-upload/op-direct-file-upload.service';-import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';-import { getTestBed, TestBed } from '@angular/core/testing';-import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';-import { States } from 'core-app/core/states/states.service';-import { I18nService } from 'core-app/core/i18n/i18n.service';-import { OpenProjectFileUploadService, UploadFile, UploadResult } from './op-file-upload.service';--describe('opFileUpload service', () => {- let injector:TestBed;- let service:OpenProjectFileUploadService;- let httpMock:HttpTestingController;-- beforeEach(() => {- TestBed.configureTestingModule({- imports: [HttpClientTestingModule],- providers: [- { provide: States, useValue: new States() },- I18nService,- OpenProjectFileUploadService,- OpenProjectDirectFileUploadService,- HalResourceService,- ],- });-- injector = getTestBed();- service = injector.get(OpenProjectFileUploadService);- httpMock = injector.get(HttpTestingController);- });-- afterEach(() => {- httpMock.verify();- });-- describe('when uploading multiple files', () => {- let result:UploadResult;- const file:UploadFile = new File([JSON.stringify({- name: 'name',- description: 'description',- })], 'name');-- beforeEach(() => {- result = service.upload('/my/api/path', [file, file]);- httpMock.match('/my/api/path').forEach((req) => {- expect(req.request.method).toBe('POST');- req.flush({});- });- });-- it('should call upload once for every file, that is no directory', () => {- expect(result.uploads.length).toEqual(2);- });-- it('should return a resolved promise that is the summary of the uploads', (done) => {- result.finished.then(done);- });- });-});diff --git a/frontend/src/app/core/file-upload/op-file-upload.service.ts b/frontend/src/app/core/file-upload/op-file-upload.service.tsdeleted file mode 100644index c597a4dca75..00000000000--- a/frontend/src/app/core/file-upload/op-file-upload.service.ts+++ /dev/null@@ -1,155 +0,0 @@-// -- copyright-// OpenProject is an open source project management software.-// Copyright (C) 2012-2023 the OpenProject GmbH-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License version 3.-//-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-// Copyright (C) 2006-2013 Jean-Philippe Lang-// Copyright (C) 2010-2013 the ChiliProject Team-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License-// as published by the Free Software Foundation; either version 2-// of the License, or (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-//-// See COPYRIGHT and LICENSE files for more details.-//++--import { Injectable } from '@angular/core';-import {- HttpClient,- HttpEvent,- HttpEventType,- HttpResponse,-} from '@angular/common/http';-import { Observable } from 'rxjs';-import { filter, map, share } from 'rxjs/operators';-import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';-import { HalResource } from 'core-app/features/hal/resources/hal-resource';--export interface UploadFile extends File {- description?:string;- customName?:string;-}--export interface UploadBlob extends Blob {- description?:string;- customName?:string;- name?:string;-}--export type UploadHttpEvent = HttpEvent<HalResource>;-export type UploadInProgress = [UploadFile, Observable<UploadHttpEvent>];--export interface UploadResult {- uploads:UploadInProgress[];- finished:Promise<any[]>;-}--export interface MappedUploadResult {- uploads:UploadInProgress[];- finished:Promise<{ response:any, uploadUrl:string }[]>;-}--@Injectable()-export class OpenProjectFileUploadService {- constructor(- protected readonly http:HttpClient,- protected readonly halResource:HalResourceService,- ) { }-- /**- * Upload multiple files and return a promise for each uploading file and a single promise for all processed uploads- * with their accessible URLs returned.- */- public uploadAndMapResponse(url:string, files:UploadFile[]):MappedUploadResult {- const { uploads, finished } = this.upload(url, files);- const mapped = finished- .then((result:HalResource[]) => result.map((element:HalResource) => ({- response: element,- uploadUrl: (element.staticDownloadLocation as unknown&{ href:string }).href,- }))) as Promise<{ response:HalResource, uploadUrl:string }[]>;-- return { uploads, finished: mapped } as MappedUploadResult;- }-- /**- * Upload multiple files and return a promise for each uploading file and a single promise for all processed uploads- * Ignore directories.- */- public upload(url:string, files:UploadFile[], method = 'post'):UploadResult {- files = _.filter(files, (file:UploadFile) => file.type !== 'directory');- const uploads:UploadInProgress[] = _.map(files, (file:UploadFile) => this.uploadSingle(url, file, method));-- const finished = this.whenFinished(uploads);- return { uploads, finished } as UploadResult;- }-- /**- * Upload a single file, get an UploadResult observable- */- public uploadSingle(- url:string,- file:UploadFile|UploadBlob,- method = 'post',- responseType:'json'|'text' = 'json',- ):UploadInProgress {- const formData = new FormData();- const metadata = {- description: file.description,- fileName: file.customName || file.name,- };-- // add the metadata object- formData.append(- 'metadata',- JSON.stringify(metadata),- );-- // Add the file- formData.append('file', file, metadata.fileName);-- const observable = this.http.request(- method,- url,- {- body: formData,- // Observe the response, not the body- observe: 'events',- withCredentials: true,- responseType,- // Subscribe to progress events. subscribe() will fire multiple times!- reportProgress: true,- },- ).pipe(share());-- return [file, observable] as UploadInProgress;- }-- /**- * Create a promise for all uploaded responses when all uploads are fully uploaded.- *- * @param {UploadInProgress[]} uploads- */- private whenFinished(uploads:UploadInProgress[]):Promise<HalResource[]> {- const promises = uploads.map(([_, observable]) => observable- .pipe(- filter((evt) => evt.type === HttpEventType.Response),- map((evt:HttpResponse<HalResource>) => this.halResource.createHalResource(evt.body)),- )- .toPromise());-- return Promise.all(promises);- }-}diff --git a/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts b/frontend/src/app/features/hal/resources/mixins/attachable-mixin.tsindex 685c3375039..8ce0889f188 100644--- a/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts+++ b/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts@@ -26,44 +26,18 @@// See COPYRIGHT and LICENSE files for more details.//++-import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';-import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';-import { ToastService } from 'core-app/shared/components/toaster/toast.service';-import { ConfigurationService } from 'core-app/core/config/configuration.service';-import { HttpErrorResponse } from '@angular/common/http';-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';-import { OpenProjectDirectFileUploadService } from 'core-app/core/file-upload/op-direct-file-upload.service';-import { OpenProjectFileUploadService, UploadFile } from 'core-app/core/file-upload/op-file-upload.service';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { AttachmentCollectionResource } from 'core-app/features/hal/resources/attachment-collection-resource';import isNewResource from 'core-app/features/hal/helpers/is-new-resource';+import { HalLink } from 'core-app/features/hal/hal-link/hal-link';-type Constructor<T = {}> = new (...args:any[]) => T;+// eslint-disable-next-line+type Constructor<T = object> = new (...args:any[]) => T;export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {return class extends Base {public attachments:AttachmentCollectionResource;- private ToastService:ToastService;-- private halNotification:HalResourceNotificationService;-- private opFileUpload:OpenProjectFileUploadService;-- private opDirectFileUpload:OpenProjectDirectFileUploadService;-- private pathHelper:PathHelperService;-- private apiV3Service:ApiV3Service;-- private config:ConfigurationService;-- /**- * Can be used in the mixed in class to disable- * attempts to upload attachments right away.- */- private attachmentsBackend:boolean|null;-/*** Return whether the user is able to upload an attachment.*@@ -71,178 +45,7 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {* adding attachments is allowed.*/public get canAddAttachments():boolean {- return !!this.$links.addAttachment || isNewResource(this);- }-- /**- *- */- public get hasAttachments():boolean {- return _.get(this.attachments, 'elements.length', 0) > 0;- }-- /**- * Try to find an existing file's download URL given its filename- * @param file- */- public lookupDownloadLocationByName(file:string):string|null {- if (!(this.attachments && this.attachments.elements)) {- return null;- }-- const match = _.find(this.attachments.elements, (res:HalResource) => res.name === file);- return _.get(match, 'staticDownloadLocation.href', null);- }-- /**- * Remove the given attachment either from the pending attachments or from- * the attachment collection, if it is a resource.- *- * Removing it from the elements array assures that the view gets updated immediately.- * If an error occurs, the user gets notified and the attachment is pushed to the elements.- */- public removeAttachment(attachment:any):Promise<any> {- _.pull(this.attachments.elements, attachment);-- if (attachment.$isHal) {- return attachment.delete()- .then(() => {- if (this.attachmentsBackend) {- this.updateAttachments();- } else {- this.attachments.count = Math.max(this.attachments.count - 1, 0);- }- })- .catch((error:any) => {- this.halNotification.handleRawError(error, this as any);- this.attachments.elements.push(attachment);- });- }- return Promise.resolve();- }-- /**- * Get updated attachments from the server and push the state- *- * Return a promise that returns the attachments. Reject, if the work package has- * no attachments.- */- public updateAttachments():Promise<HalResource> {- return this- .attachments- .updateElements()- .then(() => {- this.updateState();- return this.attachments;- });- }-- /**- * Upload the given attachments, update the resource and notify the user.- * Return an updated AttachmentCollectionResource.- */- public uploadAttachments(files:UploadFile[]):Promise<string|{ response:HalResource, uploadUrl:string }[]> {- const { uploads, finished } = this.performUpload(files);-- const message = I18n.t('js.label_upload_notification');- const notification = this.ToastService.addAttachmentUpload(message, uploads);-- return finished- .then((result:{ response:HalResource, uploadUrl:string }[]) => {- setTimeout(() => this.ToastService.remove(notification), 700);-- this.attachments.count += result.length;- result.forEach((r) => {- this.attachments.elements.push(r.response);- });- this.updateState();-- return result;- })- .catch((error:HttpErrorResponse) => {- let message:undefined|string;- console.error('Error while uploading: %O', error);-- if (error.error instanceof ErrorEvent) {- // A client-side or network error occurred.- message = this.I18n.t('js.error_attachment_upload', { error });- } else if (_.get(error, 'error._type') === 'Error') {- message = error.error.message;- } else {- // The backend returned an unsuccessful response code.- message = error.error;- }-- this.halNotification.handleRawError(message);- return message || I18n.t('js.error.internal');- });- }-- private performUpload(files:UploadFile[]) {- let href:string = this.directUploadURL || '';-- if (href) {- return this.opDirectFileUpload.uploadAndMapResponse(href, files);- } if (isNewResource(this) || !this.id || !this.attachmentsBackend) {- href = this.apiV3Service.attachments.path;- } else {- href = this.addAttachment.$link.href;- }-- return this.opFileUpload.uploadAndMapResponse(href, files);- }-- private get directUploadURL():string|null {- if (this.$links.prepareAttachment) {- return this.$links.prepareAttachment.href;- }-- if (isNewResource(this)) {- return this.config.prepareAttachmentURL;- }- return null;- }-- private updateState() {- if (this.state) {- this.state.putValue(this as any);- }- }-- public $initialize(source:any) {- if (!this.ToastService) {- this.ToastService = this.injector.get(ToastService);- }- if (!this.halNotification) {- this.halNotification = this.injector.get(HalResourceNotificationService);- }- if (!this.opFileUpload) {- this.opFileUpload = this.injector.get(OpenProjectFileUploadService);- }- if (!this.opDirectFileUpload) {- this.opDirectFileUpload = this.injector.get(OpenProjectDirectFileUploadService);- }- if (!this.config) {- this.config = this.injector.get(ConfigurationService);- }- if (!this.pathHelper) {- this.pathHelper = this.injector.get(PathHelperService);- }-- if (!this.apiV3Service) {- this.apiV3Service = this.injector.get(ApiV3Service);- }-- super.$initialize(source);-- const attachments = this.attachments || { $source: {}, elements: [] };- this.attachments = new AttachmentCollectionResource(- this.injector,- attachments,- false,- this.halInitializer,- 'HalResource',- );+ return !!((this as HalResource).$links as unknown&{ addAttachment?:HalLink }).addAttachment || isNewResource(this);}};}diff --git a/frontend/src/app/features/hal/resources/wiki-page-resource.ts b/frontend/src/app/features/hal/resources/wiki-page-resource.tsindex bfecb69f924..6da61f89e74 100644--- a/frontend/src/app/features/hal/resources/wiki-page-resource.ts+++ b/frontend/src/app/features/hal/resources/wiki-page-resource.ts@@ -35,10 +35,6 @@ export interface WikiPageResourceLinks {class WikiPageBaseResource extends HalResource {public $links:WikiPageResourceLinks;-- private attachmentsBackend = false;}export const WikiPageResource = Attachable(WikiPageBaseResource);--export type WikiPageResource = HalResource;diff --git a/frontend/src/app/features/hal/resources/work-package-resource.ts b/frontend/src/app/features/hal/resources/work-package-resource.tsindex a0677b97b2e..ef068d111c5 100644--- a/frontend/src/app/features/hal/resources/work-package-resource.ts+++ b/frontend/src/app/features/hal/resources/work-package-resource.ts@@ -35,7 +35,6 @@ import { WorkPackagesActivityService } from 'core-app/features/work-packages/comimport { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';-import { OpenProjectFileUploadService } from 'core-app/core/file-upload/op-file-upload.service';import { AttachmentCollectionResource } from 'core-app/features/hal/resources/attachment-collection-resource';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { CollectionResource } from 'core-app/features/hal/resources/collection-resource';@@ -143,8 +142,6 @@ export class WorkPackageBaseResource extends HalResource {@InjectField() pathHelper:PathHelperService;- @InjectField() opFileUpload:OpenProjectFileUploadService;-readonly attachmentsBackend = true;/**diff --git a/frontend/src/app/features/plugins/plugin-context.ts b/frontend/src/app/features/plugins/plugin-context.tsindex 865006d5555..e3d98ad4f8c 100644--- a/frontend/src/app/features/plugins/plugin-context.ts+++ b/frontend/src/app/features/plugins/plugin-context.ts@@ -15,7 +15,6 @@ import { ExternalRelationQueryConfigurationService } from 'core-app/features/worimport { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { ConfigurationService } from 'core-app/core/config/configuration.service';-import { OpenProjectFileUploadService } from 'core-app/core/file-upload/op-file-upload.service';import { EditorMacrosService } from 'core-app/shared/components/modals/editor/editor-macros.service';import { ConfirmDialogService } from 'core-app/shared/components/modals/confirm-dialog/confirm-dialog.service';import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';@@ -49,7 +48,6 @@ export class OpenProjectPluginContext {i18n: this.injector.get<I18nService>(I18nService),notifications: this.injector.get<ToastService>(ToastService),opModalService: this.injector.get<OpModalService>(OpModalService),- opFileUpload: this.injector.get<OpenProjectFileUploadService>(OpenProjectFileUploadService),displayField: this.injector.get<DisplayFieldService>(DisplayFieldService),editField: this.injector.get<EditFieldService>(EditFieldService),macros: this.injector.get<EditorMacrosService>(EditorMacrosService),diff --git a/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text-edit-field.service.ts b/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text-edit-field.service.tsindex 437da1fef54..f723e0b4c99 100644--- a/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text-edit-field.service.ts+++ b/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text-edit-field.service.ts@@ -7,9 +7,7 @@ import { SchemaResource } from 'core-app/features/hal/resources/schema-resource'import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';-import { UploadFile } from 'core-app/core/file-upload/op-file-upload.service';import { ICKEditorContext } from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';-import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { GridResource } from 'core-app/features/hal/resources/grid-resource';@Injectable()diff --git a/frontend/src/app/shared/components/toaster/toast.component.ts b/frontend/src/app/shared/components/toaster/toast.component.tsindex 77466665f5f..77c7f508705 100644--- a/frontend/src/app/shared/components/toaster/toast.component.ts+++ b/frontend/src/app/shared/components/toaster/toast.component.ts@@ -32,13 +32,6 @@ import {Input,OnInit,} from '@angular/core';-import { I18nService } from 'core-app/core/i18n/i18n.service';-import {- IToast,- ToastService,- ToastType,-} from './toast.service';-import { UploadInProgress } from 'core-app/core/file-upload/op-file-upload.service';import {BehaviorSubject,Observable,@@ -49,6 +42,9 @@ import {} from 'rxjs/operators';import { take } from 'rxjs/internal/operators/take';+import { I18nService } from 'core-app/core/i18n/i18n.service';+import { IToast, ToastService, ToastType } from 'core-app/shared/components/toaster/toast.service';+@Component({templateUrl: './toast.component.html',changeDetection: ChangeDetectionStrategy.OnPush,@@ -73,8 +69,10 @@ export class ToastComponent implements OnInit {public loading$ = new BehaviorSubject<boolean>(false);- constructor(readonly I18n:I18nService,- readonly toastService:ToastService) {+ constructor(+ readonly I18n:I18nService,+ readonly toastService:ToastService,+ ) {}ngOnInit():void {@@ -83,7 +81,7 @@ export class ToastComponent implements OnInit {this.removable = !['upload', 'loading'].includes(this.type);if (this.type === 'upload') {- const data = this.data as UploadInProgress[];+ const data = this.data as [File, Observable<unknown>];this.removable = false;this.canBeHidden = data && data.length > 5;}@@ -128,7 +126,7 @@ export class ToastComponent implements OnInit {}public get uploadText():string {- return this.I18n.t('js.label_upload_counter',- { done: this.uploadCount, count: (this.data as UploadInProgress[]).length });+ const count = (this.data as unknown[]).length;+ return this.I18n.t('js.label_upload_counter', { done: this.uploadCount, count });}}diff --git a/frontend/src/app/shared/components/toaster/toast.service.spec.ts b/frontend/src/app/shared/components/toaster/toast.service.spec.tsindex ca931eedb1e..15d2cb06b68 100644--- a/frontend/src/app/shared/components/toaster/toast.service.spec.ts+++ b/frontend/src/app/shared/components/toaster/toast.service.spec.ts@@ -32,6 +32,8 @@ import { HttpClientTestingModule } from '@angular/common/http/testing';import { ConfigurationService } from 'core-app/core/config/configuration.service';import { I18nService } from 'core-app/core/i18n/i18n.service';import { OpenprojectHalModule } from 'core-app/features/hal/openproject-hal.module';+import { Observable, of } from 'rxjs';+import { HttpEvent } from '@angular/common/http';describe('ToastService', () => {let toastService:ToastService;@@ -80,23 +82,22 @@ describe('ToastService', () => {});it('should be able to create upload messages with uploads', () => {- const toaster = toastService.addAttachmentUpload('uploading...', [0, 1, 2] as any);+ const uploadData:[File, Observable<HttpEvent<unknown>>][] = [+ [new File([], '1'), of()],+ [new File([], '2'), of()],+ [new File([], '3'), of()],+ ];+ const toaster = toastService.addUpload('uploading...', uploadData);expect(toaster).toEqual({message: 'uploading...',type: 'upload',- data: [0, 1, 2],+ data: uploadData,});});- it('should throw an Error if trying to create an upload with uploads = null', () => {- expect(() => {- toastService.addAttachmentUpload('themUploads', null as any);- }).toThrow();- });-it('should throw an Error if trying to create an upload without uploads', () => {expect(() => {- toastService.addAttachmentUpload('themUploads', []);+ toastService.addUpload('themUploads', []);}).toThrow();});diff --git a/frontend/src/app/shared/components/toaster/toast.service.ts b/frontend/src/app/shared/components/toaster/toast.service.tsindex 48bf8e6ddad..5d2a4a4b071 100644--- a/frontend/src/app/shared/components/toaster/toast.service.ts+++ b/frontend/src/app/shared/components/toaster/toast.service.ts@@ -34,7 +34,6 @@ import { HttpErrorResponse, HttpEvent } from '@angular/common/http';import { I18nService } from 'core-app/core/i18n/i18n.service';import { ConfigurationService } from 'core-app/core/config/configuration.service';-import { UploadInProgress } from 'core-app/core/file-upload/op-file-upload.service';import waitForUploadsFinished from 'core-app/core/upload/wait-for-uploads-finished';import {IHalErrorBase,@@ -141,11 +140,11 @@ export class ToastService {return this.add(this.createToast(message, 'info'));}- public addAttachmentUpload(message:IToast|string, uploads:UploadInProgress[]):IToast {- return this.add(this.createAttachmentUploadToast(message, uploads));- }-public addUpload(message:string, uploads:[File, Observable<HttpEvent<unknown>>][]):IToast {+ if (!uploads.length) {+ throw new Error('Cannot create an upload toast without uploads!');+ }+const notification = this.add({data: uploads,type: 'upload',@@ -187,17 +186,6 @@ export class ToastService {};}- private createAttachmentUploadToast(message:IToast|string, uploads:UploadInProgress[]) {- if (!uploads.length) {- throw new Error('Cannot create an upload toast without uploads!');- }-- const toast = this.createToast(message, 'upload');- toast.data = uploads;-- return toast;- }-private createLoadingToast(message:IToast|string, observable:Observable<unknown>) {const toast = this.createToast(message, 'loading');toast.data = observable;diff --git a/frontend/src/app/shared/helpers/images/resizer.ts b/frontend/src/app/shared/helpers/images/resizer.tsindex b5b01e3de7f..0fbdab6f9fa 100644--- a/frontend/src/app/shared/helpers/images/resizer.ts+++ b/frontend/src/app/shared/helpers/images/resizer.ts@@ -1,5 +1,3 @@-import { UploadBlob } from 'core-app/core/file-upload/op-file-upload.service';-function dataURItoBlob(dataURI:string) {const bytes = dataURI.split(',')[0].indexOf('base64') >= 0? atob(dataURI.split(',')[1])@@ -20,7 +18,7 @@ function dataURItoBlob(dataURI:string) {* @param {maxSize} Max width or height* @param {HTMLImageElement} Input image*/-export function resizeImage(maxSize:number, image:HTMLImageElement):[string, UploadBlob] {+export function resizeImage(maxSize:number, image:HTMLImageElement):[string, Blob] {const canvas = document.createElement('canvas');const ctx = canvas.getContext('2d')!;@@ -50,7 +48,7 @@ export function resizeImage(maxSize:number, image:HTMLImageElement):[string, Upl* @param maxSize Max width or height* @param file Input file*/-export function resizeFile(maxSize:number, file:File):Promise<[string, UploadBlob]> {+export function resizeFile(maxSize:number, file:File):Promise<[string, Blob]> {return new Promise((resolve) => {const reader = new FileReader();reader.onload = (readerEvent:ProgressEvent<FileReader>) => {