mirror of
https://github.com/woodchen-ink/docker-image.git
synced 2025-07-18 14:01:59 +08:00
修复错误
This commit is contained in:
parent
af3de52fc9
commit
d1eba7746d
@ -115,7 +115,7 @@ function getHomePageHtml(): string {
|
|||||||
function generateCommands() {
|
function generateCommands() {
|
||||||
const imageInput = document.getElementById('imageInput').value;
|
const imageInput = document.getElementById('imageInput').value;
|
||||||
const source = getSourceFromImage(imageInput);
|
const source = getSourceFromImage(imageInput);
|
||||||
const imageName = getImageNameFromInput(imageInput);
|
const imageName = getImageNameFromInput(imageInput, source);
|
||||||
const dockerPullCommand = \`docker pull \${source}/\${imageName}\`;
|
const dockerPullCommand = \`docker pull \${source}/\${imageName}\`;
|
||||||
const dockerTagCommand = \`docker tag \${source}/\${imageName} \${imageName}\`;
|
const dockerTagCommand = \`docker tag \${source}/\${imageName} \${imageName}\`;
|
||||||
const dockerRmiCommand = \`docker rmi \${source}/\${imageName}\`;
|
const dockerRmiCommand = \`docker rmi \${source}/\${imageName}\`;
|
||||||
@ -140,8 +140,18 @@ function getHomePageHtml(): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getImageNameFromInput(imageInput) {
|
function getImageNameFromInput(imageInput, source) {
|
||||||
return imageInput.replace(/^.+?\\//, '');
|
if (imageInput.startsWith("gcr.io/")) {
|
||||||
|
return imageInput.replace("gcr.io/", "");
|
||||||
|
} else if (imageInput.startsWith("k8s.gcr.io/")) {
|
||||||
|
return imageInput.replace("k8s.gcr.io/", "");
|
||||||
|
} else if (imageInput.startsWith("quay.io/")) {
|
||||||
|
return imageInput.replace("quay.io/", "");
|
||||||
|
} else if (imageInput.startsWith("ghcr.io/")) {
|
||||||
|
return imageInput.replace("ghcr.io/", "");
|
||||||
|
} else {
|
||||||
|
return imageInput;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyToClipboard(elementId) {
|
function copyToClipboard(elementId) {
|
||||||
@ -163,7 +173,7 @@ const PROXY_HEADER_ALLOW_LIST: string[] = ["accept", "user-agent", "accept-encod
|
|||||||
|
|
||||||
const validActionNames = new Set(["manifests", "blobs", "tags", "referrers"])
|
const validActionNames = new Set(["manifests", "blobs", "tags", "referrers"])
|
||||||
|
|
||||||
const ORG_NAME_BACKEND:{ [key: string]: string; } = {
|
const ORG_NAME_BACKEND: { [key: string]: string; } = {
|
||||||
"gcr": "https://gcr.io",
|
"gcr": "https://gcr.io",
|
||||||
"k8sgcr": "https://k8s.gcr.io",
|
"k8sgcr": "https://k8s.gcr.io",
|
||||||
"quay": "https://quay.io",
|
"quay": "https://quay.io",
|
||||||
@ -184,9 +194,9 @@ export async function handleRequest(request: Request): Promise<Response> {
|
|||||||
return handleRegistryRequest(request)
|
return handleRegistryRequest(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyProxyHeaders(inputHeaders: Headers) : Headers {
|
function copyProxyHeaders(inputHeaders: Headers): Headers {
|
||||||
const headers = new Headers;
|
const headers = new Headers;
|
||||||
for(const pair of inputHeaders.entries()) {
|
for (const pair of inputHeaders.entries()) {
|
||||||
if (PROXY_HEADER_ALLOW_LIST.includes(pair[0].toLowerCase())) {
|
if (PROXY_HEADER_ALLOW_LIST.includes(pair[0].toLowerCase())) {
|
||||||
headers.append(pair[0], pair[1])
|
headers.append(pair[0], pair[1])
|
||||||
}
|
}
|
||||||
@ -194,7 +204,7 @@ function copyProxyHeaders(inputHeaders: Headers) : Headers {
|
|||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
function orgNameFromPath(pathname: string): string|null {
|
function orgNameFromPath(pathname: string): string | null {
|
||||||
const splitedPath: string[] = pathname.split("/", 3)
|
const splitedPath: string[] = pathname.split("/", 3)
|
||||||
if (splitedPath.length === 3 && splitedPath[0] === "" && splitedPath[1] === "v2") {
|
if (splitedPath.length === 3 && splitedPath[0] === "" && splitedPath[1] === "v2") {
|
||||||
return splitedPath[2].toLowerCase()
|
return splitedPath[2].toLowerCase()
|
||||||
@ -202,7 +212,7 @@ function orgNameFromPath(pathname: string): string|null {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
function hostByOrgName(orgName: string|null): string {
|
function hostByOrgName(orgName: string | null): string {
|
||||||
if (orgName !== null && orgName in ORG_NAME_BACKEND) {
|
if (orgName !== null && orgName in ORG_NAME_BACKEND) {
|
||||||
return ORG_NAME_BACKEND[orgName]
|
return ORG_NAME_BACKEND[orgName]
|
||||||
}
|
}
|
||||||
@ -222,7 +232,7 @@ function rewritePath(orgName: string | null, pathname: string): string {
|
|||||||
return pathname
|
return pathname
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanSplitedPath = splitedPath.filter(function(value: string, index: number) {
|
const cleanSplitedPath = splitedPath.filter(function (value: string, index: number) {
|
||||||
return value !== orgName || index !== 2;
|
return value !== orgName || index !== 2;
|
||||||
})
|
})
|
||||||
return cleanSplitedPath.join("/")
|
return cleanSplitedPath.join("/")
|
||||||
@ -236,5 +246,5 @@ async function handleRegistryRequest(request: Request): Promise<Response> {
|
|||||||
const tokenProvider = new TokenProvider()
|
const tokenProvider = new TokenProvider()
|
||||||
const backend = new Backend(host, tokenProvider)
|
const backend = new Backend(host, tokenProvider)
|
||||||
const headers = copyProxyHeaders(request.headers)
|
const headers = copyProxyHeaders(request.headers)
|
||||||
return backend.proxy(pathname, {headers: request.headers})
|
return backend.proxy(pathname, { headers: request.headers })
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user