-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
202 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Buy me a coffee | ||
// | ||
// https://developers.buymeacoffee.com/ | ||
|
||
import { SecretKeys, fetchResponse } from '@flyxc/common'; | ||
|
||
export type Supporters = { | ||
// visible supporters | ||
names: Set<string>; | ||
// all supporters | ||
numSupporters: number; | ||
// total amount | ||
totalAmount: number; | ||
}; | ||
|
||
export async function fetchSupporters(): Promise<Supporters> { | ||
const supporters: Supporters = { | ||
names: new Set<string>(), | ||
numSupporters: 0, | ||
totalAmount: 0, | ||
}; | ||
let url = `https://developers.buymeacoffee.com/api/v1/supporters`; | ||
try { | ||
while (url) { | ||
const response = await fetchResponse(url, { | ||
headers: { | ||
Authorization: `Bearer ${SecretKeys.BUY_ME_A_COFFEE_TOKEN}`, | ||
}, | ||
}); | ||
if (response.ok) { | ||
const data = await response.json(); | ||
const users = data.data; | ||
for (const user of users) { | ||
if (user.amount <= 0) { | ||
continue; | ||
} | ||
if (user.support_visibility === 1 && user.payer_name) { | ||
supporters.names.add(user.payer_name); | ||
} | ||
supporters.numSupporters++; | ||
supporters.totalAmount += user.support_coffees * user.support_coffee_price; | ||
} | ||
url = data.next_page_url; | ||
} else { | ||
url = null; | ||
} | ||
} | ||
} catch (error) { | ||
console.error('Buy me a coffee API error!', error); | ||
} | ||
return supporters; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { html, LitElement, TemplateResult } from 'lit'; | ||
import { customElement } from 'lit/decorators.js'; | ||
|
||
import { modalController } from '@ionic/core/components'; | ||
import { fetchResponse } from '@flyxc/common'; | ||
|
||
@customElement('supporter-modal') | ||
export class SupporterModal extends LitElement { | ||
private supporters = { names: [], amount: 0, number: 0 }; | ||
|
||
async connectedCallback(): Promise<void> { | ||
super.connectedCallback(); | ||
try { | ||
const response = await fetchResponse('/api/supporters.json'); | ||
if (response.ok) { | ||
this.supporters = await response.json(); | ||
this.requestUpdate(); | ||
} | ||
} catch (e) { | ||
// do nothing | ||
} | ||
} | ||
|
||
render(): TemplateResult { | ||
return html`<ion-header> | ||
<ion-toolbar color="light"> | ||
<ion-title>Support flyxc.app</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-text color="dark"> | ||
<p> | ||
flyxc (formerly VisuGps) has always been | ||
<a href="https://github.com/vicb/visugps" target="_blank">open-source</a> and free to use since 2007. | ||
</p> | ||
<p>The development effort represents hundreds of hours per year and hosting flyxc cost about $10 a month.</p> | ||
<p> | ||
If you can afford it, please consider supporting flyxc with a small donation by clicking the button below. | ||
It will help keep me motivated to maintain and improve it. | ||
</p> | ||
</ion-text> | ||
<a href="https://www.buymeacoffee.com/vic.b" target="_blank" | ||
><img | ||
src="https://cdn.buymeacoffee.com/buttons/default-orange.png" | ||
alt="Buy Me A Coffee" | ||
height="41" | ||
width="174" | ||
/></a> | ||
<p> | ||
<ion-text color="dark" | ||
>Thanks to the ${this.supporters.number} supporters who have contributed a total of | ||
$${this.supporters.amount}: | ||
<ul> | ||
${this.supporters.names.map((n) => html`<li>${n}</li>`)} | ||
</ul> | ||
</ion-text> | ||
</p> | ||
</ion-content> | ||
<ion-footer> | ||
<ion-toolbar color="light"> | ||
<ion-buttons slot="primary"> | ||
<ion-button @click=${this.dismiss}>Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-footer>`; | ||
} | ||
|
||
protected createRenderRoot(): HTMLElement { | ||
return this; | ||
} | ||
|
||
private async dismiss(): Promise<void> { | ||
const modal = await modalController.getTop(); | ||
await modal?.dismiss(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Keys } from '@flyxc/common'; | ||
import { Request, Response, Router } from 'express'; | ||
import { Redis } from 'ioredis'; | ||
|
||
export function getSupportersRouter(redis: Redis): Router { | ||
const router = Router(); | ||
|
||
// Returns the airspaces info for the first track in the group as JSON. | ||
// Returns 404 if the info are not available (/not ready yet). | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
router.get('/supporters.json', async (req: Request, res: Response) => { | ||
try { | ||
const [names, number, amount] = ( | ||
await redis | ||
.pipeline() | ||
.lrange(Keys.supporterNames, 0, 100) | ||
.get(Keys.supporterNum) | ||
.get(Keys.supporterAmount) | ||
.exec() | ||
).map(([_, v]) => v); | ||
return res.json({ names, number, amount }); | ||
} catch (error) { | ||
return res.sendStatus(500); | ||
} | ||
}); | ||
|
||
return router; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters