mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-07-03 16:40:52 -05:00
Coral 3.3.0
This commit is contained in:
parent
5eb9bddc0d
commit
f4aed98a1d
|
|
@ -181,6 +181,7 @@ export interface Friend {
|
|||
export interface Friend_4 extends Friend {
|
||||
isOnlineNotificationEnabled: boolean;
|
||||
presence: PresenceOnline_4 | PresenceOffline;
|
||||
note: string;
|
||||
}
|
||||
|
||||
export interface FriendRoute {
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ const debug = createDebug('nxapi:api:coral');
|
|||
|
||||
const ZNCA_PLATFORM = 'Android';
|
||||
const ZNCA_PLATFORM_VERSION = '12';
|
||||
export const ZNCA_VERSION = '3.2.0'; // TODO: update to 3.1.0
|
||||
export const ZNCA_VERSION = '3.3.0';
|
||||
const ZNCA_USER_AGENT = `com.nintendo.znca/${ZNCA_VERSION}(${ZNCA_PLATFORM}/${ZNCA_PLATFORM_VERSION})`;
|
||||
|
||||
export const ZNCA_API_COMPATIBILITY_VERSION = 'hio87-mJks_e9GNF';
|
||||
export const ZNCA_API_COMPATIBILITY_VERSION = 'w8zSLBsxR7rVoGJA';
|
||||
|
||||
const ZNC_URL = 'https://api-lp1.znc.srv.nintendo.net';
|
||||
export const ZNCA_CLIENT_ID = '71b963c1b7b6d119';
|
||||
|
|
@ -53,6 +53,7 @@ export interface ResponseEncryption {
|
|||
export interface CoralApiInterface {
|
||||
getAnnouncements(): Promise<Result<Announcements_4>>;
|
||||
getFriendList(): Promise<Result<Friends_4>>;
|
||||
updateFriendNote(nsa_id: string, note: string): Promise<Result<{}>>;
|
||||
addFavouriteFriend(nsa_id: string): Promise<Result<{}>>;
|
||||
removeFavouriteFriend(nsa_id: string): Promise<Result<{}>>;
|
||||
deleteFriendIsNew(nsa_id: string): Promise<Result<{}>>;
|
||||
|
|
@ -149,13 +150,21 @@ export abstract class AbstractCoralApi {
|
|||
});
|
||||
}
|
||||
|
||||
/** @deprecated unused */
|
||||
async getFriend(nsa_id: string) {
|
||||
return this.call<Friend_4, {nsaId: string}>('/v4/Friend/Show', {
|
||||
nsaId: nsa_id,
|
||||
});
|
||||
}
|
||||
|
||||
async updateFriendNote(nsa_id: string, note: string) {
|
||||
if (note.length > 20) throw new TypeError('Friend note cannot be longer than 20 characters');
|
||||
|
||||
return this.call<{}, {friendNsaId: string; note: string}>('/v4/Friend/Note/Update', {
|
||||
friendNsaId: nsa_id,
|
||||
note,
|
||||
});
|
||||
}
|
||||
|
||||
async getPlayLog(nsa_id: string) {
|
||||
return this.call<UserPlayLog, {nsaId: string}>('/v4/User/PlayLog/Show', {
|
||||
nsaId: nsa_id,
|
||||
|
|
|
|||
|
|
@ -114,6 +114,15 @@ export default class ZncProxyApi extends AbstractCoralApi implements CoralApiInt
|
|||
return createResult(result, result.friend);
|
||||
}
|
||||
|
||||
async updateFriendNote(nsa_id: string, note: string) {
|
||||
if (note.length > 20) throw new TypeError('Friend note cannot be longer than 20 characters');
|
||||
|
||||
const result = await this.fetchProxyApi('friend/' + nsa_id, 'PATCH', JSON.stringify({
|
||||
note,
|
||||
}));
|
||||
return createResult(result, {});
|
||||
}
|
||||
|
||||
async addFavouriteFriend(nsa_id: string) {
|
||||
const result = await this.fetchProxyApi('friend/' + nsa_id, 'PATCH', JSON.stringify({
|
||||
isFavoriteFriend: true,
|
||||
|
|
|
|||
|
|
@ -645,11 +645,17 @@ class Server extends HttpServer {
|
|||
throw new ResponseError(400, 'invalid_request', 'Invalid value for isFavoriteFriend.');
|
||||
}
|
||||
|
||||
if ('isNew' in req.body && (typeof req.body.isNew !== 'boolean' ||
|
||||
if ('isNew' in req.body && (
|
||||
typeof req.body.isNew !== 'boolean' ||
|
||||
// Cannot set friend as isNew
|
||||
(!friend.isNew && req.body.isNew)
|
||||
)) {
|
||||
throw new ResponseError(400, 'invalid_request', 'Invalid value for isNew.');
|
||||
} else if ('isNew' in req.body && req.body.isNew && (
|
||||
'isFavoriteFriend' in req.body ||
|
||||
'note' in req.body
|
||||
)) {
|
||||
throw new ResponseError(400, 'invalid_request', 'Invalid value for isNew.');
|
||||
}
|
||||
|
||||
if ('isOnlineNotificationEnabled' in req.body &&
|
||||
|
|
@ -658,6 +664,13 @@ class Server extends HttpServer {
|
|||
throw new ResponseError(400, 'invalid_request', 'Invalid value for isOnlineNotificationEnabled.');
|
||||
}
|
||||
|
||||
if ('note' in req.body && (
|
||||
typeof req.body.note !== 'string' ||
|
||||
req.body.note.length > 20
|
||||
)) {
|
||||
throw new ResponseError(400, 'invalid_request', 'Invalid value for note.');
|
||||
}
|
||||
|
||||
if ('isNew' in req.body) {
|
||||
if (friend.isNew !== req.body.isNew) {
|
||||
if (!req.body.isNew) await user.nso.deleteFriendIsNew(friend.nsaId);
|
||||
|
|
@ -668,7 +681,7 @@ class Server extends HttpServer {
|
|||
// No change
|
||||
}
|
||||
} else {
|
||||
if (friend.isNew && 'isFavoriteFriend' in req.body) {
|
||||
if (friend.isNew && ('isFavoriteFriend' in req.body || 'note' in req.body)) {
|
||||
// If updating the friend they should have been marked as not new
|
||||
// It *is* possible to update the friend online notification setting
|
||||
// without doing this though
|
||||
|
|
@ -703,6 +716,17 @@ class Server extends HttpServer {
|
|||
}
|
||||
}
|
||||
|
||||
if ('note' in req.body) {
|
||||
if (friend.note !== req.body.note) {
|
||||
await user.nso.updateFriendNote(friend.nsaId, req.body.note);
|
||||
|
||||
// Update cached data
|
||||
friend.note = req.body.note;
|
||||
} else {
|
||||
// No change
|
||||
}
|
||||
}
|
||||
|
||||
if (post) {
|
||||
res.statusCode = 204;
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user