accept more media types
This commit is contained in:
		
							
								
								
									
										17
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										17
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| @@ -2859,6 +2859,7 @@ const https = __nccwpck_require__(687); | ||||
|  | ||||
| const req_timeout_ms = 30_000; | ||||
| const manifest_media_type = 'application/vnd.docker.distribution.manifest.v2+json'; | ||||
| const image_index_media_type = 'application/vnd.oci.image.index.v1+json'; | ||||
|  | ||||
| main(); | ||||
|  | ||||
| @@ -2911,7 +2912,7 @@ function parse_tags(tags) { | ||||
| async function get_manifest(input) { | ||||
| 	const path = `/v2/${input.manifest.image}/manifests/${input.manifest.tag}`; | ||||
| 	const req_headers = { | ||||
| 		accept: manifest_media_type, | ||||
| 		accept: `${manifest_media_type}, ${image_index_media_type}`, | ||||
| 	}; | ||||
|  | ||||
| 	http_basic_auth(req_headers, input); | ||||
| @@ -2932,16 +2933,18 @@ async function get_manifest(input) { | ||||
| 		throw new Error('failed to fetch existing manifest'); | ||||
| 	} | ||||
|  | ||||
| 	console.log('get manifest response', { status, headers, body }); | ||||
| 	return body; | ||||
| 	return { | ||||
| 		content: body, | ||||
| 		type: headers['content-type'], | ||||
| 		length: headers['content-length'], | ||||
| 	}; | ||||
| } | ||||
|  | ||||
| async function put_manifest(new_tag, manifest, input) { | ||||
| 	const path = `/v2/${input.manifest.image}/manifests/${new_tag}`; | ||||
| 	const content = Buffer.from(manifest, 'utf8'); | ||||
| 	const req_headers = { | ||||
| 		'content-type': manifest_media_type, | ||||
| 		'content-length': content.byteLength, | ||||
| 		'content-type': manifest.type, | ||||
| 		'content-length': manifest.length, | ||||
| 	}; | ||||
|  | ||||
| 	http_basic_auth(req_headers, input); | ||||
| @@ -2950,7 +2953,7 @@ async function put_manifest(new_tag, manifest, input) { | ||||
| 	// 	req_headers.authorization = `Bearer ${input.token}`; | ||||
| 	// } | ||||
|  | ||||
| 	const { status, headers, body } = await http_req('PUT', input.registry_url + path, req_headers, content); | ||||
| 	const { status, headers, body } = await http_req('PUT', input.registry_url + path, req_headers, manifest.content); | ||||
|  | ||||
| 	if (status >= 400) { | ||||
| 		console.error('put manifest response', { status, headers, body }); | ||||
|   | ||||
							
								
								
									
										2
									
								
								dist/index.js.map
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js.map
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										17
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								index.js
									
									
									
									
									
								
							| @@ -6,6 +6,7 @@ const https = require('https'); | ||||
|  | ||||
| const req_timeout_ms = 30_000; | ||||
| const manifest_media_type = 'application/vnd.docker.distribution.manifest.v2+json'; | ||||
| const image_index_media_type = 'application/vnd.oci.image.index.v1+json'; | ||||
|  | ||||
| main(); | ||||
|  | ||||
| @@ -58,7 +59,7 @@ function parse_tags(tags) { | ||||
| async function get_manifest(input) { | ||||
| 	const path = `/v2/${input.manifest.image}/manifests/${input.manifest.tag}`; | ||||
| 	const req_headers = { | ||||
| 		accept: manifest_media_type, | ||||
| 		accept: `${manifest_media_type}, ${image_index_media_type}`, | ||||
| 	}; | ||||
|  | ||||
| 	http_basic_auth(req_headers, input); | ||||
| @@ -79,16 +80,18 @@ async function get_manifest(input) { | ||||
| 		throw new Error('failed to fetch existing manifest'); | ||||
| 	} | ||||
|  | ||||
| 	console.log('get manifest response', { status, headers, body }); | ||||
| 	return body; | ||||
| 	return { | ||||
| 		content: body, | ||||
| 		type: headers['content-type'], | ||||
| 		length: headers['content-length'], | ||||
| 	}; | ||||
| } | ||||
|  | ||||
| async function put_manifest(new_tag, manifest, input) { | ||||
| 	const path = `/v2/${input.manifest.image}/manifests/${new_tag}`; | ||||
| 	const content = Buffer.from(manifest, 'utf8'); | ||||
| 	const req_headers = { | ||||
| 		'content-type': manifest_media_type, | ||||
| 		'content-length': content.byteLength, | ||||
| 		'content-type': manifest.type, | ||||
| 		'content-length': manifest.length, | ||||
| 	}; | ||||
|  | ||||
| 	http_basic_auth(req_headers, input); | ||||
| @@ -97,7 +100,7 @@ async function put_manifest(new_tag, manifest, input) { | ||||
| 	// 	req_headers.authorization = `Bearer ${input.token}`; | ||||
| 	// } | ||||
|  | ||||
| 	const { status, headers, body } = await http_req('PUT', input.registry_url + path, req_headers, content); | ||||
| 	const { status, headers, body } = await http_req('PUT', input.registry_url + path, req_headers, manifest.content); | ||||
|  | ||||
| 	if (status >= 400) { | ||||
| 		console.error('put manifest response', { status, headers, body }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user