Enforce API key quota within the database transaction
This commit is contained in:
+3
-4
@@ -1174,10 +1174,8 @@ const server = http.createServer(async (req, res) => {
|
||||
|
||||
if (req.method === 'POST') {
|
||||
try {
|
||||
const mevcut = store.listApiKeys(user.email).length;
|
||||
kotaKontrol(user.email, 'apiAnahtari', mevcut, 1, { isAdmin: user.isAdmin });
|
||||
const body = await readBody(req).catch(() => ({}));
|
||||
const k = store.createApiKey(user.email, body.ad);
|
||||
const body = await readBody(req);
|
||||
const k = store.createApiKey(user.email, body.ad, { limit: haklar(user.email, { isAdmin: user.isAdmin }).apiAnahtari });
|
||||
// `anahtar` YALNIZCA burada döner; sunucuda yalnızca hash'i saklanır
|
||||
return json(res, 200, { success: true, anahtar: k });
|
||||
} catch (e) {
|
||||
@@ -1188,6 +1186,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const ok = store.revokeApiKey(user.email, url.searchParams.get('id'));
|
||||
return json(res, ok ? 200 : 404, { success: ok, error: ok ? undefined : 'Anahtar bulunamadı veya bu hesaba ait değil.', anahtarlar: store.listApiKeys(user.email), limit: haklar(user.email, { isAdmin: user.isAdmin }).apiAnahtari });
|
||||
}
|
||||
if (req.method !== 'GET') return json(res, 405, { success: false, error: 'Desteklenmeyen metot.' });
|
||||
return json(res, 200, { success: true, anahtarlar: store.listApiKeys(user.email), limit: haklar(user.email, { isAdmin: user.isAdmin }).apiAnahtari });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user