@@ -7,6 +7,14 @@ $(function() {
7
7
) ;
8
8
} ) ;
9
9
10
+ // ASYNC UPLOAD LOGIC
11
+ const getPathPrefix = ( ) => {
12
+ const hostname = window . location . hostname
13
+ const subdomain = hostname . split ( '.' ) [ 0 ] ;
14
+ return subdomain === 'localhost' ? '' : '/gids'
15
+ } ;
16
+ const PATH_PREFIX = getPathPrefix ( ) ; ;
17
+
10
18
// Open dialog during initial async upload to disable page
11
19
$ ( "#async-upload-dialog" ) . dialog ( {
12
20
autoOpen : false ,
@@ -53,7 +61,7 @@ $(function() {
53
61
$ ( icon ) . off ( "click mouseleave" ) ;
54
62
try {
55
63
await $ . ajax ( {
56
- url : `/uploads/${ uploadId } /cancel` ,
64
+ url : `${ PATH_PREFIX } /uploads/${ uploadId } /cancel` ,
57
65
type : "PATCH" ,
58
66
contentType : false ,
59
67
processData : false ,
@@ -79,7 +87,7 @@ $(function() {
79
87
const { uploadId, csvType } = $ ( this ) . data ( ) ;
80
88
$ ( this ) . html (
81
89
`<p>${ csvType } file upload complete</p>` +
82
- '<p>Click ' + `<a href="/uploads/${ uploadId } ">here</a>` +
90
+ '<p>Click ' + `<a href="${ PATH_PREFIX } /uploads/${ uploadId } ">here</a>` +
83
91
' for a more detailed report</p>'
84
92
) ;
85
93
}
@@ -100,7 +108,7 @@ $(function() {
100
108
try {
101
109
const xhr = new XMLHttpRequest ( ) ;
102
110
const getUploadStatus = ( ) => {
103
- xhr . open ( "GET" , `/uploads/${ uploadId } /status` ) ;
111
+ xhr . open ( "GET" , `${ PATH_PREFIX } /uploads/${ uploadId } /status` ) ;
104
112
xhr . send ( ) ;
105
113
} ;
106
114
xhr . onload = function ( ) {
@@ -139,7 +147,7 @@ $(function() {
139
147
$ ( uploadStatusDiv ) . html ( capitalize ( ok ? "succeeded" : "failed" , titlecase ) ) ;
140
148
}
141
149
// If on upload#show page, reload page to render flash alerts
142
- if ( window . location . pathname === `/uploads/${ uploadId } ` ) {
150
+ if ( window . location . pathname === `${ PATH_PREFIX } /uploads/${ uploadId } ` ) {
143
151
window . location . reload ( ) ;
144
152
// Otherwise render link to alerts in pop dialog
145
153
} else if ( ! canceled ) {
@@ -228,7 +236,7 @@ $(function() {
228
236
formData . set ( "upload[metadata][count][current]" , i + 1 ) ;
229
237
formData . set ( "upload[metadata][count][total]" , blobs . length ) ;
230
238
const response = await $ . ajax ( {
231
- url : " /uploads" ,
239
+ url : ` ${ PATH_PREFIX } /uploads` ,
232
240
type : "POST" ,
233
241
data : formData ,
234
242
dataType : "json" ,
@@ -239,10 +247,10 @@ $(function() {
239
247
}
240
248
// If successful, save upload ID in local storage to enable status polling
241
249
addToQueue ( uploadId ) ;
242
- window . location . href = `/uploads/${ uploadId } ` ;
250
+ window . location . href = `${ PATH_PREFIX } /uploads/${ uploadId } ` ;
243
251
} catch ( error ) {
244
252
console . error ( error ) ;
245
- window . location . href = `/uploads/new/${ csvType } ` ;
253
+ window . location . href = `${ PATH_PREFIX } /uploads/new/${ csvType } ` ;
246
254
}
247
255
} ;
248
256
0 commit comments