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

fix api_key bugs cause server not started #58

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
10 changes: 6 additions & 4 deletions tools/apiKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { API_KEY_TABLE } from "../database/types.js";
import { getTable } from "../database/index.js";

const MAX_USAGE = 10;
const tbl = await getTable(API_KEY_TABLE);

function queryApiKeyTbl(key) {
async function queryApiKeyTbl(key, table = null) {
const tbl = table || await getTable(API_KEY_TABLE);
const keyQuery = tbl.query()
.where('api_key = '+"'"+key+"'")
.limit(1)
Expand All @@ -28,7 +28,8 @@ function queryApiKeyTbl(key) {
}

export async function addKeytoTable(key){
const keyQuery = await queryApiKeyTbl(key);
const tbl = await getTable(API_KEY_TABLE);
const keyQuery = await queryApiKeyTbl(key, tbl);
if ( keyQuery.length == 0){
await tbl.add([{api_key: key, usage: MAX_USAGE}]);
}
Expand All @@ -38,7 +39,8 @@ export async function addKeytoTable(key){
}

export async function updateKeyUsage(key){
const keyQuery = await queryApiKeyTbl(key);
const tbl = await getTable(API_KEY_TABLE);
const keyQuery = await queryApiKeyTbl(key, tbl);
console.log(keyQuery)
if (keyQuery.length > 0){
let usage = keyQuery[0].usage
Expand Down
Loading