[+] Server
This commit is contained in:
+25
@@ -172,3 +172,28 @@ cython_debug/
|
|||||||
|
|
||||||
# PyPI configuration file
|
# PyPI configuration file
|
||||||
.pypirc
|
.pypirc
|
||||||
|
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
uvicorn~=0.34.0
|
||||||
|
fastapi~=0.115.11
|
||||||
Binary file not shown.
@@ -0,0 +1,59 @@
|
|||||||
|
from fastapi import FastAPI, HTTPException
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from pathlib import Path
|
||||||
|
import uvicorn
|
||||||
|
import time
|
||||||
|
import re
|
||||||
|
import winsound
|
||||||
|
from vk import press_key, release_key
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
# CORS
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=["*"],
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
PATH = Path('aime.txt')
|
||||||
|
AUDIO_EFFECT = Path(__file__).parent / 'audio/mixkit-gaming-lock-2848.wav'
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/scan")
|
||||||
|
def scan(uid: str):
|
||||||
|
"""
|
||||||
|
Parse the UID from the raw input string.
|
||||||
|
"""
|
||||||
|
uid = uid.replace(":", "")
|
||||||
|
|
||||||
|
# If the UID is 16-digit hex, treat it as a Felica and convert that to a 20-digit int
|
||||||
|
if re.match(r'^[0-9a-fA-F]{16}$', uid):
|
||||||
|
uid = str(int(uid, 16))
|
||||||
|
|
||||||
|
# Else if uid is a 20-digit int, use it
|
||||||
|
elif re.match(r'^\d{20}$', uid):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Else, raise an error
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=400, detail="Invalid UID format")
|
||||||
|
|
||||||
|
PATH.write_text(uid)
|
||||||
|
|
||||||
|
# Play sound
|
||||||
|
winsound.PlaySound(str(AUDIO_EFFECT), winsound.SND_FILENAME)
|
||||||
|
|
||||||
|
# Simulate key press
|
||||||
|
press_key()
|
||||||
|
time.sleep(5)
|
||||||
|
release_key()
|
||||||
|
|
||||||
|
return {"uid": uid}
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
uvicorn.run(app, host="0.0.0.0", port=8249)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import ctypes
|
||||||
|
from ctypes import wintypes
|
||||||
|
|
||||||
|
# Virtual-Key codes
|
||||||
|
# RESERVED: 0xEA
|
||||||
|
VK = 0x6B
|
||||||
|
KEYEVENTF_KEYUP = 0x0002
|
||||||
|
|
||||||
|
|
||||||
|
def press_key(vk_code = VK):
|
||||||
|
scan_code = ctypes.windll.user32.MapVirtualKeyA(vk_code, 0)
|
||||||
|
ctypes.windll.user32.keybd_event(vk_code, scan_code, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def release_key(vk_code = VK):
|
||||||
|
scan_code = ctypes.windll.user32.MapVirtualKeyA(vk_code, 0)
|
||||||
|
ctypes.windll.user32.keybd_event(vk_code, scan_code, KEYEVENTF_KEYUP, 0)
|
||||||
Reference in New Issue
Block a user