mirror of
https://github.com/multipleof4/gitea-github-cron.git
synced 2026-10-15 16:27:53 +00:00
Sync GitHub organization avatars to Gitea
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
const syncOrgAvatar = async (org, giteaApi, headers) => {
|
||||
if (!org.avatar_url) return false;
|
||||
|
||||
const avatar = await fetch(org.avatar_url, { signal: AbortSignal.timeout(30_000) });
|
||||
if (!avatar.ok) throw new Error(`GitHub avatar download failed: ${avatar.status}`);
|
||||
|
||||
const image = Buffer.from(await avatar.arrayBuffer());
|
||||
if (!image.length) throw new Error('GitHub avatar is empty');
|
||||
|
||||
const upload = await fetch(`${giteaApi}/orgs/${encodeURIComponent(org.login)}/avatar`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({ image: image.toString('base64') }),
|
||||
signal: AbortSignal.timeout(30_000)
|
||||
});
|
||||
if (!upload.ok) throw new Error(`Gitea avatar upload failed: ${upload.status} ${await upload.text()}`);
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = syncOrgAvatar;
|
||||
Reference in New Issue
Block a user