SkywardAI / voyager

The project is OpenAI-like API service of SkywardAI ecosystem
Apache License 2.0
3 stars 13 forks source link

Add apiKey.js script to add API keys to database and update usage count. #43

Closed Murkeee closed 3 months ago

Murkeee commented 3 months ago

Description

This PR fixes #28

Notes for Reviewers Hopefully this is what you want. One function for adding api key to database and another for updating the usage count. Let me know if changes need to be made.

Signed commits

Murkeee commented 3 months ago

In that case should functions return status codes like this?

if ( keyQuery.length == 0){
        await tbl.add([{api_key: key, usage: MAX_USAGE}]);
        return res.status(200).send(`Data with values: api_key: ${key}, usage: ${usage}, successfully added to table`)
    }
    else {
        return res.status(406).send("Attempted to add existing key to table");
    }

Or should that be handled differently?

cbh778899 commented 3 months ago

In that case should functions return status codes like this?

if ( keyQuery.length == 0){
        await tbl.add([{api_key: key, usage: MAX_USAGE}]);
        return res.status(200).send(`Data with values: api_key: ${key}, usage: ${usage}, successfully added to table`)
    }
    else {
        return res.status(406).send("Attempted to add existing key to table");
    }

Or should that be handled differently?

no, i think this should be handled by functions in /actions/*.js files, they are specifically for req/res related actions.

Murkeee commented 3 months ago

👍 Got it. Thanks.