mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-15 09:04:04 +02:00
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { readFile } from 'fs-extra';
|
|
import { getRootDir } from '@joplin/utils';
|
|
import { fetchWithRetry } from '@joplin/utils/net';
|
|
import { githubOauthToken } from '../tool-utils';
|
|
|
|
export interface GithubSponsor {
|
|
name: string;
|
|
id: string;
|
|
}
|
|
|
|
export interface Sponsors {
|
|
github: GithubSponsor[];
|
|
orgs: OrgSponsor[];
|
|
}
|
|
|
|
export interface OrgSponsor {
|
|
url: string;
|
|
urlWebsite?: string;
|
|
title: string;
|
|
imageName: string;
|
|
}
|
|
|
|
export const loadSponsors = async (): Promise<Sponsors> => {
|
|
const sponsorsPath = `${await getRootDir()}/packages/tools/sponsors.json`;
|
|
const output: Sponsors = JSON.parse(await readFile(sponsorsPath, 'utf8'));
|
|
|
|
output.orgs = output.orgs.map(o => {
|
|
if (o.urlWebsite) o.url = o.urlWebsite;
|
|
return o;
|
|
});
|
|
|
|
const oauthToken = await githubOauthToken();
|
|
|
|
for (const ghSponsor of output.github) {
|
|
const userResponse = await fetchWithRetry(`https://api.github.com/users/${ghSponsor.name}`, {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `token ${oauthToken}`,
|
|
},
|
|
});
|
|
|
|
if (!userResponse.ok) throw new Error(await userResponse.text());
|
|
const user = await userResponse.json();
|
|
ghSponsor.id = user.id;
|
|
}
|
|
|
|
return output;
|
|
};
|