@@ -2,6 +2,7 @@ package com.jetpackduba.gitnuro.lfs
2
2
3
3
import com.jetpackduba.gitnuro.Result
4
4
import com.jetpackduba.gitnuro.models.lfs.LfsObject
5
+ import com.jetpackduba.gitnuro.models.lfs.LfsObjectBatch
5
6
import com.jetpackduba.gitnuro.models.lfs.LfsObjects
6
7
import com.jetpackduba.gitnuro.models.lfs.LfsPrepareUploadObjectBatch
7
8
import io.ktor.client.*
@@ -68,7 +69,7 @@ class LfsNetworkDataSource @Inject constructor(
68
69
remoteUrl : String ,
69
70
lfsPrepareUploadObjectBatch : LfsPrepareUploadObjectBatch ,
70
71
username : String? ,
71
- password : String?
72
+ password : String? ,
72
73
): Result <LfsObjects , LfsError > {
73
74
val response = client.post(" ${remoteUrl.removeSuffix(" /" )} /objects/batch" ) {
74
75
this .headers {
@@ -125,29 +126,20 @@ class LfsNetworkDataSource @Inject constructor(
125
126
password : String? ,
126
127
) {
127
128
val response = client.put(uploadUrl) {
128
- if (username != null && password != null ) {
129
- val objHeaders = lfsObject.actions.upload?.header
130
-
131
- if (objHeaders.isNullOrEmpty()) {
132
- basicAuth(username, password)
133
- } else {
134
- for (header in objHeaders.entries) {
135
- header(header.key, header.value)
136
- }
137
- }
138
-
129
+ val objHeaders = lfsObject.actions?.upload?.header.orEmpty()
139
130
140
- // if (authorization != null) {
141
- //
142
- // bearerAuth(authorization)
143
- // } else {
144
- // basicAuth(username, password)
145
- // }
131
+ for (header in objHeaders.entries) {
132
+ header(header.key, header.value)
146
133
}
147
134
148
135
this .headers {
149
- this [" Accept" ] = " application/vnd.git-lfs"
150
- this [" Content-Length" ] = size.toString()
136
+ if (username != null && password != null && ! headers.contains(" Authorization" )) {
137
+ basicAuth(username, password)
138
+ }
139
+
140
+ if (! this .contains(" Accept" )) {
141
+ this [" Accept" ] = " application/vnd.git-lfs"
142
+ }
151
143
}
152
144
153
145
setBody(file.readChannel())
@@ -159,26 +151,33 @@ class LfsNetworkDataSource @Inject constructor(
159
151
}
160
152
161
153
override suspend fun verify (lfsObject : LfsObject , username : String? , password : String? ) {
162
- val response = client.post(lfsObject.actions.verify!! .href) {
163
- if (username != null && password != null ) {
164
- val objHeaders = lfsObject.actions.verify?.header
154
+ val verify = lfsObject.actions?.verify
165
155
166
- if (objHeaders.isNullOrEmpty()) {
167
- basicAuth(username, password)
168
- } else {
169
- for (header in objHeaders.entries) {
170
- header(header.key, header.value)
156
+ if (verify != null ) {
157
+ val response = client.post(verify.href) {
158
+ val objHeaders = verify.header.orEmpty()
159
+
160
+ for (header in objHeaders.entries) {
161
+ header(header.key, header.value)
162
+ }
163
+
164
+ this .headers {
165
+ if (username != null && password != null && ! headers.contains(" Authorization" )) {
166
+ basicAuth(username, password)
167
+ }
168
+
169
+ if (! this .contains(" Accept" )) {
170
+ this [" Accept" ] = " application/vnd.git-lfs"
171
171
}
172
172
}
173
- }
174
173
175
- this .headers {
176
- this [ " Accept " ] = " application/vnd.git-lfs "
174
+ val body = LfsObjectBatch (lfsObject.oid, lfsObject.size)
175
+ setBody(json.encodeToString(body))
177
176
}
178
- }
179
177
180
- if (response.status != HttpStatusCode .OK ) {
181
- throw Exception (" Verify status is ${response.status} instead of HTTP OK 200" )
178
+ if (response.status != HttpStatusCode .OK ) {
179
+ throw Exception (" Verify status is ${response.status} instead of HTTP OK 200" )
180
+ }
182
181
}
183
182
}
184
183
0 commit comments