Skip to content

Commit 5b32bed

Browse files
committed
fix: normalise plugin download count key to full commit ID
1 parent 199332a commit 5b32bed

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • apps/www/src/app/api/bump/plugin/[slug]

apps/www/src/app/api/bump/plugin/[slug]/route.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FieldValue } from 'firebase-admin/firestore';
22
import { Database } from '../../../Firebase';
3+
import { FetchPlugins } from '../../v1/plugins/GetPlugins';
34

45
function withCORS(response: Response): Response {
56
response.headers.set('Access-Control-Allow-Origin', 'https://steamloopback.host');
@@ -15,7 +16,14 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug
1516
}
1617

1718
try {
18-
const docRef = Database.collection('downloads').doc(slug);
19+
const { pluginData } = await FetchPlugins();
20+
const plugin = pluginData.find((p) => p.id === slug || p.initCommitId === slug);
21+
22+
if (!plugin) {
23+
return withCORS(new Response(JSON.stringify({ success: false, message: 'Plugin not found' }), { status: 404 }));
24+
}
25+
26+
const docRef = Database.collection('downloads').doc(plugin.initCommitId);
1927
await docRef.set({ downloadCount: FieldValue.increment(1) }, { merge: true });
2028

2129
const updatedDoc = await docRef.get();

0 commit comments

Comments
 (0)