@@ -9,6 +9,7 @@ import { AuthService } from '@dspace/core/auth/auth.service';
99import { NotificationsService } from '@dspace/core/notification-system/notifications.service' ;
1010import { HALEndpointService } from '@dspace/core/shared/hal-endpoint.service' ;
1111import { normalizeSectionData } from '@dspace/core/submission/submission-response-parsing.service' ;
12+ import { SubmissionScopeType } from '@dspace/core/submission/submission-scope-type' ;
1213import {
1314 hasValue ,
1415 isNotEmpty ,
@@ -46,14 +47,17 @@ import { SectionsService } from '../../../../sections.service';
4647 ] ,
4748} )
4849/**
49- * Modal component used inside the submission/ edit-item upload section to replace the content of
50- * an existing Bitstream without changing its metadata or its position in the bundle.
50+ * Modal component used inside the edit-item upload section to replace the content of an existing
51+ * Bitstream without changing its metadata or its position in the bundle.
5152 *
52- * The component is opened by {@link SectionUploadFileComponent} when the user clicks the
53- * "Replace" button next to a listed file. It issues a `PUT` request to
54- * `bitstreams/{uuid}/content`, the same endpoint used by {@link ReplaceBitstreamPageComponent}
55- * from the Bitstream admin tab, with an optional `replaceName` query parameter that controls
56- * whether the stored file name is updated to match the newly uploaded file.
53+ * The component is opened by {@link SectionUploadFileComponent} when the user clicks the "Replace"
54+ * button next to a listed file. It issues a `POST` multipart request to the `edititems` endpoint
55+ * (e.g. `edititems/{submissionId}?replaceFile={bitstreamUuid}&replaceName={bool}`), which is the
56+ * same endpoint used for new file uploads in the edit-item UI. The `replaceFile` parameter tells
57+ * the backend to replace the identified Bitstream rather than creating a new one.
58+ *
59+ * The replace button is intentionally hidden for fresh workspace/workflow item submissions — it is
60+ * only shown when the submission scope is {@link SubmissionScopeType.EditItem}.
5761 */
5862export class SubmissionSectionUploadFileReplaceComponent implements OnInit , OnDestroy {
5963
@@ -91,13 +95,13 @@ export class SubmissionSectionUploadFileReplaceComponent implements OnInit, OnDe
9195 * @type {UploaderOptions }
9296 */
9397 protected uploadFilesOptions : UploaderOptions = Object . assign ( new UploaderOptions ( ) , {
94- // URL needs to contain something to not produce any errors. This will be replaced once a bundle has been selected .
95- url : 'placeholder' , /* TODO Change upload URL */
98+ // URL needs to contain something to not produce any errors. This will be replaced once ready .
99+ url : 'placeholder' ,
96100 authToken : null ,
97101 disableMultipart : false ,
98102 itemAlias : null ,
99103 autoUpload : false ,
100- method : RestRequestMethod . PUT ,
104+ method : RestRequestMethod . POST ,
101105 } ) ;
102106
103107 /**
@@ -198,24 +202,32 @@ export class SubmissionSectionUploadFileReplaceComponent implements OnInit, OnDe
198202 }
199203
200204 /**
201- * Set the upload URL to the bitstream content endpoint for this specific bitstream.
202- * Uses PUT to replace the existing file content, matching the behaviour of ReplaceBitstreamPageComponent.
205+ * Set the upload URL to the edititems endpoint for this submission, which mirrors the endpoint
206+ * used for new file uploads in the edit-item UI. A `replaceFile` UUID parameter instructs the
207+ * backend to replace the identified existing Bitstream rather than creating a new one.
203208 */
204209 private setUploadUrl ( ) {
205210 this . subs . push (
206- this . halService . getEndpoint ( 'bitstreams' ) . pipe (
211+ this . halService . getEndpoint ( this . submissionService . getSubmissionObjectLinkName ( ) ) . pipe (
207212 filter ( ( href : string ) => isNotEmpty ( href ) ) ,
208213 distinctUntilChanged ( ) )
209214 . subscribe ( ( endpointURL ) => {
210215 this . uploadFilesOptions . authToken = this . authService . buildAuthHeader ( ) ;
211- this . uploadFilesUrlNoParam = `${ endpointURL } /${ this . bitstreamUuid } ` ;
216+ this . uploadFilesUrlNoParam = `${ endpointURL } /${ this . submissionId } ` ;
212217 this . setUploadUrlParameters ( ) ;
213218 } ) ,
214219 ) ;
215220 }
216221
222+ /**
223+ * Applies the `replaceFile` and `replaceName` query parameters to the upload URL and optionally
224+ * syncs the new URL into the underlying file-upload library so that a file already in the queue
225+ * picks up the latest value before the upload starts.
226+ *
227+ * @param uploader - Optional {@link UploaderComponent} whose internal options should also be updated.
228+ */
217229 protected setUploadUrlParameters ( uploader ?: UploaderComponent ) {
218- this . uploadFilesOptions . url = `${ this . uploadFilesUrlNoParam } /content? replaceName=${ this . shouldReplaceName } ` ;
230+ this . uploadFilesOptions . url = `${ this . uploadFilesUrlNoParam } ?replaceFile= ${ this . bitstreamUuid } & replaceName=${ this . shouldReplaceName } ` ;
219231 if ( hasValue ( uploader ?. uploader ?. options ) ) {
220232 uploader . uploader . options . url = this . uploadFilesOptions . url ;
221233 }
0 commit comments