That’s why I’m explaining it upfront and posting the full code here. The entire plugin code is public, and this usage counter code is literally all there is. Nothing more happens behind the scenes.
This is just a very simple counter to know how many people are using the plugin. There’s no tracking logic, no logs and no data collection.
The usage counter will also be optional. You’ll be able to disable it in the plugin settings if you don’t want it enabled. It’s not required to use the plugin.
> Cloudflare handles IPs at the infrastructure level, like any HTTPS request, but this worker itself has no access to that information.
I’m adding this to Translatica and I’d really like to hear your thoughts or feedback before moving forward.
export default {
async fetch(request, env) {
// Only POST is expected here
if (request.method !== "POST") {
return new Response("ok");
}
// Simple shared key check
const pluginKey = request.headers.get("X-Plugin-Key");
if (pluginKey !== env.PLUGIN_KEY) {
return new Response("forbidden", { status: 403 });
}
// Read current value
let total = await env.STATS.get("translatica");
total = Number(total ?? 0);
// Increment and store
await env.STATS.put("translatica", String(total + 1));
return new Response("ok");
}
};
Join: @CommunityByApple
