nah gonna redo it again
This commit is contained in:
257
pyapi/main.py
257
pyapi/main.py
@@ -1,11 +1,16 @@
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from typing import Dict, List, Optional
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import aiohttp
|
||||
from dotenv import load_dotenv
|
||||
from fastapi import FastAPI, HTTPException, Request
|
||||
from fastapi.responses import JSONResponse, Response
|
||||
from pydantic import BaseModel
|
||||
from scrapling.fetchers import StealthySession
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
@@ -19,6 +24,10 @@ app = FastAPI()
|
||||
|
||||
logger.info("FastAPI Proxy Server initialized")
|
||||
|
||||
SCRAPERAPI_API_KEY = os.getenv("SCRAPERAPI_API_KEY")
|
||||
if not SCRAPERAPI_API_KEY:
|
||||
raise ValueError("SCRAPERAPI_API_KEY is not set")
|
||||
|
||||
|
||||
CONSTANTS = {
|
||||
"SESSION_KEY_NAME": "SID",
|
||||
@@ -27,6 +36,7 @@ CONSTANTS = {
|
||||
"LAST_FETCHED_KEY": "LAST_FETCHED",
|
||||
"SCRAP_API_URL": "https://gamebooking24.com/lottery-api",
|
||||
"SCRAP_API_SESSION_KEY": "SRAJWT",
|
||||
"SCRAPERAPI_BASE_URL": "http://api.scraperapi.com",
|
||||
"SCRAP_API_BASE_HEADERS": {
|
||||
"Host": "gamebooking24.com",
|
||||
"Sec-Ch-Ua": '"Not/A)Brand";v="8", "Chromium";v="126"',
|
||||
@@ -44,33 +54,6 @@ CONSTANTS = {
|
||||
},
|
||||
}
|
||||
|
||||
# Global StealthySession instance - will be initialized on startup
|
||||
stealthy_session: Optional[StealthySession] = None
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""Initialize the StealthySession when the app starts"""
|
||||
global stealthy_session
|
||||
logger.info("Initializing StealthySession...")
|
||||
stealthy_session = StealthySession(
|
||||
headless=True,
|
||||
solve_cloudflare=True,
|
||||
max_pages=10, # Allow up to 10 concurrent requests
|
||||
google_search=False, # Skip Google search simulation for faster startup
|
||||
)
|
||||
logger.info("StealthySession initialized successfully")
|
||||
|
||||
|
||||
@app.on_event("shutdown")
|
||||
async def shutdown_event():
|
||||
"""Close the StealthySession when the app shuts down"""
|
||||
global stealthy_session
|
||||
if stealthy_session:
|
||||
logger.info("Closing StealthySession...")
|
||||
await stealthy_session.close()
|
||||
logger.info("StealthySession closed successfully")
|
||||
|
||||
|
||||
# Middleware for logging all requests
|
||||
@app.middleware("http")
|
||||
@@ -109,6 +92,110 @@ def build_headers(
|
||||
return headers
|
||||
|
||||
|
||||
async def make_get_request(
|
||||
url: str, params: Optional[Dict] = None, headers: Optional[Dict] = None
|
||||
):
|
||||
"""Make a GET request using ScraperAPI"""
|
||||
if SCRAPERAPI_API_KEY == "<TODO: get and put the key in here>":
|
||||
raise HTTPException(status_code=500, detail="ScraperAPI API key not configured")
|
||||
|
||||
# Build the ScraperAPI request params
|
||||
scraperapi_params = {
|
||||
"api_key": SCRAPERAPI_API_KEY,
|
||||
"url": url,
|
||||
"render": "true",
|
||||
}
|
||||
|
||||
# Add query params to the target URL if provided
|
||||
if params:
|
||||
url_with_params = f"{url}?{urlencode(params)}"
|
||||
scraperapi_params["url"] = url_with_params
|
||||
|
||||
# Make the request to ScraperAPI using aiohttp
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(
|
||||
CONSTANTS["SCRAPERAPI_BASE_URL"],
|
||||
params=scraperapi_params,
|
||||
headers=headers,
|
||||
timeout=aiohttp.ClientTimeout(total=60),
|
||||
) as response:
|
||||
# Create a simple response-like object
|
||||
class AsyncResponse:
|
||||
def __init__(self, aiohttp_response):
|
||||
self._response = aiohttp_response
|
||||
self.status_code = aiohttp_response.status
|
||||
self.headers = aiohttp_response.headers
|
||||
self._text = None
|
||||
self._json = None
|
||||
self._content = None
|
||||
|
||||
async def text(self):
|
||||
if self._text is None:
|
||||
self._text = await self._response.text()
|
||||
return self._text
|
||||
|
||||
async def json(self):
|
||||
if self._json is None:
|
||||
self._json = await self._response.json()
|
||||
return self._json
|
||||
|
||||
async def content(self):
|
||||
if self._content is None:
|
||||
self._content = await self._response.read()
|
||||
return self._content
|
||||
|
||||
return AsyncResponse(response)
|
||||
|
||||
|
||||
async def make_post_request(url: str, data: dict, headers: Optional[Dict] = None):
|
||||
"""Make a POST request using ScraperAPI"""
|
||||
if SCRAPERAPI_API_KEY == "<TODO: get and put the key in here>":
|
||||
raise HTTPException(status_code=500, detail="ScraperAPI API key not configured")
|
||||
|
||||
# Build the ScraperAPI request params
|
||||
scraperapi_params = {
|
||||
"api_key": SCRAPERAPI_API_KEY,
|
||||
"url": url,
|
||||
"render": "true",
|
||||
}
|
||||
|
||||
# Make the POST request to ScraperAPI using aiohttp
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(
|
||||
CONSTANTS["SCRAPERAPI_BASE_URL"],
|
||||
params=scraperapi_params,
|
||||
json=data, # Use json= for JSON payloads (sets Content-Type automatically)
|
||||
headers=headers,
|
||||
timeout=aiohttp.ClientTimeout(total=60),
|
||||
) as response:
|
||||
# Create a simple response-like object
|
||||
class AsyncResponse:
|
||||
def __init__(self, aiohttp_response):
|
||||
self._response = aiohttp_response
|
||||
self.status_code = aiohttp_response.status
|
||||
self.headers = aiohttp_response.headers
|
||||
self._text = None
|
||||
self._json = None
|
||||
self._content = None
|
||||
|
||||
async def text(self):
|
||||
if self._text is None:
|
||||
self._text = await self._response.text()
|
||||
return self._text
|
||||
|
||||
async def json(self):
|
||||
if self._json is None:
|
||||
self._json = await self._response.json()
|
||||
return self._json
|
||||
|
||||
async def content(self):
|
||||
if self._content is None:
|
||||
self._content = await self._response.read()
|
||||
return self._content
|
||||
|
||||
return AsyncResponse(response)
|
||||
|
||||
|
||||
# Pydantic models for request bodies
|
||||
class LoginPayload(BaseModel):
|
||||
userId: str
|
||||
@@ -168,13 +255,15 @@ async def get_balance(userId: int, authorization: str):
|
||||
logger.info(f"[GET /v1/user/get-balance] userId={userId}")
|
||||
try:
|
||||
headers = build_headers(authorization=authorization)
|
||||
page = stealthy_session.fetch(
|
||||
response = await make_get_request(
|
||||
f"{CONSTANTS['SCRAP_API_URL']}/v1/user/get-balance",
|
||||
params={"userId": userId},
|
||||
headers=headers,
|
||||
)
|
||||
logger.info(f"[GET /v1/user/get-balance] Response: {page.status}")
|
||||
return JSONResponse(content=page.response.json(), status_code=page.status)
|
||||
logger.info(f"[GET /v1/user/get-balance] Response: {response.status_code}")
|
||||
return JSONResponse(
|
||||
content=await response.json(), status_code=response.status_code
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"[GET /v1/user/get-balance] Error: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -185,14 +274,37 @@ async def login(payload: LoginPayload):
|
||||
logger.info(f"[POST /v1/auth/login] - payload={payload.model_dump()}")
|
||||
try:
|
||||
headers = build_headers(extra_headers={"Content-Type": "application/json"})
|
||||
page = stealthy_session.fetch(
|
||||
response = await make_post_request(
|
||||
f"{CONSTANTS['SCRAP_API_URL']}/v1/auth/login",
|
||||
method="POST",
|
||||
data=payload.model_dump(),
|
||||
headers=headers,
|
||||
)
|
||||
logger.info(f"[POST /v1/auth/login] Response: {page.status}")
|
||||
return JSONResponse(content=page.response.json(), status_code=page.status)
|
||||
logger.info(f"[POST /v1/auth/login] Response: {response.status_code}")
|
||||
|
||||
# Handle non-JSON responses (e.g., 403 HTML pages)
|
||||
if response.status_code == 403:
|
||||
response_text = await response.text()
|
||||
logger.error(
|
||||
f"[POST /v1/auth/login] 403 Forbidden - Response: {response_text[:500]}"
|
||||
)
|
||||
raise HTTPException(status_code=403, detail="Request blocked")
|
||||
|
||||
# Try to parse as JSON
|
||||
try:
|
||||
response_json = await response.json()
|
||||
except Exception as json_error:
|
||||
response_text = await response.text()
|
||||
logger.error(
|
||||
f"[POST /v1/auth/login] Failed to parse JSON response: {json_error}"
|
||||
)
|
||||
logger.error(f"[POST /v1/auth/login] Response text: {response_text[:500]}")
|
||||
raise HTTPException(
|
||||
status_code=500, detail=f"Invalid JSON response: {str(json_error)}"
|
||||
)
|
||||
|
||||
return JSONResponse(content=response_json, status_code=response.status_code)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"[POST /v1/auth/login] Error: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -207,28 +319,28 @@ async def get_captcha(uuid: str):
|
||||
"Accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"
|
||||
}
|
||||
)
|
||||
page = stealthy_session.fetch(
|
||||
response = await make_get_request(
|
||||
f"{CONSTANTS['SCRAP_API_URL']}/verify/image",
|
||||
params={"uuid": uuid},
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
if page.status == 403:
|
||||
if response.status_code == 403:
|
||||
logger.error("[GET /verify/image] 403 Forbidden - Request blocked")
|
||||
logger.error(
|
||||
"[GET /verify/image] 403 Forbidden - Cloudflare blocked the request"
|
||||
f"[GET /verify/image] Response headers: {dict(response.headers)}"
|
||||
)
|
||||
logger.error(
|
||||
f"[GET /verify/image] Response headers: {dict(page.response.headers)}"
|
||||
)
|
||||
logger.error(f"[GET /verify/image] Response text: {page.response.text}")
|
||||
response_text = await response.text()
|
||||
logger.error(f"[GET /verify/image] Response text: {response_text[:500]}")
|
||||
|
||||
content = await response.content()
|
||||
logger.info(
|
||||
f"[GET /verify/image] Response: {page.status}, size={len(page.response.content)} bytes"
|
||||
f"[GET /verify/image] Response: {response.status_code}, size={len(content)} bytes"
|
||||
)
|
||||
return Response(
|
||||
content=page.response.content,
|
||||
content=content,
|
||||
media_type="image/png",
|
||||
status_code=page.status,
|
||||
status_code=response.status_code,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"[GET /verify/image] Error: {str(e)}")
|
||||
@@ -245,14 +357,15 @@ async def dealer_list(payload: DealerListPayload, authorization: str):
|
||||
authorization=authorization,
|
||||
extra_headers={"Content-Type": "application/json"},
|
||||
)
|
||||
page = stealthy_session.fetch(
|
||||
response = await make_post_request(
|
||||
f"{CONSTANTS['SCRAP_API_URL']}/v1/user/dealer-list",
|
||||
method="POST",
|
||||
data=payload.model_dump(),
|
||||
headers=headers,
|
||||
)
|
||||
logger.info(f"[POST /v1/user/dealer-list] Response: {page.status}")
|
||||
return JSONResponse(content=page.response.json(), status_code=page.status)
|
||||
logger.info(f"[POST /v1/user/dealer-list] Response: {response.status_code}")
|
||||
return JSONResponse(
|
||||
content=await response.json(), status_code=response.status_code
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"[POST /v1/user/dealer-list] Error: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -268,14 +381,17 @@ async def distributor_list(payload: DistributorListPayload, authorization: str):
|
||||
authorization=authorization,
|
||||
extra_headers={"Content-Type": "application/json"},
|
||||
)
|
||||
page = stealthy_session.fetch(
|
||||
response = await make_post_request(
|
||||
f"{CONSTANTS['SCRAP_API_URL']}/v1/user/distributor-list",
|
||||
method="POST",
|
||||
data=payload.model_dump(),
|
||||
headers=headers,
|
||||
)
|
||||
logger.info(f"[POST /v1/user/distributor-list] Response: {page.status}")
|
||||
return JSONResponse(content=page.response.json(), status_code=page.status)
|
||||
logger.info(
|
||||
f"[POST /v1/user/distributor-list] Response: {response.status_code}"
|
||||
)
|
||||
return JSONResponse(
|
||||
content=await response.json(), status_code=response.status_code
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"[POST /v1/user/distributor-list] Error: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -289,13 +405,15 @@ async def list_draws(userId: int, authorization: str):
|
||||
authorization=authorization,
|
||||
extra_headers={"Content-Type": "application/json"},
|
||||
)
|
||||
page = stealthy_session.fetch(
|
||||
response = await make_get_request(
|
||||
f"{CONSTANTS['SCRAP_API_URL']}/v1/draw/list-my",
|
||||
params={"userId": userId},
|
||||
headers=headers,
|
||||
)
|
||||
logger.info(f"[GET /v1/draw/list-my] Response: {page.status}")
|
||||
return JSONResponse(content=page.response.json(), status_code=page.status)
|
||||
logger.info(f"[GET /v1/draw/list-my] Response: {response.status_code}")
|
||||
return JSONResponse(
|
||||
content=await response.json(), status_code=response.status_code
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"[GET /v1/draw/list-my] Error: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -311,14 +429,15 @@ async def book_list(payload: BookListPayload, authorization: str):
|
||||
authorization=authorization,
|
||||
extra_headers={"Content-Type": "application/json"},
|
||||
)
|
||||
page = stealthy_session.fetch(
|
||||
response = await make_post_request(
|
||||
f"{CONSTANTS['SCRAP_API_URL']}/v1/book/list2",
|
||||
method="POST",
|
||||
data=payload.model_dump(),
|
||||
headers=headers,
|
||||
)
|
||||
logger.info(f"[POST /v1/book/list2] Response: {page.status}")
|
||||
return JSONResponse(content=page.response.json(), status_code=page.status)
|
||||
logger.info(f"[POST /v1/book/list2] Response: {response.status_code}")
|
||||
return JSONResponse(
|
||||
content=await response.json(), status_code=response.status_code
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"[POST /v1/book/list2] Error: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -335,14 +454,15 @@ async def add_multiple(payload: AddMultiplePayload, authorization: str):
|
||||
authorization=authorization,
|
||||
extra_headers={"Content-Type": "application/json;charset=UTF-8"},
|
||||
)
|
||||
page = stealthy_session.fetch(
|
||||
response = await make_post_request(
|
||||
f"{CONSTANTS['SCRAP_API_URL']}/v1/book/add-multiple",
|
||||
method="POST",
|
||||
data=payload.model_dump(),
|
||||
headers=headers,
|
||||
)
|
||||
logger.info(f"[POST /v1/book/add-multiple] Response: {page.status}")
|
||||
return JSONResponse(content=page.response.json(), status_code=page.status)
|
||||
logger.info(f"[POST /v1/book/add-multiple] Response: {response.status_code}")
|
||||
return JSONResponse(
|
||||
content=await response.json(), status_code=response.status_code
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"[POST /v1/book/add-multiple] Error: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -358,14 +478,15 @@ async def delete_multiple(payload: DeleteMultiplePayload, authorization: str):
|
||||
authorization=authorization,
|
||||
extra_headers={"Content-Type": "application/json;charset=UTF-8"},
|
||||
)
|
||||
page = stealthy_session.fetch(
|
||||
response = await make_post_request(
|
||||
f"{CONSTANTS['SCRAP_API_URL']}/v1/book/delete-multiple",
|
||||
method="POST",
|
||||
data=payload.model_dump(),
|
||||
headers=headers,
|
||||
)
|
||||
logger.info(f"[POST /v1/book/delete-multiple] Response: {page.status}")
|
||||
return JSONResponse(content=page.response.json(), status_code=page.status)
|
||||
logger.info(f"[POST /v1/book/delete-multiple] Response: {response.status_code}")
|
||||
return JSONResponse(
|
||||
content=await response.json(), status_code=response.status_code
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"[POST /v1/book/delete-multiple] Error: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@@ -5,9 +5,8 @@ description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = [
|
||||
"cloudscraper>=1.2.71",
|
||||
"aiohttp>=3.13.2",
|
||||
"fastapi[standard]>=0.128.0",
|
||||
"pydantic>=2.12.5",
|
||||
"python-dotenv>=1.2.1",
|
||||
"scrapling[all]>=0.3.12",
|
||||
]
|
||||
|
||||
1167
pyapi/uv.lock
generated
1167
pyapi/uv.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,248 +1,248 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export type Session = {
|
||||
sId: string;
|
||||
ip: string;
|
||||
userAgent: string;
|
||||
username: string;
|
||||
userType: string;
|
||||
sId: string;
|
||||
ip: string;
|
||||
userAgent: string;
|
||||
username: string;
|
||||
userType: string;
|
||||
};
|
||||
|
||||
export type APISession = {
|
||||
ip: string;
|
||||
sessionToken: string;
|
||||
userId: string;
|
||||
ip: string;
|
||||
sessionToken: string;
|
||||
userId: string;
|
||||
};
|
||||
|
||||
export const zAuthPayload = z.object({
|
||||
username: z.string().min(4).max(64),
|
||||
password: z.string().min(8).max(64),
|
||||
username: z.string().min(4).max(64),
|
||||
password: z.string().min(8).max(64),
|
||||
});
|
||||
|
||||
export const zUser = z.object({
|
||||
id: z.string().length(16),
|
||||
createdAt: z.string(),
|
||||
updatedAt: z.string(),
|
||||
username: z.string().min(4).max(64),
|
||||
password: z.string().min(8).max(64),
|
||||
userType: z.string().min(4).max(5),
|
||||
association: z.string(),
|
||||
id: z.string().length(16),
|
||||
createdAt: z.string(),
|
||||
updatedAt: z.string(),
|
||||
username: z.string().min(4).max(64),
|
||||
password: z.string().min(8).max(64),
|
||||
userType: z.string().min(4).max(5),
|
||||
association: z.string(),
|
||||
});
|
||||
export type User = z.infer<typeof zUser>;
|
||||
|
||||
export const zLooseUser = z.object({
|
||||
id: z.string().length(16).optional(),
|
||||
createdAt: z.string().optional(),
|
||||
updatedAt: z.string().optional(),
|
||||
username: z.string().min(4).max(64),
|
||||
password: z.string().min(8).max(64),
|
||||
userType: z.string().min(4).max(5),
|
||||
association: z.string(),
|
||||
id: z.string().length(16).optional(),
|
||||
createdAt: z.string().optional(),
|
||||
updatedAt: z.string().optional(),
|
||||
username: z.string().min(4).max(64),
|
||||
password: z.string().min(8).max(64),
|
||||
userType: z.string().min(4).max(5),
|
||||
association: z.string(),
|
||||
});
|
||||
export type LooseUser = z.infer<typeof zLooseUser>;
|
||||
|
||||
export const zApiUser = z.object({
|
||||
id: z.string().length(16),
|
||||
userType: z.number(),
|
||||
disableBooking: z.string().nullable().optional(),
|
||||
sendVoucher: z.string().nullable().optional(),
|
||||
voucherGenerated: z.string().nullable().optional(),
|
||||
parentAdmin: z.number(),
|
||||
parentDistributor: z.number(),
|
||||
userName: z.string(),
|
||||
userCity: z.string().nullable().optional(),
|
||||
userId: z.string(),
|
||||
password: z.string(),
|
||||
accessDenied: z.number(),
|
||||
phoneNumber: z.string(),
|
||||
emailAddress: z.string(),
|
||||
disable: z.number(),
|
||||
commission: z.number(),
|
||||
commissionPangora: z.number(),
|
||||
allowTitles: z.string(),
|
||||
specialDealer: z.number(),
|
||||
allowBalance: z.number(),
|
||||
balance: z.number(),
|
||||
profitlossShare: z.number(),
|
||||
shareProfitonly: z.number(),
|
||||
allowRemoveold: z.number(),
|
||||
removeDays: z.number().nullable().optional(),
|
||||
language: z.number(),
|
||||
postData: z.boolean().nullable().optional(),
|
||||
createdAt: z.string().nullable(),
|
||||
updatedAt: z.string().nullable(),
|
||||
id: z.string().length(16),
|
||||
userType: z.number(),
|
||||
disableBooking: z.string().nullable().optional(),
|
||||
sendVoucher: z.string().nullable().optional(),
|
||||
voucherGenerated: z.string().nullable().optional(),
|
||||
parentAdmin: z.number(),
|
||||
parentDistributor: z.number(),
|
||||
userName: z.string(),
|
||||
userCity: z.string().nullable().optional(),
|
||||
userId: z.string(),
|
||||
password: z.string(),
|
||||
accessDenied: z.number(),
|
||||
phoneNumber: z.string(),
|
||||
emailAddress: z.string(),
|
||||
disable: z.number(),
|
||||
commission: z.number(),
|
||||
commissionPangora: z.number(),
|
||||
allowTitles: z.string(),
|
||||
specialDealer: z.number(),
|
||||
allowBalance: z.number(),
|
||||
balance: z.number(),
|
||||
profitlossShare: z.number(),
|
||||
shareProfitonly: z.number(),
|
||||
allowRemoveold: z.number(),
|
||||
removeDays: z.number().nullable().optional(),
|
||||
language: z.number(),
|
||||
postData: z.boolean().nullable().optional(),
|
||||
createdAt: z.string().nullable(),
|
||||
updatedAt: z.string().nullable(),
|
||||
});
|
||||
export type ApiUser = z.infer<typeof zApiUser>;
|
||||
|
||||
export const zApiPostUser = z.object({
|
||||
id: z.string(),
|
||||
userName: z.string(),
|
||||
userId: z.string(),
|
||||
postData: z.boolean(),
|
||||
balance: z.number().optional(),
|
||||
id: z.string(),
|
||||
userName: z.string(),
|
||||
userId: z.string(),
|
||||
postData: z.boolean(),
|
||||
balance: z.number().optional(),
|
||||
});
|
||||
export type ApiPostUser = z.infer<typeof zApiPostUser>;
|
||||
|
||||
export const zLooseApiUser = z.object({
|
||||
id: z.string().length(16).optional(),
|
||||
userType: z.number().optional(),
|
||||
disableBooking: z.string().nullable().optional(),
|
||||
sendVoucher: z.string().nullable().optional(),
|
||||
voucherGenerated: z.string().nullable().optional(),
|
||||
parentAdmin: z.number(),
|
||||
parentDistributor: z.number(),
|
||||
userName: z.string(),
|
||||
userCity: z.string().nullable().optional(),
|
||||
userId: z.string().optional(),
|
||||
password: z.string(),
|
||||
accessDenied: z.number(),
|
||||
phoneNumber: z.string(),
|
||||
emailAddress: z.string(),
|
||||
disable: z.number(),
|
||||
commission: z.number(),
|
||||
commissionPangora: z.number(),
|
||||
allowTitles: z.string(),
|
||||
specialDealer: z.number(),
|
||||
allowBalance: z.number(),
|
||||
balance: z.number(),
|
||||
profitlossShare: z.number(),
|
||||
shareProfitonly: z.number(),
|
||||
allowRemoveold: z.number(),
|
||||
removeDays: z.number().nullable().optional(),
|
||||
language: z.number().optional(),
|
||||
postData: z.boolean().nullable().optional(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
id: z.string().length(16).optional(),
|
||||
userType: z.number().optional(),
|
||||
disableBooking: z.string().nullable().optional(),
|
||||
sendVoucher: z.string().nullable().optional(),
|
||||
voucherGenerated: z.string().nullable().optional(),
|
||||
parentAdmin: z.number(),
|
||||
parentDistributor: z.number(),
|
||||
userName: z.string(),
|
||||
userCity: z.string().nullable().optional(),
|
||||
userId: z.string().optional(),
|
||||
password: z.string(),
|
||||
accessDenied: z.number(),
|
||||
phoneNumber: z.string(),
|
||||
emailAddress: z.string(),
|
||||
disable: z.number(),
|
||||
commission: z.number(),
|
||||
commissionPangora: z.number(),
|
||||
allowTitles: z.string(),
|
||||
specialDealer: z.number(),
|
||||
allowBalance: z.number(),
|
||||
balance: z.number(),
|
||||
profitlossShare: z.number(),
|
||||
shareProfitonly: z.number(),
|
||||
allowRemoveold: z.number(),
|
||||
removeDays: z.number().nullable().optional(),
|
||||
language: z.number().optional(),
|
||||
postData: z.boolean().nullable().optional(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
});
|
||||
export type LooseApiUser = z.infer<typeof zLooseApiUser>;
|
||||
|
||||
export const zDraw = z.object({
|
||||
id: z.string(),
|
||||
title: z.string(),
|
||||
closeTime: z.string(),
|
||||
filterDuplicatesWhilePosting: z.boolean(),
|
||||
drawType: z.number(),
|
||||
adminId: z.number(),
|
||||
abRateF: z.coerce.number(),
|
||||
abRateS: z.coerce.number(),
|
||||
abcRateF: z.coerce.number(),
|
||||
abcRateS: z.coerce.number(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
id: z.string(),
|
||||
title: z.string(),
|
||||
closeTime: z.string(),
|
||||
filterDuplicatesWhilePosting: z.boolean(),
|
||||
drawType: z.number(),
|
||||
adminId: z.number(),
|
||||
abRateF: z.coerce.number(),
|
||||
abRateS: z.coerce.number(),
|
||||
abcRateF: z.coerce.number(),
|
||||
abcRateS: z.coerce.number(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
});
|
||||
export type Draw = z.infer<typeof zDraw>;
|
||||
|
||||
export const zBookingEntry = z.object({
|
||||
id: z.string(),
|
||||
distributorId: z.number(),
|
||||
dealerId: z.number(),
|
||||
drawId: z.number(),
|
||||
bookDate: z.string(),
|
||||
number: z.string(),
|
||||
first: z.number(),
|
||||
second: z.number(),
|
||||
changedBalance: z.number(),
|
||||
sheetName: z.string().nullable().optional(),
|
||||
sheetId: z.string().nullable().optional(),
|
||||
requestId: z.string(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
id: z.string(),
|
||||
distributorId: z.number(),
|
||||
dealerId: z.number(),
|
||||
drawId: z.number(),
|
||||
bookDate: z.string(),
|
||||
number: z.string(),
|
||||
first: z.number(),
|
||||
second: z.number(),
|
||||
changedBalance: z.number(),
|
||||
sheetName: z.string().nullable().optional(),
|
||||
sheetId: z.string().nullable().optional(),
|
||||
requestId: z.string(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
});
|
||||
export type BookingEntry = z.infer<typeof zBookingEntry>;
|
||||
|
||||
export const zPostDataEntry = z.object({
|
||||
id: z.string(),
|
||||
requestId: z.string().nullable().optional(),
|
||||
number: z.string(),
|
||||
first: z.number(),
|
||||
second: z.number(),
|
||||
userId: z.string().nullable().optional(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
id: z.string(),
|
||||
requestId: z.string().nullable().optional(),
|
||||
number: z.string(),
|
||||
first: z.number(),
|
||||
second: z.number(),
|
||||
userId: z.string().nullable().optional(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
});
|
||||
export type PostDataEntry = z.infer<typeof zPostDataEntry>;
|
||||
|
||||
const zPostDataHistory = z.object({
|
||||
id: z.string(),
|
||||
data: z.array(zPostDataEntry),
|
||||
drawId: z.number(),
|
||||
bookDate: z.string(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
id: z.string(),
|
||||
data: z.array(zPostDataEntry),
|
||||
drawId: z.number(),
|
||||
bookDate: z.string(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
updatedAt: z.string().nullable().optional(),
|
||||
});
|
||||
export type PostDataHistory = z.infer<typeof zPostDataHistory>;
|
||||
|
||||
export const zPresetDataEntry = z.object({
|
||||
id: z.string(),
|
||||
drawId: z.number(),
|
||||
bookDate: z.string(),
|
||||
number: z.string(),
|
||||
first: z.number(),
|
||||
second: z.number(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
dealerId: z.number().optional().nullable(),
|
||||
id: z.string(),
|
||||
drawId: z.number(),
|
||||
bookDate: z.string(),
|
||||
number: z.string(),
|
||||
first: z.number(),
|
||||
second: z.number(),
|
||||
createdAt: z.string().nullable().optional(),
|
||||
dealerId: z.number().optional().nullable(),
|
||||
});
|
||||
export type PresetDataEntry = z.infer<typeof zPresetDataEntry>;
|
||||
|
||||
export const fsPair = z.object({
|
||||
first: z.number(),
|
||||
second: z.number(),
|
||||
first: z.number(),
|
||||
second: z.number(),
|
||||
});
|
||||
|
||||
export const zLexiCodeCacheObject = z.object({
|
||||
number: z.string(),
|
||||
rate: fsPair,
|
||||
prize: fsPair,
|
||||
frequency: fsPair,
|
||||
number: z.string(),
|
||||
rate: fsPair,
|
||||
prize: fsPair,
|
||||
frequency: fsPair,
|
||||
});
|
||||
|
||||
export const reducedFinalSheetRow = z.object({
|
||||
id: z.string(),
|
||||
number: z.string(),
|
||||
frequency: fsPair,
|
||||
frequencies: z.object({
|
||||
// a: fsPair,
|
||||
// ab: fsPair,
|
||||
// abc: fsPair,
|
||||
// "+abc": fsPair,
|
||||
// "a+bc": fsPair,
|
||||
// "ab+c": fsPair,
|
||||
abcd: fsPair,
|
||||
}),
|
||||
rate: fsPair,
|
||||
prize: fsPair,
|
||||
profit: fsPair,
|
||||
id: z.string(),
|
||||
number: z.string(),
|
||||
frequency: fsPair,
|
||||
frequencies: z.object({
|
||||
// a: fsPair,
|
||||
// ab: fsPair,
|
||||
// abc: fsPair,
|
||||
// "+abc": fsPair,
|
||||
// "a+bc": fsPair,
|
||||
// "ab+c": fsPair,
|
||||
abcd: fsPair,
|
||||
}),
|
||||
rate: fsPair,
|
||||
prize: fsPair,
|
||||
profit: fsPair,
|
||||
});
|
||||
|
||||
export const zfinalSheetRow = z.object({
|
||||
id: z.string(),
|
||||
number: z.string(),
|
||||
frequency: fsPair,
|
||||
rate: fsPair,
|
||||
prize: fsPair,
|
||||
profit: fsPair,
|
||||
id: z.string(),
|
||||
number: z.string(),
|
||||
frequency: fsPair,
|
||||
rate: fsPair,
|
||||
prize: fsPair,
|
||||
profit: fsPair,
|
||||
|
||||
a: zLexiCodeCacheObject,
|
||||
xa: zLexiCodeCacheObject,
|
||||
xxa: zLexiCodeCacheObject,
|
||||
xxxa: zLexiCodeCacheObject,
|
||||
ab: zLexiCodeCacheObject,
|
||||
xab: zLexiCodeCacheObject,
|
||||
axb: zLexiCodeCacheObject,
|
||||
xaxb: zLexiCodeCacheObject,
|
||||
xxab: zLexiCodeCacheObject,
|
||||
axxb: zLexiCodeCacheObject,
|
||||
abc: zLexiCodeCacheObject,
|
||||
xabc: zLexiCodeCacheObject,
|
||||
axbc: zLexiCodeCacheObject,
|
||||
abxc: zLexiCodeCacheObject,
|
||||
abcd: zLexiCodeCacheObject,
|
||||
a: zLexiCodeCacheObject,
|
||||
xa: zLexiCodeCacheObject,
|
||||
xxa: zLexiCodeCacheObject,
|
||||
xxxa: zLexiCodeCacheObject,
|
||||
ab: zLexiCodeCacheObject,
|
||||
xab: zLexiCodeCacheObject,
|
||||
axb: zLexiCodeCacheObject,
|
||||
xaxb: zLexiCodeCacheObject,
|
||||
xxab: zLexiCodeCacheObject,
|
||||
axxb: zLexiCodeCacheObject,
|
||||
abc: zLexiCodeCacheObject,
|
||||
xabc: zLexiCodeCacheObject,
|
||||
axbc: zLexiCodeCacheObject,
|
||||
abxc: zLexiCodeCacheObject,
|
||||
abcd: zLexiCodeCacheObject,
|
||||
});
|
||||
|
||||
export type ServerError = Array<{
|
||||
message: string;
|
||||
value?: string;
|
||||
meta?: any;
|
||||
message: string;
|
||||
value?: string;
|
||||
meta?: any;
|
||||
}>;
|
||||
|
||||
export const UserTypes = { ADMIN: "ADMIN", USER: "USER" };
|
||||
@@ -250,8 +250,8 @@ export const UserTypes = { ADMIN: "ADMIN", USER: "USER" };
|
||||
export const ApiUserTypes = { ADMIN: 1, DISTRIBUTOR: 2, DEALER: 3 };
|
||||
|
||||
export type ApiPostUserWithParent = ApiPostUser & {
|
||||
parentAdmin: number;
|
||||
parentDistributor: number;
|
||||
parentAdmin: number;
|
||||
parentDistributor: number;
|
||||
};
|
||||
|
||||
export type LexiCodeCacheObject = z.infer<typeof zLexiCodeCacheObject>;
|
||||
@@ -265,108 +265,109 @@ export type ReducedFinalSheetRow = z.infer<typeof reducedFinalSheetRow>;
|
||||
export type FSPair = z.infer<typeof fsPair>;
|
||||
|
||||
export type FSTotals = {
|
||||
rate: FSPair;
|
||||
prize: FSPair;
|
||||
commission: FSPair;
|
||||
netRate: FSPair;
|
||||
frequency: FSPair;
|
||||
rate: FSPair;
|
||||
prize: FSPair;
|
||||
commission: FSPair;
|
||||
netRate: FSPair;
|
||||
frequency: FSPair;
|
||||
};
|
||||
|
||||
export type ReducedFinalSheetData = {
|
||||
id: string;
|
||||
date: string;
|
||||
drawId: string;
|
||||
data: Array<ReducedFinalSheetRow>;
|
||||
totals: FSTotals;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
id: string;
|
||||
date: string;
|
||||
drawId: string;
|
||||
data: Array<ReducedFinalSheetRow>;
|
||||
totals: FSTotals;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
};
|
||||
|
||||
export type FinalSheetData = {
|
||||
id: string;
|
||||
date: string;
|
||||
drawId: string;
|
||||
data: Array<FinalSheetRow>;
|
||||
totals: FSTotals;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
id: string;
|
||||
date: string;
|
||||
drawId: string;
|
||||
data: Array<FinalSheetRow>;
|
||||
totals: FSTotals;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
};
|
||||
|
||||
export type AuthPayload = z.infer<typeof zAuthPayload>;
|
||||
|
||||
export type SessionData = {
|
||||
username: string;
|
||||
userType: string;
|
||||
username: string;
|
||||
userType: string;
|
||||
};
|
||||
|
||||
export type BookingInputValues = {
|
||||
number: string;
|
||||
default: { first: string; second: string };
|
||||
first: Record<string, string>;
|
||||
second: Record<string, string>;
|
||||
number: string;
|
||||
default: { first: string; second: string };
|
||||
first: Record<string, string>;
|
||||
second: Record<string, string>;
|
||||
};
|
||||
|
||||
export const zPostDataHistoryFilters = z.object({
|
||||
date: z.string(),
|
||||
draw: zDraw,
|
||||
date: z.string(),
|
||||
draw: zDraw,
|
||||
});
|
||||
|
||||
export type PostDataHistoryFilters = z.infer<typeof zPostDataHistoryFilters>;
|
||||
|
||||
export const zDDFilters = z.object({
|
||||
date: z.string(),
|
||||
draw: zDraw.optional(),
|
||||
date: z.string(),
|
||||
draw: zDraw.optional(),
|
||||
});
|
||||
|
||||
export type DDFilters = z.infer<typeof zDDFilters>;
|
||||
|
||||
export const zDDUserFilters = z.object({
|
||||
date: z.string(),
|
||||
draw: zDraw.optional(),
|
||||
user: zApiUser.optional(),
|
||||
date: z.string(),
|
||||
draw: zDraw.optional(),
|
||||
user: zApiUser.optional(),
|
||||
});
|
||||
|
||||
export type DDUserFilters = z.infer<typeof zDDUserFilters>;
|
||||
|
||||
export const zPostDataFilters = z.object({
|
||||
date: z.string(),
|
||||
draw: zDraw.optional().nullable(),
|
||||
minPrize: z.coerce.number(),
|
||||
maxPrize: z.coerce.number(),
|
||||
twoDigitRates: fsPair,
|
||||
threeDigitRates: fsPair,
|
||||
customData: z.string(),
|
||||
date: z.string(),
|
||||
draw: zDraw.optional().nullable(),
|
||||
minPrize: z.coerce.number(),
|
||||
maxPrize: z.coerce.number(),
|
||||
twoDigitRates: fsPair,
|
||||
threeDigitRates: fsPair,
|
||||
customData: z.string(),
|
||||
});
|
||||
|
||||
export type PostDataFilters = z.infer<typeof zPostDataFilters>;
|
||||
|
||||
// TODO: THIS IS OUTDATED, HAVE TO UPDATE THIS TO A NEW DISTRIBUTOR
|
||||
export const DEFAULT_RANDOM_DISTRIBUTOR = {
|
||||
id: "apiuser:6339",
|
||||
userType: 2,
|
||||
disableBooking: null,
|
||||
sendVoucher: null,
|
||||
voucherGenerated: null,
|
||||
parentAdmin: 15,
|
||||
parentDistributor: 0,
|
||||
userName: "Baba Sagar",
|
||||
userCity: "Shikar pur",
|
||||
userId: "317XY3",
|
||||
password: "405613",
|
||||
accessDenied: 0,
|
||||
phoneNumber: "",
|
||||
emailAddress: "",
|
||||
disable: 0,
|
||||
commission: 20.0,
|
||||
commissionPangora: 20.0,
|
||||
allowTitles: ",7,8,9,10,11,12,13,14,15,16,30,31,32,",
|
||||
specialDealer: 0,
|
||||
allowBalance: 1,
|
||||
balance: 30094.905,
|
||||
profitlossShare: 50.0,
|
||||
shareProfitonly: 0,
|
||||
allowRemoveold: 0,
|
||||
removeDays: 30,
|
||||
language: 0,
|
||||
createdAt: new Date().toString(),
|
||||
updatedAt: new Date().toString(),
|
||||
id: "apiuser:6339",
|
||||
userType: 2,
|
||||
disableBooking: null,
|
||||
sendVoucher: null,
|
||||
voucherGenerated: null,
|
||||
parentAdmin: 15,
|
||||
parentDistributor: 0,
|
||||
userName: "Baba Sagar",
|
||||
userCity: "Shikar pur",
|
||||
userId: "298HAM",
|
||||
password: "HA16Z7",
|
||||
accessDenied: 0,
|
||||
phoneNumber: "",
|
||||
emailAddress: "",
|
||||
disable: 0,
|
||||
commission: 20.0,
|
||||
commissionPangora: 20.0,
|
||||
allowTitles: ",7,8,9,10,11,12,13,14,15,16,30,31,32,",
|
||||
specialDealer: 0,
|
||||
allowBalance: 1,
|
||||
balance: 30094.905,
|
||||
profitlossShare: 50.0,
|
||||
shareProfitonly: 0,
|
||||
allowRemoveold: 0,
|
||||
removeDays: 30,
|
||||
language: 0,
|
||||
createdAt: new Date().toString(),
|
||||
updatedAt: new Date().toString(),
|
||||
} as unknown as ApiUser;
|
||||
|
||||
Reference in New Issue
Block a user