mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-10-03 04:07:58 +03:00
rename folder
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
export const CARD_ID_REGEX = /^(?:[0-9]{4} ?){5}$/i;
|
||||
|
||||
/**
|
||||
* Generates a random Aime card id.
|
||||
*/
|
||||
export function generateAimeCardId(): string {
|
||||
let cardId = '';
|
||||
|
||||
while (true) {
|
||||
// don't start with a 3
|
||||
const firstDigit = Math.floor(Math.random() * 10);
|
||||
|
||||
if (firstDigit !== 3) {
|
||||
cardId = firstDigit.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < 19; i++) {
|
||||
cardId += Math.floor(Math.random() * 10).toString();
|
||||
}
|
||||
|
||||
return cardId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the provided card id by known parameters
|
||||
* @param id The card id to validate
|
||||
*/
|
||||
export function validateAimeCardId(id: string): boolean {
|
||||
return id[0] !== '3' && CARD_ID_REGEX.test(id);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
export const AMNET_API_VERSION = 1;
|
||||
|
||||
export interface AimeServerInfo {
|
||||
serverName: string;
|
||||
apiVersion: number;
|
||||
}
|
||||
|
||||
export interface AimeCardinRequest {
|
||||
cardId: string;
|
||||
}
|
||||
|
||||
export async function getServerInfo(address: string) {
|
||||
const response = await fetch(address, {
|
||||
signal: AbortSignal.timeout(10000)
|
||||
});
|
||||
|
||||
const json: AimeServerInfo = await response.json();
|
||||
return json;
|
||||
}
|
||||
|
||||
export function serverCardIn(address: string, id: string) {
|
||||
return fetch(`${address}/card`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
cardId: id
|
||||
} satisfies AimeCardinRequest),
|
||||
signal: AbortSignal.timeout(5000)
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import Dexie, { type EntityTable } from 'dexie';
|
||||
|
||||
import {AimeServerInfo} from "@/lib/aime-net.ts";
|
||||
|
||||
export const CARD_LIMIT = 15;
|
||||
|
||||
interface AimeServer extends AimeServerInfo {
|
||||
id: number;
|
||||
address: string;
|
||||
lastConnected: number;
|
||||
}
|
||||
|
||||
interface AimeCard {
|
||||
id: string;
|
||||
name: string;
|
||||
lastUsed: number;
|
||||
}
|
||||
|
||||
const db = new Dexie('aimedb') as Dexie & {
|
||||
servers: EntityTable<AimeServer, 'id'>;
|
||||
cards: EntityTable<AimeCard, 'id'>;
|
||||
};
|
||||
|
||||
db.version(1).stores({
|
||||
servers: '++id, address',
|
||||
cards: 'id'
|
||||
});
|
||||
|
||||
export type {AimeServer, AimeCard};
|
||||
export {db};
|
||||
@@ -0,0 +1,6 @@
|
||||
import { type ClassValue, clsx } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
Reference in New Issue
Block a user