Skip to content

Commit

Permalink
with changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ItamarYuran committed Nov 27, 2024
1 parent 5934a42 commit c2d9149
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
3 changes: 0 additions & 3 deletions webui/src/lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,6 @@ export const uploadWithProgress = (url, file, method = 'POST', onProgress = null
});
xhr.addEventListener('load', () => {
resolve({
status: xhr.status,
body: xhr.responseText,
contentType: xhr.getResponseHeader('Content-Type'),
rawHeaders: xhr.getAllResponseHeaders(), // add raw headers
});
});
Expand Down
24 changes: 12 additions & 12 deletions webui/src/pages/repositories/repository/objects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,22 @@ function extractChecksumFromResponse(rawHeaders) {
const headersString = typeof rawHeaders === 'string' ? rawHeaders : rawHeaders.toString();
const cleanedHeadersString = headersString.trim();
const headerLines = cleanedHeadersString.split('\n');
const parsedHeaders = {};

headerLines.forEach((line) => {
const [key, value] = line.split(':', 2).map((part) => part.trim());
if (key && value) {
parsedHeaders[key.toLowerCase()] = value;
}
});

const parsedHeaders = headerLines.reduce((acc, line) => {
let [key, ...value] = line.split(':'); // split into key and the rest of the value
key = key.trim();
value = value.join(':').trim();
if (key && value) {
acc[key.toLowerCase()] = value;
}
return acc;
}, {});
if (parsedHeaders['content-md5']) {
return parsedHeaders['content-md5'];
}
// fallback to ETag
if (parsedHeaders['etag']) {
const cleanedEtag = parsedHeaders['etag'].replace(/"/g, '');
return cleanedEtag;
// drop any quote and space
return parsedHeaders['etag'].replace(/"/g, '');
}
return null;
}
Expand All @@ -259,10 +259,10 @@ const uploadFile = async (config, repo, reference, path, file, onProgress) => {
}
const getResp = await staging.get(repo.id, reference.id, fpath, config.pre_sign_support_ui);
const uploadResponse = await uploadWithProgress(getResp.presigned_url, file, 'PUT', onProgress, additionalHeaders);
const checksum = extractChecksumFromResponse(uploadResponse.rawHeaders);
if (uploadResponse.status >= 400) {
throw new Error(`Error uploading file: HTTP ${uploadResponse.status}`);
}
const checksum = extractChecksumFromResponse(uploadResponse.rawHeaders);
await staging.link(repo.id, reference.id, fpath, getResp, checksum, file.size, file.type);
} else {
await objects.upload(repo.id, reference.id, fpath, file, onProgress);
Expand Down

0 comments on commit c2d9149

Please sign in to comment.