in operations/codeup/files.ts [165:211]
export async function updateFileFunc(
organizationId: string,
repositoryId: string,
filePath: string,
content: string,
commitMessage: string,
branch: string,
encoding?: string
): Promise<z.infer<typeof CreateFileResponseSchema>> {
//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("/")) {
const pathToEncode = filePath.startsWith("/") ? filePath.substring(1) : filePath;
encodedFilePath = encodeURIComponent(pathToEncode);
}
const url = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files/${encodedFilePath}`;
const body = {
branch: branch,
commitMessage: commitMessage,
content: content,
encoding: encoding || "text" // 默认使用text编码
};
const response = await yunxiaoRequest(url, {
method: "PUT",
body: body
});
return CreateFileResponseSchema.parse(response);
}