mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-10-23 18:15:39 -05:00
Use package.json exports field
This commit is contained in:
@@ -10,7 +10,7 @@ const debugFlapg = createDebug('nxapi:api:flapg');
|
||||
const debugImink = createDebug('nxapi:api:imink');
|
||||
const debugZncaApi = createDebug('nxapi:api:znca-api');
|
||||
|
||||
abstract class ZncaApi {
|
||||
export abstract class ZncaApi {
|
||||
constructor(
|
||||
public useragent?: string
|
||||
) {}
|
||||
@@ -291,7 +291,7 @@ export type FResult = {
|
||||
result: AndroidZncaFResponse;
|
||||
});
|
||||
|
||||
function getZncaApiFromEnvironment(useragent?: string): ZncaApi {
|
||||
export function getZncaApiFromEnvironment(useragent?: string): ZncaApi {
|
||||
if (process.env.NXAPI_ZNCA_API) {
|
||||
if (process.env.NXAPI_ZNCA_API === 'flapg') {
|
||||
return new ZncaApiFlapg(useragent);
|
||||
|
||||
@@ -178,9 +178,14 @@ export type PresenceUrlResponse =
|
||||
CurrentUser | {user: CurrentUser} |
|
||||
Friend | {friend: Friend};
|
||||
|
||||
export async function getPresenceFromUrl(presence_url: string) {
|
||||
export async function getPresenceFromUrl(presence_url: string, useragent?: string) {
|
||||
const [signal, cancel] = timeoutSignal();
|
||||
const response = await fetch(presence_url, {signal}).finally(cancel);
|
||||
const response = await fetch(presence_url, {
|
||||
headers: {
|
||||
'User-Agent': getUserAgent(useragent),
|
||||
},
|
||||
signal,
|
||||
}).finally(cancel);
|
||||
|
||||
debug('fetch %s %s, response %s', 'GET', presence_url, response.status);
|
||||
|
||||
|
||||
@@ -6,15 +6,19 @@ import { dir } from '../../util/product.js';
|
||||
|
||||
export const bundlepath = path.resolve(dir, 'dist', 'app', 'bundle');
|
||||
|
||||
export async function getNativeImageFromUrl(url: URL | string) {
|
||||
const response = await fetch(url.toString());
|
||||
export async function getNativeImageFromUrl(url: URL | string, useragent?: string) {
|
||||
const response = await fetch(url.toString(), {
|
||||
headers: {
|
||||
'User-Agent': useragent ?? '',
|
||||
},
|
||||
});
|
||||
const image = await response.arrayBuffer();
|
||||
return nativeImage.createFromBuffer(Buffer.from(image));
|
||||
}
|
||||
|
||||
export async function tryGetNativeImageFromUrl(url: URL | string) {
|
||||
export async function tryGetNativeImageFromUrl(url: URL | string, useragent?: string) {
|
||||
try {
|
||||
return await getNativeImageFromUrl(url);
|
||||
return await getNativeImageFromUrl(url, useragent);
|
||||
} catch (err) {}
|
||||
|
||||
return undefined;
|
||||
|
||||
@@ -273,7 +273,11 @@ export class WebServiceIpc {
|
||||
|
||||
debug('Downloading image %s to %s as %s', req.image_url, dir, filename);
|
||||
|
||||
const response = await fetch(req.image_url);
|
||||
const response = await fetch(req.image_url, {
|
||||
headers: {
|
||||
'User-Agent': '',
|
||||
},
|
||||
});
|
||||
const image = await response.arrayBuffer();
|
||||
await fs.writeFile(path.join(dir, filename), Buffer.from(image));
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { getToken } from '../../common/auth/nso.js';
|
||||
import { AuthPolicy, AuthToken } from '../../api/znc-proxy.js';
|
||||
import { Argv } from '../../util/yargs.js';
|
||||
import { initStorage } from '../../util/storage.js';
|
||||
import { getUserAgent } from '../../util/useragent.js';
|
||||
|
||||
const debug = createDebug('cli:nso:znc-proxy-tokens');
|
||||
|
||||
@@ -157,6 +158,7 @@ export function builder(yargs: Argv<ParentArguments>) {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + argv.token,
|
||||
'User-Agent': getUserAgent(),
|
||||
},
|
||||
});
|
||||
debug('fetch %s %s, response %d', 'DELETE', '/token', response.status);
|
||||
|
||||
@@ -8,6 +8,8 @@ import { DiscordPresenceContext, DiscordPresencePlayTime, getDiscordPresence, ge
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
|
||||
import { initStorage } from '../../util/storage.js';
|
||||
import { getToken } from '../../common/auth/nso.js';
|
||||
import { timeoutSignal } from '../../util/misc.js';
|
||||
import { getUserAgent } from '../../util/useragent.js';
|
||||
|
||||
const debug = createDebug('cli:util:discord-activity');
|
||||
|
||||
@@ -234,7 +236,14 @@ export async function getDiscordApplicationRpc(id: string) {
|
||||
|
||||
const url = 'https://discord.com/api/v9/applications/' + id + '/rpc';
|
||||
|
||||
const response = await fetch(url);
|
||||
const [signal, cancel] = timeoutSignal();
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'User-Agent': getUserAgent(),
|
||||
},
|
||||
signal,
|
||||
}).finally(cancel);
|
||||
|
||||
debug('fetch %s %s, response %s', 'GET', url, response.status);
|
||||
|
||||
if (response.status !== 200) {
|
||||
|
||||
@@ -108,7 +108,12 @@ export async function dumpProfileImage(
|
||||
|
||||
debug('Fetching profile image', share);
|
||||
const [signal, cancel] = timeoutSignal();
|
||||
const image_response = await fetch(share.url, {signal}).finally(cancel);
|
||||
const image_response = await fetch(share.url, {
|
||||
headers: {
|
||||
'User-Agent': splatnet.useragent,
|
||||
},
|
||||
signal,
|
||||
}).finally(cancel);
|
||||
const image = await image_response.arrayBuffer();
|
||||
|
||||
debug('Writing profile image %s', image_filename);
|
||||
@@ -142,7 +147,12 @@ export async function dumpChallenges(
|
||||
|
||||
debug('Fetching challenge image for %s', challenge.key, share);
|
||||
const [signal, cancel] = timeoutSignal();
|
||||
const image_response = await fetch(share.url, {signal}).finally(cancel);
|
||||
const image_response = await fetch(share.url, {
|
||||
headers: {
|
||||
'User-Agent': splatnet.useragent,
|
||||
},
|
||||
signal,
|
||||
}).finally(cancel);
|
||||
const image = await image_response.arrayBuffer();
|
||||
|
||||
debug('Writing challenge image %s', filename);
|
||||
|
||||
@@ -53,7 +53,12 @@ export async function dumpResults(
|
||||
|
||||
debug('Fetching battle results summary image', share);
|
||||
const [signal, cancel] = timeoutSignal();
|
||||
const image_response = await fetch(share.url, {signal}).finally(cancel);
|
||||
const image_response = await fetch(share.url, {
|
||||
headers: {
|
||||
'User-Agent': splatnet.useragent,
|
||||
},
|
||||
signal,
|
||||
}).finally(cancel);
|
||||
const image = await image_response.arrayBuffer();
|
||||
|
||||
debug('Writing battle results summary image %s', filename);
|
||||
@@ -111,7 +116,12 @@ export async function dumpResults(
|
||||
|
||||
debug('Fetching battle results image', share);
|
||||
const [signal, cancel] = timeoutSignal();
|
||||
const image_response = await fetch(share.url, {signal}).finally(cancel);
|
||||
const image_response = await fetch(share.url, {
|
||||
headers: {
|
||||
'User-Agent': splatnet.useragent,
|
||||
},
|
||||
signal,
|
||||
}).finally(cancel);
|
||||
const image = await image_response.arrayBuffer();
|
||||
|
||||
debug('Writing battle results image %s', filename);
|
||||
|
||||
22
src/exports/coral.ts
Normal file
22
src/exports/coral.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export { default } from '../api/coral.js';
|
||||
export * from '../api/coral-types.js';
|
||||
|
||||
export { default as ZncProxyApi } from '../api/znc-proxy.js';
|
||||
|
||||
export {
|
||||
ZncaApi,
|
||||
getZncaApiFromEnvironment,
|
||||
f,
|
||||
|
||||
ZncaApiFlapg,
|
||||
FlapgIid,
|
||||
FlapgApiResponse,
|
||||
|
||||
ZncaApiImink,
|
||||
IminkFResponse,
|
||||
IminkFError,
|
||||
|
||||
ZncaApiNxapi,
|
||||
AndroidZncaFResponse,
|
||||
AndroidZncaFError,
|
||||
} from '../api/f.js';
|
||||
3
src/exports/index.ts
Normal file
3
src/exports/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { getTitleIdFromEcUrl } from '../util/misc.js';
|
||||
export { ErrorResponse } from '../api/util.js';
|
||||
export { addUserAgent } from '../util/useragent.js';
|
||||
2
src/exports/moon.ts
Normal file
2
src/exports/moon.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default } from '../api/moon.js';
|
||||
export * from '../api/moon-types.js';
|
||||
7
src/exports/nooklink.ts
Normal file
7
src/exports/nooklink.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export {
|
||||
default as NooklinkApi,
|
||||
NooklinkUserApi,
|
||||
MessageType,
|
||||
} from '../api/nooklink.js';
|
||||
|
||||
export * from '../api/nooklink-types.js';
|
||||
19
src/exports/splatnet2.ts
Normal file
19
src/exports/splatnet2.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export {
|
||||
default,
|
||||
LeagueType,
|
||||
LeagueRegion,
|
||||
ShareColour as ShareProfileColour,
|
||||
toLeagueId,
|
||||
} from '../api/splatnet2.js';
|
||||
|
||||
export {
|
||||
Season as XRankSeason,
|
||||
Rule as XPowerRankingRule,
|
||||
getAllSeasons as getXRankSeasons,
|
||||
getSeason as getXRankSeason,
|
||||
getNextSeason as getNextXRankSeason,
|
||||
getPreviousSeason as getPreviousXRankSeason,
|
||||
toSeasonId as toXRankSeasonId,
|
||||
} from '../api/splatnet2-xrank.js';
|
||||
|
||||
export * from '../api/splatnet2-types.js';
|
||||
Reference in New Issue
Block a user