Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlacePage donations #88

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
.wrangler/
# Autogenerated by esbuild.
workers-site/index.js
node_modules/
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ npm i

Use `npx wrangler dev` for localhost development and for testing using Cloudflare dev tools.

```
curl -H "X-OM-DataVersion: 241001" -H "X-OM-AppVersion: 2024.10.22-10-Google" -H 'Accept-Language: fr-FR' http://localhost:8787/maps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Какая вероятность возмущённых комментов по поводу сбора дополнительной инфы о юзерах при добавлении отправки ещё одного хидера на сервер в открытых PR в основной репо? Можно ли без этого обойтись, чтобы не привлекать ненужное внимание к уже отправляющимся хидерам?

Copy link
Collaborator

@kirylkaveryn kirylkaveryn Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@biodranik если не слать локаль, то придется каждому юзеру качать всю эту инфу в полном объеме для всех языков (все переводы и все продукты) и фильтровать ее уже на этапе парсинга данных на устройстве. Если там будет много стран, то json будет приличный... да и не зачем на девайс приходить тому что не нужно...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Значение страны юзера уже есть в заголовках хидеров CloudFlare. Можно просто взять и использовать if (cf.country == 'France'). Чем явная передача с клиента лучше?
  2. Чем передача строчек переводов с сервера лучше явного вбивания их на клиенте через strings.txt?

Copy link
Collaborator

@kirylkaveryn kirylkaveryn Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. если есть возможность не слать с клиента было бы лучше конечно!
  2. строки промоушен текста+продукты и их ссылки такая инфа которую бы хорошо менять динамически отвязавшись от апдейта приложения и не ожидая весь цикл разработка-ревью-установка юзером (может занять месяц/ы). Пока у нас карты не обновляются так, но я думаю что в будущем мы и это сделаем! Можно settings чекать при каждом запуске и всегда иметь up to date содержание баннера, постепенно добавлять страны и конфигуровать текста гибче. - например к какому-нибудь празднику как с елочкой у нас).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Не слать легко, но придётся сразу выбрать тексты и переводы для всех языков, или при необходимости выкатить обновление.
  2. Не очень понял про продукты. Разве тут не достаточно получения списка цен и его отображения (а потом передачи значений в виде параметров при клике)? Самое простое было бы "что пришло в жсоне, то и показать, и то отправить назад". Например, прилетело $ 20 для кнопки, оно и отображается, а на сервер улетает что-то вроде https://url/buttonclicked?value=$%2020.
  3. Чекать при каждом запуске пока не стоит, ОМ не ходит лишний раз в интернет, и это хорошо, т.к. не привлекает внимания provacy-focused community.
  4. Нам не нужно спамить юзеров сразу после установки ОМ, наоборот, лучше показывать только тогда, когда человек действительно пользуется некоторое время. Поэтому не вижу проблем из-за задержек (если изначальные тексты составлены достаточно хорошо).

```

## Update node dependencies to their major versions

