Skip to content

Commit

Permalink
Merge pull request #170 from HannesOberreiter/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
HannesOberreiter committed Aug 12, 2024
2 parents 1b028d7 + c280606 commit 717b01a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 35 deletions.
2 changes: 2 additions & 0 deletions mails/premium_reminder_de.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Liebe/r Imker/in,

deine Premium Mitgliedschaft läuft bald aus. Wir würden uns freuen, wenn du uns als Premium Mitglied behalten bleibst!

Imkerei: %key%

Jetzt verlängern: %base_url%premium%params%

Wenn deine Premium Mitgliedschaft ausgelaufen ist, verlierst du natürlich keine Daten. Du kannst mit deinen existierenden Stöcken und Ständen ohne weiteres weiterarbeiten, aber die Basic User Limitierungen sind wieder aktiv.
2 changes: 2 additions & 0 deletions mails/premium_reminder_en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Dear Beekeeper!

Your Premium Membership will expire soon! We would be happy to keep you as Premium Member around.

Organization: %key%

Renew now: %base_url%premium%params%

If your Premium Membership runs out, you wont loose any data! You also can still work with all your hives and apiaries for free but basic membership limitations are again in place!
2 changes: 2 additions & 0 deletions mails/premium_reminder_fr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Cher apiculteur !

Votre adhésion Premium va bientôt expirer! Nous serions heureux de vous garder comme membre Premium.

Organization: %key%

Prolonger maintenant: %base_url%premium%params%

Si votre abonnement Premium expire, vous ne perdrez aucune donnée ! Vous pouvez également continuer à travailler avec toutes vos ruches et ruchers gratuitement, mais les limitations de l'adhésion de base sont de nouveau en place !
2 changes: 2 additions & 0 deletions mails/premium_reminder_it.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Caro apicoltore!

La tua iscrizione Premium scadrà presto! Saremo lieti di mantenerla come Membro Premium.

Organization: %key%

Rinnovare ora: %base_url%premium%params%

Se la tua iscrizione Premium scade, non perderai alcun dato! Potrai inoltre continuare a lavorare gratuitamente con tutti i tuoi alveari e apiari, ma le limitazioni dell'iscrizione di base sono di nuovo in vigore!
14 changes: 8 additions & 6 deletions src/api/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,14 @@ export default class AuthController {
throw new Error('No name or email');
}
return reply.redirect(
frontend +
'/visitor/register?name=' +
result.name +
'&email=' +
result.email +
'&oauth=google',
encodeURI(
frontend +
'/visitor/register?name=' +
result.name +
'&email=' +
result.email +
'&oauth=google',
),
);
}
} catch (e) {
Expand Down
34 changes: 5 additions & 29 deletions src/api/controllers/public.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function mapTaxa(req: FastifyRequest) {
return taxa;
}

export function buildRedisCacheKeyObservationsRecent(taxa: Taxa) {
return `cache:${taxa}ObservationsRecent`;
}

export default class PublicController {
static async getPestObservationsRecent(
req: FastifyRequest,
Expand All @@ -22,7 +26,7 @@ export default class PublicController {
const taxa = mapTaxa(req);

reply.header('Cache-Control', 'public, max-age=21600');
const cacheKey = `cache:${taxa}ObservationsRecent`;
const cacheKey = buildRedisCacheKeyObservationsRecent(taxa);

const redis = RedisServer.client;
const cached = await redis.get(cacheKey);
Expand Down Expand Up @@ -87,32 +91,4 @@ export default class PublicController {
.where('taxa', taxa);
return res[0];
}

static async getPestObservationsArray(
req: FastifyRequest,
reply: FastifyReply,
) {
const taxa = mapTaxa(req);

reply.header('Cache-Control', 'public, max-age=21600');
const cacheKey = `cache:${taxa}ObservationsArray`;

const redis = RedisServer.client;
const cached = await redis.get(cacheKey);
if (cached) {
return cached;
}

const result = await Observation.query()
.select('location')
.where('taxa', taxa);
const res = [];
for (const r of result) {
res.push([(r as any).location.x, (r as any).location.y]);
}

redis.set(cacheKey, JSON.stringify(res), 'EX', 21600);

return res;
}
}
1 change: 1 addition & 0 deletions src/api/utils/cron.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export const reminderPremium = async () => {
lang: u.lang,
subject: 'premium_reminder',
name: u.username,
key: company.name,
});
await User.query().findById(u.id).patch({
reminder_premium: nowDate,
Expand Down
7 changes: 7 additions & 0 deletions src/api/utils/pest.util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RedisServer } from '../../servers/redis.server.js';
import { buildRedisCacheKeyObservationsRecent } from '../controllers/public.controller.js';
import { Observation, Taxa } from '../models/observation.model.js';
import proj4 from 'proj4';

Expand All @@ -10,7 +12,12 @@ export async function fetchObservations(taxa: Taxa = 'Vespa velutina') {
const patriNat =
taxa === 'Vespa velutina' ? await fetchPatriNat() : { newObservations: 0 };

/** after fetching new taxa we want to cleanup any possible cached map results */
const cacheKey = buildRedisCacheKeyObservationsRecent(taxa);
RedisServer.client.del(cacheKey);

return {
taxa: taxa,
iNaturalist: inat,
patriNat: patriNat,
artenfinderNet: artenfinderNet,
Expand Down

0 comments on commit 717b01a

Please sign in to comment.