Skip to content

Commit

Permalink
fix: 油猴脚本在火狐的 headers 解析不正确
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 8, 2023
1 parent 383dd51 commit 93c3d1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
41 changes: 20 additions & 21 deletions src/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,26 @@ type UploadPoliciesAssetsRsonpse = {
export const uploadPoliciesAssets = async (
bf: ArrayBuffer,
): Promise<GithubPoliciesAsset> => {
const [name, content_type] = (() => {
if (isPngBf(bf)) {
return [`file.png`, `image/png`];
} else if (isZipBf(bf)) {
return [`file.zip`, `application/x-zip-compressed`];
}
throw new Error(`invalid buffer, it must be png or zip`);
})();
const file = new File([bf], name, { type: content_type });
const resp = await fetch(
'https://github-upload-assets.lisonge.workers.dev/',
{
method: 'POST',
body: obj2form({ file }),
},
);
const xRpcOk = resp.headers.get('X_RPC_OK');
if (xRpcOk === 'true') {
return resp.json();
}
// 如果上传失败, 使用油猴脚本上传
// const [name, content_type] = (() => {
// if (isPngBf(bf)) {
// return [`file.png`, `image/png`];
// } else if (isZipBf(bf)) {
// return [`file.zip`, `application/x-zip-compressed`];
// }
// throw new Error(`invalid buffer, it must be png or zip`);
// })();
// const file = new File([bf], name, { type: content_type });
// const resp = await fetch(
// 'https://github-upload-assets.lisonge.workers.dev/',
// {
// method: 'POST',
// body: obj2form({ file }),
// },
// );
// const xRpcOk = resp.headers.get('X_RPC_OK');
// if (xRpcOk === 'true') {
// return resp.json();
// }
return uploadPoliciesAssetsByExtension(bf);
};

Expand Down
5 changes: 4 additions & 1 deletion src/utils/gm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export const parseHeaders = (rawHeaders = '') => {
let key = parts.shift()?.trim();
if (key) {
let value = parts.join(':').trim();
headers.append(key, value);
try {
// https://github.com/gkd-kit/subscription/pull/762#discussion_r1349695154
headers.append(key, value);
} catch {}
}
});
return headers;
Expand Down

0 comments on commit 93c3d1a

Please sign in to comment.