```bash
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"scripts": {
"build": "esbuild src/index.ts --bundle --outfile=dist/index.js",
"test": "jest",
"format": "prettier --write '{src,test}/**/*.{ts,tsx}' '*.json' '*.toml' '.github/**/*.yml'",
"format:ci": "prettier --check '{src,test}/**/*.{ts,tsx}' '*.json' '*.toml' '.github/**/*.yml'",
"format": "prettier --write '{src,test}/**/*.{ts,tsx,json}' '*.json' '*.toml' '.github/**/*.yml'",
"format:ci": "prettier --check '{src,test}/**/*.{ts,tsx,json}' '*.json' '*.toml' '.github/**/*.yml'",
"upgrade": "npx npm-check-updates -u && npm install",
"logs": "npx wrangler tail --env prod --format json"
},
Expand Down
44 changes: 44 additions & 0 deletions src/locales.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"en": {
"placePagePrompt": "Organic Maps app is free for everyone, thanks to your donations. No ads. No trackers. Open source.",
"perMonth": "/month",
"perYear": "/year",
"otherAmount": "Other"
},
"de": {
"placePagePrompt": "Organic Maps ist dank deiner Spenden für alle kostenlos. Keine Werbung. Keine Tracker. Open Source.",
"perMonth": "/Monat",
"perYear": "/Jahr",
"otherAmount": "Andere"
},
"fr": {
"placePagePrompt": "L'application Organic Maps est gratuite pour tout le monde grâce à vos dons. Pas de publicité. Pas de trackers. Open-source.",
"perMonth": "/mois",
"perYear": "/an",
"otherAmount": "Autre"
},
"nl": {
"placePagePrompt": "De Organic Maps app is gratis voor iedereen dankzij jullie donaties. Geen advertenties. Geen trackers. Open-source.",
"perMonth": "/maand",
"perYear": "/jaar",
"otherAmount": "Ander"
},
"it": {
"placePagePrompt": "L'app Organic Maps è gratuita per tutti grazie alle vostre donazioni. Nessuna pubblicità. Nessun tracker. Open-source.",
"perMonth": "/mese",
"perYear": "/anno",
"otherAmount": "Altro"
},
"es": {
"placePagePrompt": "Organic Maps es gratis para todos gracias a sus donaciones. Sin anuncios. Sin rastreadores. Código abierto.",
"perMonth": "/mes",
"perYear": "/año",
"otherAmount": "Otro"
},
"pt": {
"placePagePrompt": "O app Organic Maps é gratuito para todos graças às suas doações. Sem anúncios. Sem rastreadores. Código aberto.",
"perMonth": "/mês",
"perYear": "/ano",
"otherAmount": "Outro"
}
}
15 changes: 15 additions & 0 deletions src/locales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import LOCALES_JSON from './locales.json';

export interface Locale {
placePagePrompt: string;
perMonth: string;
perYear: string;
otherAmount: string;
}

export interface Locales {
[key: string]: Locale;
}

const LOCALES = LOCALES_JSON as Locales;
export default LOCALES;
198 changes: 198 additions & 0 deletions src/products.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
{
"FR": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"DE": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"NL": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"IT": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"ES": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"PT": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"BE": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"AT": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"LU": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"MC": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"AD": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"SM": [
{
"title": "4,99€$per_month",
"link": "https://donate.stripe.com/6oEg2912f2c81r200j"
},
{
"title": "34,99€$per_year",
"link": "https://donate.stripe.com/eVa2bjdP19EA0mY6oI"
},
{
"title": "$other",
"link": "https://donate.stripe.com/28odU16mzg2Yc5GfYY"
}
],
"GB": [
{
"title": "£4.99$per_month",
"link": "https://donate.stripe.com/8wMg29fX98Awd9K28u"
},
{
"title": "£34.99$per_year",
"link": "https://donate.stripe.com/eVabLT9yL2c89Xy7sP"
},
{
"title": "$other",
"link": "https://donate.stripe.com/6oE7vD26j3gc2v69AC"
}
],
"US": [
{
"title": "$5.49$per_month",
"link": "https://donate.stripe.com/00g3fncKXcQMedO5kL"
},
{
"title": "$36.99$per_year",
"link": "https://donate.stripe.com/bIY6rz5ivcQM9XyaF6"
},
{
"title": "$other",
"link": "https://donate.stripe.com/7sIcPX5ivg2Y2v6145"
}
]
}
40 changes: 40 additions & 0 deletions src/products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import LOCALES from './locales';
import PRODUCTS_JSON from './products.json';

export interface Product {
title: string;
link: string;
}

const PRODUCTS = PRODUCTS_JSON as Record<string, Product[]>;

export interface ProductsConfig {
placePagePrompt: string;
products: Product[];
}

export function getProducts(locale: string | null): ProductsConfig | undefined {
if (!locale) {
return undefined;
}
const parts = locale.split(/[-_]/);
const language = parts[0].toLowerCase();
const country = parts[1] ? parts[1].toUpperCase() : '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему страну нельзя брать из заголовков CF, как сейчас берётся континент?


const products = PRODUCTS[country];
const trans = LOCALES[language];
if (products === undefined || trans === undefined) {
return undefined;
}

return {
placePagePrompt: trans.placePagePrompt,
products: products.map((product) => ({
...product,
title: product.title
.replace('$other', trans.otherAmount)
.replace('$per_month', trans.perMonth)
.replace('$per_year', trans.perYear),
})),
};
}
9 changes: 7 additions & 2 deletions src/servers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseDataVersion, parseAppVersion } from './versions';
import { getProducts, ProductsConfig } from './products';

export const DATA_VERSIONS = [
210529, //
Expand Down Expand Up @@ -125,7 +126,7 @@ export async function getServersList(request: Request) {
if (dataVersion === null) {
// Older clients download from the archive.
servers = [SERVER.backblaze];
} else if (dataVersion == 240702 && abusedVersions.includes(request.headers.get('x-om-appversion'))) {
} else if (dataVersion == 240702 && abusedVersions.includes(request.headers.get('x-om-appversion') || 'unknown')) {
// Redirect https://apps.apple.com/us/app/mapxplorer-navigation-radar/id6463052823
// who abuses our servers to a slow download "trap" node.
return new Response('["https://cdn-fi2.organicmaps.app/"]', {
Expand Down Expand Up @@ -176,6 +177,7 @@ export async function getServersList(request: Request) {
DonateUrl?: string;
NY?: string;
};
productsConfig?: ProductsConfig;
} = {
servers: servers,
};
Expand Down Expand Up @@ -203,11 +205,14 @@ export async function getServersList(request: Request) {

if (donatesEnabled) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore workarounds error TS2339: Property 'country' does not exist on type 'IncomingRequestCfProperties<unknown>'.
response.settings = {
DonateUrl: DONATE_URL,
NY: 'false', // Must be `string` instead of `bool`, otherwise clients will crash
};
if (appVersion.code >= 241022) {
const locale = request.headers.get('accept-language');
response.productsConfig = getProducts(locale);
}
}

return new Response(JSON.stringify(response), {
Expand Down
14 changes: 14 additions & 0 deletions test/products.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, test } from '@jest/globals';
import { getProducts } from '../src/products';

describe('getProducts', () => {
test('fr-FR', () => {
const fr_FR = getProducts('fr-FR');
expect(fr_FR).toBeDefined();
if (!fr_FR) return;
expect(fr_FR.placePagePrompt).toBe(
"L'application Organic Maps est gratuite pour tout le monde grâce à vos dons. Pas de publicité. Pas de trackers. Open-source.",
);
expect(fr_FR.products[fr_FR.products.length - 1].title).toEqual('Autre');
});
});
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"preserveConstEnums": true,
"sourceMap": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"types": ["@cloudflare/workers-types"]
},
"include": ["src/"],
Expand Down