feat(overview-artifact): 產生可預覽總覽與截圖 fallback
This commit is contained in:
@@ -422,6 +422,31 @@ export async function giteaRequest(login, method, path, { body, query } = {}) {
|
||||
const text = await response.text();
|
||||
return { status: response.status, body: text ? safeJson(text) : null };
|
||||
}
|
||||
/**
|
||||
* 上傳 Gitea issue attachment。這是唯一的 multipart HTTP 出口。
|
||||
* @param {{base:string, token:string}} login
|
||||
* @param {string} path
|
||||
* @param {string} filePath
|
||||
* @param {string} fileName
|
||||
* @returns {Promise<{status:number, body:any}>}
|
||||
*/
|
||||
export async function giteaUpload(login, path, filePath, fileName) {
|
||||
const form = new FormData();
|
||||
form.append('attachment', new Blob([readFileSync(filePath)]), fileName);
|
||||
const url = new URL(`${login.base}${path}`);
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `token ${login.token}`, Accept: 'application/json' },
|
||||
body: form,
|
||||
});
|
||||
} catch (cause) {
|
||||
throw new ScriptError('NETWORK_ERROR', `連不上 Gitea(POST ${path}):${cause.message}`);
|
||||
}
|
||||
const text = await response.text();
|
||||
return { status: response.status, body: safeJson(text) };
|
||||
}
|
||||
|
||||
/**
|
||||
* 把「非預期狀態碼」收斂成帶狀態碼的錯誤,成功則回傳 body。
|
||||
|
||||
Reference in New Issue
Block a user