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