fix:锁定文件只读
This commit is contained in:
@@ -424,11 +424,41 @@ export async function getScriptContent(
|
||||
content: string | object;
|
||||
format: string;
|
||||
}> {
|
||||
return apiRequest(
|
||||
`/api/v1/scripts/${scriptId}/content`,
|
||||
{},
|
||||
workspaceId,
|
||||
).then((envelope) => (envelope as Record<string, any>).data);
|
||||
const response = await fetch(
|
||||
`/api/v1/scripts/${scriptId}/content?workspace_id=${encodeURIComponent(workspaceId)}`,
|
||||
{
|
||||
credentials: "same-origin",
|
||||
headers: {
|
||||
"X-Request-ID": createUuid().replaceAll("-", ""),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status === 401 && typeof window !== "undefined") {
|
||||
const here = window.location.pathname;
|
||||
if (here !== "/login") {
|
||||
window.location.assign("/login");
|
||||
}
|
||||
throw new ApiRequestError("未登录或登录已过期", 401);
|
||||
}
|
||||
|
||||
const payload = await response.json();
|
||||
if (!response.ok) {
|
||||
const error = payload as ApiErrorEnvelope;
|
||||
const detailMessage = typeof error.detail === "string"
|
||||
? error.detail
|
||||
: error.detail?.message;
|
||||
throw new ApiRequestError(
|
||||
detailMessage ?? `请求失败(HTTP ${response.status})`,
|
||||
response.status,
|
||||
);
|
||||
}
|
||||
|
||||
const data = (payload as { data: { script_id: string; script_type: ScriptType; content: string | object; format: string } }).data;
|
||||
if (!data || !data.script_type) {
|
||||
throw new ApiRequestError("响应数据格式错误", response.status);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function deleteScript(
|
||||
|
||||
Reference in New Issue
Block a user