2021-12-18 13:55:31 +00:00
|
|
|
import { fromByteArray as Base64Encode } from 'base64-js';
|
2021-05-24 15:48:52 +00:00
|
|
|
|
2021-12-18 13:55:31 +00:00
|
|
|
export const IXAREA_API_ENDPOINT = 'https://um-api.ixarea.com';
|
2021-05-24 15:48:52 +00:00
|
|
|
|
|
|
|
export interface UpdateInfo {
|
2021-12-18 13:55:31 +00:00
|
|
|
Found: boolean;
|
|
|
|
HttpsFound: boolean;
|
|
|
|
Version: string;
|
|
|
|
URL: string;
|
|
|
|
Detail: string;
|
2021-05-24 15:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function checkUpdate(version: string): Promise<UpdateInfo> {
|
2021-12-18 13:55:31 +00:00
|
|
|
const resp = await fetch(IXAREA_API_ENDPOINT + '/music/app-version', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
body: JSON.stringify({ Version: version }),
|
|
|
|
});
|
|
|
|
return await resp.json();
|
2021-05-24 15:48:52 +00:00
|
|
|
}
|
|
|
|
|
2021-12-18 13:55:31 +00:00
|
|
|
export function reportKeyUsage(
|
|
|
|
keyData: Uint8Array,
|
|
|
|
maskData: number[],
|
|
|
|
filename: string,
|
|
|
|
format: string,
|
|
|
|
title: string,
|
|
|
|
artist?: string,
|
|
|
|
album?: string,
|
|
|
|
) {
|
|
|
|
return fetch(IXAREA_API_ENDPOINT + '/qmcmask/usage', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
body: JSON.stringify({
|
|
|
|
Mask: Base64Encode(new Uint8Array(maskData)),
|
|
|
|
Key: Base64Encode(keyData),
|
|
|
|
Artist: artist,
|
|
|
|
Title: title,
|
|
|
|
Album: album,
|
|
|
|
Filename: filename,
|
|
|
|
Format: format,
|
|
|
|
}),
|
|
|
|
});
|
2021-05-24 15:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface KeyInfo {
|
2021-12-18 13:55:31 +00:00
|
|
|
Matrix44: string;
|
2021-05-24 15:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function queryKeyInfo(keyData: Uint8Array, filename: string, format: string): Promise<KeyInfo> {
|
2021-12-18 13:55:31 +00:00
|
|
|
const resp = await fetch(IXAREA_API_ENDPOINT + '/qmcmask/query', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
body: JSON.stringify({ Format: format, Key: Base64Encode(keyData), Filename: filename, Type: 44 }),
|
|
|
|
});
|
|
|
|
return await resp.json();
|
2021-05-24 15:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CoverInfo {
|
2021-12-18 13:55:31 +00:00
|
|
|
Id: string;
|
|
|
|
Type: number;
|
2021-05-24 15:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function queryAlbumCover(title: string, artist?: string, album?: string): Promise<CoverInfo> {
|
2021-12-18 13:55:31 +00:00
|
|
|
const endpoint = IXAREA_API_ENDPOINT + '/music/qq-cover';
|
|
|
|
const params = new URLSearchParams([
|
|
|
|
['Title', title],
|
|
|
|
['Artist', artist ?? ''],
|
|
|
|
['Album', album ?? ''],
|
|
|
|
]);
|
|
|
|
const resp = await fetch(`${endpoint}?${params.toString()}`);
|
|
|
|
return await resp.json();
|
2021-05-24 15:48:52 +00:00
|
|
|
}
|