in operations/codeup/files.ts [56:97]
export async function getFileBlobsFunc(
organizationId: string,
repositoryId: string,
filePath: string,
ref: string
): Promise<z.infer<typeof FileContentSchema>> {
// const { encodedRepoId, encodedFilePath } = handlePathEncoding(repositoryId, filePath);
let encodedRepoId = repositoryId;
let encodedFilePath = filePath;
// 自动处理repositoryId中未编码的斜杠
if (repositoryId.includes("/")) {
// 发现未编码的斜杠,自动进行URL编码
const parts = repositoryId.split("/", 2);
if (parts.length === 2) {
const encodedRepoName = encodeURIComponent(parts[1]);
// 移除编码中的+号(空格被编码为+,但我们需要%20)
const formattedEncodedName = encodedRepoName.replace(/\+/g, "%20");
encodedRepoId = `${parts[0]}%2F${formattedEncodedName}`;
}
}
// 确保filePath已被URL编码
if (filePath.includes("/")) {
encodedFilePath = encodeURIComponent(filePath);
}
const baseUrl = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files/${encodedFilePath}`;
// 构建查询参数
const queryParams: Record<string, string | number | undefined> = {
ref: ref
};
// 使用buildUrl函数构建包含查询参数的URL
const url = buildUrl(baseUrl, queryParams);
const response = await yunxiaoRequest(url, {
method: "GET",
});
return FileContentSchema.parse(response);
}