update built javascript files
This commit is contained in:
1 parent
c3d068a21c
commit
1796957cb9
4 files changed
+84
-45
No files matched your search
Vendored
+57
-34
@@ -6,6 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeWanikani = void 0;
|
||||
const axios_1 = __importDefault(require("axios"));
|
||||
const axios_rate_limit_1 = __importDefault(require("axios-rate-limit"));
|
||||
/**
|
||||
* https://docs.api.wanikani.com/20170710/#rate-limit
|
||||
*
|
||||
* Requests per minute 60
|
||||
*
|
||||
* @param apiKey @default process.env['WANIKANI_API_KEY']
|
||||
* @returns
|
||||
*/
|
||||
function makeWanikani(apiKey = process.env['WANIKANI_API_KEY']) {
|
||||
const wkApi = (0, axios_rate_limit_1.default)(axios_1.default.create({
|
||||
baseURL: 'https://api.wanikani.com/v2/',
|
||||
@@ -15,12 +23,7 @@ function makeWanikani(apiKey = process.env['WANIKANI_API_KEY']) {
|
||||
validateStatus: function () {
|
||||
return true;
|
||||
},
|
||||
}),
|
||||
/**
|
||||
* https://docs.api.wanikani.com/20170710/#rate-limit
|
||||
* Requests per minute 60
|
||||
*/
|
||||
{
|
||||
}), {
|
||||
/**
|
||||
* Per second
|
||||
*/
|
||||
@@ -28,74 +31,94 @@ function makeWanikani(apiKey = process.env['WANIKANI_API_KEY']) {
|
||||
perMilliseconds: 1000,
|
||||
});
|
||||
return Object.assign(wkApi, {
|
||||
async getKanji() {
|
||||
const allData = [];
|
||||
async *kanji(params = {}) {
|
||||
let nextUrl = '/subjects';
|
||||
while (true) {
|
||||
const r = await wkApi.get(nextUrl, {
|
||||
params: {
|
||||
...params,
|
||||
types: 'kanji',
|
||||
},
|
||||
});
|
||||
allData.push(...r.data.data.map((d) => ({
|
||||
id: d.id,
|
||||
level: d.data.level,
|
||||
characters: d.data.characters,
|
||||
})));
|
||||
for (const d of r.data.data) {
|
||||
yield {
|
||||
id: d.id,
|
||||
level: d.data.level,
|
||||
characters: d.data.characters,
|
||||
};
|
||||
}
|
||||
console.error(r.data.url);
|
||||
nextUrl = r.data.pages.next_url || '';
|
||||
if (!nextUrl) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return allData;
|
||||
},
|
||||
async getVocab() {
|
||||
const allData = [];
|
||||
async *vocabulary(params = {}) {
|
||||
let nextUrl = '/subjects';
|
||||
while (true) {
|
||||
const r = await wkApi.get(nextUrl, {
|
||||
params: {
|
||||
...params,
|
||||
types: 'vocabulary',
|
||||
},
|
||||
});
|
||||
allData.push(...r.data.data.map((d) => ({
|
||||
id: d.id,
|
||||
level: d.data.level,
|
||||
characters: d.data.characters,
|
||||
sentences: d.data.context_sentences,
|
||||
})));
|
||||
for (const d of r.data.data) {
|
||||
yield {
|
||||
id: d.id,
|
||||
level: d.data.level,
|
||||
characters: d.data.characters,
|
||||
sentences: d.data.context_sentences,
|
||||
};
|
||||
}
|
||||
console.error(r.data.url);
|
||||
nextUrl = r.data.pages.next_url || '';
|
||||
if (!nextUrl) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return allData;
|
||||
},
|
||||
async getLearnt() {
|
||||
const allData = [];
|
||||
async *subjects(params = {}) {
|
||||
let nextUrl = '/subjects';
|
||||
while (true) {
|
||||
const r = await wkApi.get(nextUrl, { params });
|
||||
for (const d of r.data.data) {
|
||||
yield {
|
||||
id: d.id,
|
||||
data_updated_at: d.data_updated_at,
|
||||
object: d.object,
|
||||
url: d.url,
|
||||
data: d.data,
|
||||
};
|
||||
}
|
||||
console.error(r.data.url);
|
||||
nextUrl = r.data.pages.next_url || '';
|
||||
if (!nextUrl) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
async *assignments(params = {
|
||||
unlocked: 'true',
|
||||
}) {
|
||||
let nextUrl = '/assignments';
|
||||
while (true) {
|
||||
const r = await wkApi.get(nextUrl, {
|
||||
params: {
|
||||
unlocked: 'true',
|
||||
},
|
||||
params,
|
||||
});
|
||||
console.error(r.data.url);
|
||||
r.data.data.map((d) => {
|
||||
allData.push({
|
||||
for (const d of r.data.data) {
|
||||
yield {
|
||||
id: d.data.subject_id,
|
||||
srsLevel: d.data.srs_stage,
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
nextUrl = r.data.pages.next_url || '';
|
||||
if (!nextUrl) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return allData;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
exports.makeWanikani = makeWanikani;
|
||||
|
||||
Reference in new issue
Block a user