Update logic and UI for MiniMax and POE specific formats
This commit is contained in:
1 parent
b3fd63b594
commit
0a2368e3e7
5 files changed
+48
-12
No files matched your search
+3
-2
@@ -1,6 +1,7 @@
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
import { getLatestQuotas, getQuotaHistory } from './services/db';
|
||||
import { getQuotaHistory } from './services/db';
|
||||
import { fetchAllQuotas } from './services/providers';
|
||||
import './cron'; // Start the cron jobs
|
||||
|
||||
const app = express();
|
||||
@@ -11,7 +12,7 @@ app.use(express.json());
|
||||
|
||||
app.get('/api/quotas', async (req, res) => {
|
||||
try {
|
||||
const quotas = await getLatestQuotas();
|
||||
const quotas = await fetchAllQuotas();
|
||||
res.json(quotas);
|
||||
} catch (error) {
|
||||
console.error('Error fetching quotas:', error);
|
||||
|
||||
@@ -18,6 +18,7 @@ export interface QuotaEntry {
|
||||
total: number;
|
||||
percentage: number;
|
||||
timestamp?: Date;
|
||||
meta?: any;
|
||||
}
|
||||
|
||||
export async function initDb() {
|
||||
|
||||
@@ -28,24 +28,21 @@ export async function fetchAntigravityQuota(): Promise<QuotaEntry> {
|
||||
|
||||
export async function fetchPoeQuota(): Promise<QuotaEntry> {
|
||||
try {
|
||||
// According to docs, returns available point balance
|
||||
const res = await axios.get('https://api.poe.com/usage/current_balance', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${process.env.POE_API_KEY}`
|
||||
}
|
||||
});
|
||||
|
||||
// POE logic: 75000 daily points is standard. We might need to adjust based on actual API payload.
|
||||
// Assuming response has: { available: number }
|
||||
const available = res.data.current_point_balance || 0;
|
||||
const total = 2575000;
|
||||
const total = 2500000;
|
||||
const used = total - available > 0 ? total - available : 0;
|
||||
const percentage = (used / total) * 100;
|
||||
|
||||
return { provider: 'POE', used, total, percentage };
|
||||
} catch (error: any) {
|
||||
console.error('Error fetching POE quota:', error.message);
|
||||
return { provider: 'POE', used: 0, total: 75000, percentage: 0 };
|
||||
return { provider: 'POE', used: 0, total: 2500000, percentage: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,11 +55,22 @@ export async function fetchMinimaxQuota(): Promise<QuotaEntry> {
|
||||
});
|
||||
|
||||
const remains = res.data.model_remains?.find((r: any) => r.model_name === 'general');
|
||||
const total = 100;
|
||||
const percentage = remains ? (100 - remains.current_weekly_remaining_percent) : 0;
|
||||
const intervalUsed = remains ? (100 - remains.current_interval_remaining_percent) : 0;
|
||||
const weeklyUsed = remains ? (100 - remains.current_weekly_remaining_percent) : 0;
|
||||
|
||||
// Use the highest percentage for the progress bar logic
|
||||
const percentage = Math.max(intervalUsed, weeklyUsed);
|
||||
const used = percentage;
|
||||
const total = 100;
|
||||
|
||||
const meta = {
|
||||
intervalUsed,
|
||||
weeklyUsed,
|
||||
intervalReset: remains ? remains.end_time : null,
|
||||
weeklyReset: remains ? remains.weekly_end_time : null
|
||||
};
|
||||
|
||||
return { provider: 'MiniMax', used, total, percentage };
|
||||
return { provider: 'MiniMax', used, total, percentage, meta };
|
||||
} catch (error: any) {
|
||||
console.error('Error fetching MiniMax quota:', error.message);
|
||||
return { provider: 'MiniMax', used: 0, total: 100, percentage: 0 };
|
||||
|
||||
Reference in new issue
Block a user