This Project takes Form-Data as input and return request-id, the image is upscaled via upscaly ncnn and then progress percentage gets updated to supabase via realtime API, it also extract the png metadata from the input image. It also checks if the API check is valid and has enough quota to initiate the process.
The Databse should be configured like this.
1st Function :- Name :- check_api_key_and_quota
Argument :- api_key_param TEXT
DECLARE
daily_quota_remaining INTEGER;
monthly_quota_remaining INTEGER;
yearly_quota_remaining INTEGER;
exp BOOLEAN;
result check_api_key_and_quota_result;
BEGIN
-- Get the remaining daily, monthly, and yearly quotas for the provided API key
SELECT daily_quota, monthly_quota, yearly_quota, expired
INTO daily_quota_remaining, monthly_quota_remaining, yearly_quota_remaining, exp
FROM api_table
WHERE api = api_key_param;
-- If the API key doesn't exist, has no remaining daily, monthly, or yearly quota, or is expired, return false
IF daily_quota_remaining IS NULL OR daily_quota_remaining <= 0
OR monthly_quota_remaining IS NULL OR monthly_quota_remaining <= 0
OR yearly_quota_remaining IS NULL OR yearly_quota_remaining <= 0
OR exp THEN
result.success := FALSE;
result.message := 'Invalid API key or quota exceeded';
ELSE
result.success := TRUE;
result.message := '';
END IF;
RETURN result;
END;
2nd Function :- Name :- update_api_quotas
Argument :- api_key_param TEXT
BEGIN
UPDATE api_table
SET daily_quota = daily_quota - 1,
monthly_quota = monthly_quota - 1,
yearly_quota = yearly_quota - 1,
quota_used = quota_used + 1
WHERE api = api_key_param;
END;
You can vist https://github.com/upscayl/upscayl-ncnn and follow instruction to install it.
Git clone the repo git clone https://github.com/Mohking1/Upscale-ncnn-API.git
Create a .env file then paste below code.
supabaseUrl = <Your_supabase_url>
supabaseKey = <Your_supabse_key>
upscayl-bin_location = "<location_of_upscayl_bin>"
upscayl-input_location = "<location_of_input_for_upscayl>"
upscayl-output_location = "<location_of_output_for_upscayl>"
upscayl-model_location = "<location_of_models_for_upscayl>"
npm initnpm installnpm start