send idm with card in requests

This commit is contained in:
ppc
2025-01-14 18:52:08 +00:00
parent a6ad82ffda
commit 0a42a0a912
6 changed files with 15 additions and 23 deletions
+3 -4
View File
@@ -147,10 +147,9 @@ export default function ServerCardIn({route, navigation}) {
const cardInCallback = useCallback(() => {
setCardInCompleted(false);
const cardId = selectedCard.physicalCardData && server.preferredCardIdFormat === "idm" ? icCard0008Number(selectedCard.physicalCardData.cardIDm) : selectedCard.code;
const abortController = new AbortController();
performCardIn(server, {cardId}, abortController.signal).then(r => {
performCardIn(server, {cardId: selectedCard.code, physicalCardIDm: selectedCard.physicalCardData?.cardIDm ?? undefined}, abortController.signal).then(r => {
const now = new Date();
realm.write(() => {
server.lastUsed = now;
@@ -178,10 +177,10 @@ export default function ServerCardIn({route, navigation}) {
setCardInCompleted(false);
const cardId = server.preferredCardIdFormat === "idm" || card.type !== ICType.Amusement ? icCard0008Number(card.idm) : card.accessCode;
const cardId = card.type !== ICType.Amusement ? icCard0008Number(card.idm) : card.accessCode;
const abortController = new AbortController();
performCardIn(server, {cardId}, abortController.signal).then(r => {
performCardIn(server, {cardId, physicalCardIDm: card.idm}, abortController.signal).then(r => {
setCardInCompleted(r);
}).catch(() => {
setCardInCompleted(false);
+3 -5
View File
@@ -8,6 +8,7 @@ declare const AMNET_API_VERSION = 1;
declare const MIN_AMNET_API_VERSION = 1;
interface AMCardInRequest {
cardId: string;
physicalCardIDm?: string;
}
/**
* Server connection info (api version, address, etc.)
@@ -30,13 +31,10 @@ interface AMServerInstanceMetrics {
timeSinceLastPoll?: number;
sessionUptime?: number;
}
interface AMServerPhysicalCardPreferences {
preferredCardIdFormat?: "idm" | "access" | null;
}
/**
* The response from an AMNet server's info endpoint
*/
type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics & AMServerPhysicalCardPreferences;
type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics;
/**
* Performs the card-in request to the specified server
* @param server The server to perform the request against
@@ -65,4 +63,4 @@ declare function validateCardId(id: string): boolean;
*/
declare function getGameName(id: string): string | null;
export { type AMCardInRequest, AMNET_API_VERSION, type AMServerConnectionInfo, type AMServerInfo, type AMServerInstanceMetrics, type AMServerMetadata, type AMServerPhysicalCardPreferences, CARD_ID_REGEX, MIN_AMNET_API_VERSION, fetchServerInfo, generateCardNumber, getGameName, performCardIn, validateCardId };
export { type AMCardInRequest, AMNET_API_VERSION, type AMServerConnectionInfo, type AMServerInfo, type AMServerInstanceMetrics, type AMServerMetadata, CARD_ID_REGEX, MIN_AMNET_API_VERSION, fetchServerInfo, generateCardNumber, getGameName, performCardIn, validateCardId };
+3 -5
View File
@@ -8,6 +8,7 @@ declare const AMNET_API_VERSION = 1;
declare const MIN_AMNET_API_VERSION = 1;
interface AMCardInRequest {
cardId: string;
physicalCardIDm?: string;
}
/**
* Server connection info (api version, address, etc.)
@@ -30,13 +31,10 @@ interface AMServerInstanceMetrics {
timeSinceLastPoll?: number;
sessionUptime?: number;
}
interface AMServerPhysicalCardPreferences {
preferredCardIdFormat?: "idm" | "access" | null;
}
/**
* The response from an AMNet server's info endpoint
*/
type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics & AMServerPhysicalCardPreferences;
type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics;
/**
* Performs the card-in request to the specified server
* @param server The server to perform the request against
@@ -65,4 +63,4 @@ declare function validateCardId(id: string): boolean;
*/
declare function getGameName(id: string): string | null;
export { type AMCardInRequest, AMNET_API_VERSION, type AMServerConnectionInfo, type AMServerInfo, type AMServerInstanceMetrics, type AMServerMetadata, type AMServerPhysicalCardPreferences, CARD_ID_REGEX, MIN_AMNET_API_VERSION, fetchServerInfo, generateCardNumber, getGameName, performCardIn, validateCardId };
export { type AMCardInRequest, AMNET_API_VERSION, type AMServerConnectionInfo, type AMServerInfo, type AMServerInstanceMetrics, type AMServerMetadata, CARD_ID_REGEX, MIN_AMNET_API_VERSION, fetchServerInfo, generateCardNumber, getGameName, performCardIn, validateCardId };
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -7
View File
@@ -10,6 +10,7 @@ export const MIN_AMNET_API_VERSION = 1;
export interface AMCardInRequest {
cardId: string;
physicalCardIDm?: string;
}
/**
@@ -36,14 +37,10 @@ export interface AMServerInstanceMetrics {
sessionUptime?: number;
}
export interface AMServerPhysicalCardPreferences {
preferredCardIdFormat?: "idm" | "access" | null;
}
/**
* The response from an AMNet server's info endpoint
*/
export type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics & AMServerPhysicalCardPreferences;
export type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics;
/**
* Performs the card-in request to the specified server
@@ -55,7 +52,7 @@ export async function performCardIn(server: AMServerConnectionInfo, request: AMC
if (server.apiVersion < MIN_AMNET_API_VERSION || server.apiVersion > AMNET_API_VERSION) {
throw new Error("Unsupported server API version");
}
try {
const response = await fetch(`${new URL(server.serverAddress).origin}/amnet/signin`, {
method: "POST",
@@ -82,7 +79,7 @@ export async function fetchServerInfo(serverAddress: string, abort: AbortSignal)
const response = await fetch(`${new URL(serverAddress).origin}/amnet/info`, {
signal: abort
});
if (!response.ok) {
return null;
}