@mx-space/api-client 0.0.5 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs.js +411 -53
- package/build/index.cjs.js.map +1 -1
- package/build/index.cjs.min.js +1 -1
- package/build/index.cjs.min.js.map +1 -1
- package/build/index.d.ts +463 -108
- package/build/index.esm.js +411 -53
- package/build/index.esm.js.map +1 -1
- package/build/index.esm.min.js +1 -1
- package/build/index.esm.min.js.map +1 -1
- package/build/index.umd.js +411 -53
- package/build/index.umd.js.map +1 -1
- package/build/index.umd.min.js +1 -1
- package/build/index.umd.min.js.map +1 -1
- package/esm/core/attachRequest.js +4 -0
- package/esm/core/attachRequest.js.map +1 -1
- package/esm/core/client.d.ts +2 -9
- package/esm/core/client.js +16 -2
- package/esm/core/client.js.map +1 -1
- package/esm/core/controllers/aggregate.d.ts +44 -0
- package/esm/core/controllers/aggregate.js +40 -0
- package/esm/core/controllers/aggregate.js.map +1 -0
- package/esm/core/controllers/all.d.ts +13 -2
- package/esm/core/controllers/all.js +38 -9
- package/esm/core/controllers/all.js.map +1 -1
- package/esm/core/controllers/base.d.ts +29 -0
- package/esm/core/controllers/base.js +25 -0
- package/esm/core/controllers/base.js.map +1 -0
- package/esm/core/controllers/category.d.ts +44 -0
- package/esm/core/controllers/category.js +66 -0
- package/esm/core/controllers/category.js.map +1 -0
- package/esm/core/controllers/index.d.ts +0 -2
- package/esm/core/controllers/index.js +0 -3
- package/esm/core/controllers/index.js.map +1 -1
- package/esm/core/controllers/link.d.ts +9 -0
- package/esm/core/controllers/link.js +10 -0
- package/esm/core/controllers/link.js.map +1 -0
- package/esm/core/controllers/project.d.ts +9 -0
- package/esm/core/controllers/project.js +10 -0
- package/esm/core/controllers/project.js.map +1 -0
- package/esm/core/controllers/recently.d.ts +33 -0
- package/esm/core/controllers/recently.js +32 -0
- package/esm/core/controllers/recently.js.map +1 -0
- package/esm/core/controllers/say.d.ts +22 -0
- package/esm/core/controllers/say.js +19 -0
- package/esm/core/controllers/say.js.map +1 -0
- package/esm/core/controllers/search.d.ts +58 -0
- package/esm/core/controllers/search.js +26 -0
- package/esm/core/controllers/search.js.map +1 -0
- package/esm/core/controllers/snippet.d.ts +18 -0
- package/esm/core/controllers/snippet.js +17 -0
- package/esm/core/controllers/snippet.js.map +1 -0
- package/esm/core/controllers/user.d.ts +28 -0
- package/esm/core/controllers/user.js +29 -0
- package/esm/core/controllers/user.js.map +1 -0
- package/esm/core/define.d.ts +19 -0
- package/esm/core/define.js +12 -0
- package/esm/core/define.js.map +1 -0
- package/esm/interfaces/options.d.ts +1 -0
- package/esm/interfaces/options.js +2 -0
- package/esm/interfaces/options.js.map +1 -0
- package/esm/interfaces/request.d.ts +9 -3
- package/esm/models/aggregate.d.ts +47 -0
- package/esm/models/aggregate.js +6 -0
- package/esm/models/aggregate.js.map +1 -0
- package/esm/models/category.d.ts +24 -0
- package/esm/models/category.js +6 -0
- package/esm/models/category.js.map +1 -0
- package/esm/models/link.d.ts +17 -0
- package/esm/models/link.js +11 -0
- package/esm/models/link.js.map +1 -0
- package/esm/models/project.d.ts +16 -0
- package/esm/models/project.js +2 -0
- package/esm/models/project.js.map +1 -0
- package/esm/models/recently.d.ts +5 -0
- package/esm/models/recently.js +2 -0
- package/esm/models/recently.js.map +1 -0
- package/esm/models/say.d.ts +6 -0
- package/esm/models/say.js +2 -0
- package/esm/models/say.js.map +1 -0
- package/esm/models/setting.d.ts +66 -0
- package/esm/models/setting.js +2 -0
- package/esm/models/setting.js.map +1 -0
- package/esm/models/snippet.d.ts +14 -0
- package/esm/models/snippet.js +7 -0
- package/esm/models/snippet.js.map +1 -0
- package/esm/models/user.d.ts +29 -0
- package/esm/models/user.js +2 -0
- package/esm/models/user.js.map +1 -0
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.js +38 -0
- package/esm/utils/index.js.map +1 -1
- package/lib/core/attachRequest.js +4 -0
- package/lib/core/attachRequest.js.map +1 -1
- package/lib/core/client.d.ts +2 -9
- package/lib/core/client.js +16 -2
- package/lib/core/client.js.map +1 -1
- package/lib/core/controllers/aggregate.d.ts +44 -0
- package/lib/core/controllers/aggregate.js +44 -0
- package/lib/core/controllers/aggregate.js.map +1 -0
- package/lib/core/controllers/all.d.ts +13 -2
- package/lib/core/controllers/all.js +52 -11
- package/lib/core/controllers/all.js.map +1 -1
- package/lib/core/controllers/base.d.ts +29 -0
- package/lib/core/controllers/base.js +29 -0
- package/lib/core/controllers/base.js.map +1 -0
- package/lib/core/controllers/category.d.ts +44 -0
- package/lib/core/controllers/category.js +70 -0
- package/lib/core/controllers/category.js.map +1 -0
- package/lib/core/controllers/index.d.ts +0 -2
- package/lib/core/controllers/index.js +0 -3
- package/lib/core/controllers/index.js.map +1 -1
- package/lib/core/controllers/link.d.ts +9 -0
- package/lib/core/controllers/link.js +14 -0
- package/lib/core/controllers/link.js.map +1 -0
- package/lib/core/controllers/project.d.ts +9 -0
- package/lib/core/controllers/project.js +14 -0
- package/lib/core/controllers/project.js.map +1 -0
- package/lib/core/controllers/recently.d.ts +33 -0
- package/lib/core/controllers/recently.js +36 -0
- package/lib/core/controllers/recently.js.map +1 -0
- package/lib/core/controllers/say.d.ts +22 -0
- package/lib/core/controllers/say.js +23 -0
- package/lib/core/controllers/say.js.map +1 -0
- package/lib/core/controllers/search.d.ts +58 -0
- package/lib/core/controllers/search.js +30 -0
- package/lib/core/controllers/search.js.map +1 -0
- package/lib/core/controllers/snippet.d.ts +18 -0
- package/lib/core/controllers/snippet.js +21 -0
- package/lib/core/controllers/snippet.js.map +1 -0
- package/lib/core/controllers/user.d.ts +28 -0
- package/lib/core/controllers/user.js +33 -0
- package/lib/core/controllers/user.js.map +1 -0
- package/lib/core/define.d.ts +19 -0
- package/lib/core/define.js +16 -0
- package/lib/core/define.js.map +1 -0
- package/lib/interfaces/options.d.ts +1 -0
- package/lib/interfaces/options.js +3 -0
- package/lib/interfaces/options.js.map +1 -0
- package/lib/interfaces/request.d.ts +9 -3
- package/lib/models/aggregate.d.ts +47 -0
- package/lib/models/aggregate.js +9 -0
- package/lib/models/aggregate.js.map +1 -0
- package/lib/models/category.d.ts +24 -0
- package/lib/models/category.js +9 -0
- package/lib/models/category.js.map +1 -0
- package/lib/models/link.d.ts +17 -0
- package/lib/models/link.js +14 -0
- package/lib/models/link.js.map +1 -0
- package/lib/models/project.d.ts +16 -0
- package/lib/models/project.js +3 -0
- package/lib/models/project.js.map +1 -0
- package/lib/models/recently.d.ts +5 -0
- package/lib/models/recently.js +3 -0
- package/lib/models/recently.js.map +1 -0
- package/lib/models/say.d.ts +6 -0
- package/lib/models/say.js +3 -0
- package/lib/models/say.js.map +1 -0
- package/lib/models/setting.d.ts +66 -0
- package/lib/models/setting.js +3 -0
- package/lib/models/setting.js.map +1 -0
- package/lib/models/snippet.d.ts +14 -0
- package/lib/models/snippet.js +10 -0
- package/lib/models/snippet.js.map +1 -0
- package/lib/models/user.d.ts +29 -0
- package/lib/models/user.js +3 -0
- package/lib/models/user.js.map +1 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +42 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +11 -11
package/build/index.esm.js
CHANGED
|
@@ -360,6 +360,44 @@ var camelcaseKeys = (input, options) => {
|
|
|
360
360
|
|
|
361
361
|
const isPlainObject = (obj) => typeof obj === 'object' &&
|
|
362
362
|
Object.prototype.toString.call(obj) === '[object Object]';
|
|
363
|
+
const sortOrderToNumber = (order) => {
|
|
364
|
+
return ({
|
|
365
|
+
asc: 1,
|
|
366
|
+
desc: -1,
|
|
367
|
+
}[order] || 1);
|
|
368
|
+
};
|
|
369
|
+
const destructureData = (payload) => {
|
|
370
|
+
if (typeof payload !== 'object') {
|
|
371
|
+
return payload;
|
|
372
|
+
}
|
|
373
|
+
if (payload === null) {
|
|
374
|
+
return payload;
|
|
375
|
+
}
|
|
376
|
+
const data = payload.data;
|
|
377
|
+
const dataIsPlainObject = Object.prototype.toString.call(data) === '[object Object]';
|
|
378
|
+
if (dataIsPlainObject && Object.keys(payload).length === 1) {
|
|
379
|
+
const d = Object.assign({}, data);
|
|
380
|
+
// attach raw onto new data
|
|
381
|
+
attachRawFromOneToAnthor(payload, d);
|
|
382
|
+
return d;
|
|
383
|
+
}
|
|
384
|
+
return payload;
|
|
385
|
+
};
|
|
386
|
+
const attachRawFromOneToAnthor = (from, to) => {
|
|
387
|
+
if (!from) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
from.$raw &&
|
|
391
|
+
Object.defineProperty(to, '$raw', {
|
|
392
|
+
value: Object.assign({}, from.$raw),
|
|
393
|
+
enumerable: false,
|
|
394
|
+
});
|
|
395
|
+
from.$request &&
|
|
396
|
+
Object.defineProperty(to, '$request', {
|
|
397
|
+
value: Object.assign({}, from.$request),
|
|
398
|
+
enumerable: false,
|
|
399
|
+
});
|
|
400
|
+
};
|
|
363
401
|
|
|
364
402
|
function attachRequestMethod(target) {
|
|
365
403
|
Object.defineProperty(target, '$$get', {
|
|
@@ -386,11 +424,200 @@ function handleSearchParams(obj) {
|
|
|
386
424
|
}
|
|
387
425
|
const search = new URLSearchParams();
|
|
388
426
|
Object.entries(obj).forEach(([k, v]) => {
|
|
427
|
+
if (typeof v === 'undefined' ||
|
|
428
|
+
Object.prototype.toString.call(v) === '[object Null]') {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
389
431
|
search.set(k, v);
|
|
390
432
|
});
|
|
391
433
|
return search.toString();
|
|
392
434
|
}
|
|
393
435
|
|
|
436
|
+
class AggregateController {
|
|
437
|
+
constructor(client) {
|
|
438
|
+
this.client = client;
|
|
439
|
+
this.base = 'aggregate';
|
|
440
|
+
this.name = 'aggregate';
|
|
441
|
+
}
|
|
442
|
+
get proxy() {
|
|
443
|
+
return this.client.proxy(this.base);
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* 获取聚合数据
|
|
447
|
+
*/
|
|
448
|
+
getAggregateData() {
|
|
449
|
+
return this.proxy.get();
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* 获取最新发布的内容
|
|
453
|
+
*/
|
|
454
|
+
getTop(size = 5) {
|
|
455
|
+
return this.proxy.top.get({ params: { size } });
|
|
456
|
+
}
|
|
457
|
+
getTimeline(options) {
|
|
458
|
+
const { sort, type, year } = options || {};
|
|
459
|
+
return this.proxy.timeline.get({
|
|
460
|
+
params: {
|
|
461
|
+
sort: sort && sortOrderToNumber(sort),
|
|
462
|
+
type,
|
|
463
|
+
year,
|
|
464
|
+
},
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* 获取聚合数据统计
|
|
469
|
+
*/
|
|
470
|
+
getStat() {
|
|
471
|
+
return this.proxy.stat.get();
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
var CategoryType;
|
|
476
|
+
(function (CategoryType) {
|
|
477
|
+
CategoryType[CategoryType["Category"] = 0] = "Category";
|
|
478
|
+
CategoryType[CategoryType["Tag"] = 1] = "Tag";
|
|
479
|
+
})(CategoryType || (CategoryType = {}));
|
|
480
|
+
|
|
481
|
+
class CategoryController {
|
|
482
|
+
constructor(client) {
|
|
483
|
+
this.client = client;
|
|
484
|
+
this.name = 'category';
|
|
485
|
+
this.base = 'categories';
|
|
486
|
+
}
|
|
487
|
+
get proxy() {
|
|
488
|
+
return this.client.proxy(this.base);
|
|
489
|
+
}
|
|
490
|
+
getAllCategories() {
|
|
491
|
+
return this.proxy.get({
|
|
492
|
+
params: {
|
|
493
|
+
type: CategoryType.Category,
|
|
494
|
+
},
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
getAllTags() {
|
|
498
|
+
return this.proxy.get({
|
|
499
|
+
params: {
|
|
500
|
+
type: CategoryType.Tag,
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
async getCategoryDetail(ids) {
|
|
505
|
+
if (typeof ids === 'string') {
|
|
506
|
+
const data = await this.proxy.get({
|
|
507
|
+
params: {
|
|
508
|
+
ids: ids,
|
|
509
|
+
},
|
|
510
|
+
});
|
|
511
|
+
const result = Object.values(data.entries)[0];
|
|
512
|
+
attachRawFromOneToAnthor(data, result);
|
|
513
|
+
return result;
|
|
514
|
+
}
|
|
515
|
+
else if (Array.isArray(ids)) {
|
|
516
|
+
const data = await this.proxy.get({
|
|
517
|
+
params: {
|
|
518
|
+
ids: ids.join(','),
|
|
519
|
+
},
|
|
520
|
+
});
|
|
521
|
+
const entries = data === null || data === void 0 ? void 0 : data.entries;
|
|
522
|
+
if (!entries) {
|
|
523
|
+
throw new RequestError('data structure error', 500, data.$request.path, data);
|
|
524
|
+
}
|
|
525
|
+
const map = new Map(Object.entries(entries).map(([id, value]) => [id.toLowerCase(), value]));
|
|
526
|
+
attachRawFromOneToAnthor(data, map);
|
|
527
|
+
return map;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
async getCategoryByIdOrSlug(idOrSlug) {
|
|
531
|
+
const res = await this.proxy(idOrSlug).get();
|
|
532
|
+
return destructureData(res);
|
|
533
|
+
}
|
|
534
|
+
async getTagByName(name) {
|
|
535
|
+
const res = await this.proxy(name).get({
|
|
536
|
+
params: {
|
|
537
|
+
tag: 1,
|
|
538
|
+
},
|
|
539
|
+
});
|
|
540
|
+
return res;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
class CommentController {
|
|
545
|
+
constructor(client) {
|
|
546
|
+
this.client = client;
|
|
547
|
+
this.base = 'comments';
|
|
548
|
+
this.name = 'comment';
|
|
549
|
+
}
|
|
550
|
+
get proxy() {
|
|
551
|
+
return this.client.proxy(this.base);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* 根据 comment id 获取评论, 包括子评论
|
|
555
|
+
*/
|
|
556
|
+
getById(id) {
|
|
557
|
+
return this.proxy(id).get();
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* 获取文章的评论列表
|
|
561
|
+
* @param refId 文章 Id
|
|
562
|
+
*/
|
|
563
|
+
getByRefId(refId, pagination = {}) {
|
|
564
|
+
const { page, size } = pagination;
|
|
565
|
+
return this.proxy.ref(refId).get({
|
|
566
|
+
params: { page: page || 1, size: size || 10 },
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* 评论
|
|
571
|
+
*/
|
|
572
|
+
comment(refId, data) {
|
|
573
|
+
return this.proxy(refId).post({
|
|
574
|
+
data,
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* 回复评论
|
|
579
|
+
*/
|
|
580
|
+
reply(commentId, data) {
|
|
581
|
+
return this.proxy.reply(commentId).post({
|
|
582
|
+
data,
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
class BaseCrudController {
|
|
588
|
+
constructor(client) {
|
|
589
|
+
this.client = client;
|
|
590
|
+
}
|
|
591
|
+
get proxy() {
|
|
592
|
+
return this.client.proxy(this.base);
|
|
593
|
+
}
|
|
594
|
+
getById(id) {
|
|
595
|
+
return this.proxy(id).get();
|
|
596
|
+
}
|
|
597
|
+
getAll() {
|
|
598
|
+
return this.proxy.all.get();
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* 带分页的查询
|
|
602
|
+
* @param page
|
|
603
|
+
* @param perPage
|
|
604
|
+
*/
|
|
605
|
+
getAllPaginated(page, perPage) {
|
|
606
|
+
return this.proxy.get({
|
|
607
|
+
params: { page, size: perPage },
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
class LinkController extends BaseCrudController {
|
|
613
|
+
constructor(client) {
|
|
614
|
+
super(client);
|
|
615
|
+
this.client = client;
|
|
616
|
+
this.name = 'link';
|
|
617
|
+
this.base = 'links';
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
394
621
|
class NoteController {
|
|
395
622
|
constructor(client) {
|
|
396
623
|
this.client = client;
|
|
@@ -445,6 +672,39 @@ class NoteController {
|
|
|
445
672
|
}
|
|
446
673
|
}
|
|
447
674
|
|
|
675
|
+
class PageController {
|
|
676
|
+
constructor(client) {
|
|
677
|
+
this.client = client;
|
|
678
|
+
this.base = 'pages';
|
|
679
|
+
this.name = 'page';
|
|
680
|
+
}
|
|
681
|
+
get proxy() {
|
|
682
|
+
return this.client.proxy(this.base);
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* 页面列表
|
|
686
|
+
*/
|
|
687
|
+
getList(page = 1, perPage = 10) {
|
|
688
|
+
return this.proxy.get({
|
|
689
|
+
params: { page, size: perPage },
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* 页面详情
|
|
694
|
+
*/
|
|
695
|
+
getById(id) {
|
|
696
|
+
return this.proxy(id).get();
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* 根据路径获取页面
|
|
700
|
+
* @param slug 路径
|
|
701
|
+
* @returns
|
|
702
|
+
*/
|
|
703
|
+
getBySlug(slug) {
|
|
704
|
+
return this.proxy.slug(slug).get({});
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
448
708
|
class PostController {
|
|
449
709
|
constructor(client) {
|
|
450
710
|
this.client = client;
|
|
@@ -487,94 +747,179 @@ class PostController {
|
|
|
487
747
|
}
|
|
488
748
|
}
|
|
489
749
|
|
|
490
|
-
class
|
|
750
|
+
class ProjectController extends BaseCrudController {
|
|
491
751
|
constructor(client) {
|
|
752
|
+
super(client);
|
|
492
753
|
this.client = client;
|
|
493
|
-
this.base = '
|
|
494
|
-
this.name = '
|
|
754
|
+
this.base = 'projects';
|
|
755
|
+
this.name = 'project';
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
class RecentlyController {
|
|
760
|
+
constructor(client) {
|
|
761
|
+
this.client = client;
|
|
762
|
+
this.base = 'recently';
|
|
763
|
+
this.name = 'recently';
|
|
495
764
|
}
|
|
496
765
|
get proxy() {
|
|
497
766
|
return this.client.proxy(this.base);
|
|
498
767
|
}
|
|
499
768
|
/**
|
|
500
|
-
*
|
|
769
|
+
* 获取最新一条
|
|
501
770
|
*/
|
|
502
|
-
|
|
503
|
-
return this.proxy
|
|
771
|
+
getLatestOne() {
|
|
772
|
+
return this.proxy.latest.get();
|
|
504
773
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
* @param refId 文章 Id
|
|
508
|
-
*/
|
|
509
|
-
getByRefId(refId, pagination = {}) {
|
|
510
|
-
const { page, size } = pagination;
|
|
511
|
-
return this.proxy.ref(refId).get({
|
|
512
|
-
params: { page: page || 1, size: size || 10 },
|
|
513
|
-
});
|
|
774
|
+
getAll() {
|
|
775
|
+
return this.proxy.all.get();
|
|
514
776
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
return this.proxy
|
|
520
|
-
|
|
777
|
+
getList(before, after, size) {
|
|
778
|
+
if (!before && !after) {
|
|
779
|
+
throw new Error('you can only choose `before` or `after`');
|
|
780
|
+
}
|
|
781
|
+
return this.proxy.get({
|
|
782
|
+
params: {
|
|
783
|
+
before,
|
|
784
|
+
after,
|
|
785
|
+
size,
|
|
786
|
+
},
|
|
521
787
|
});
|
|
522
788
|
}
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
class SayController extends BaseCrudController {
|
|
792
|
+
constructor(client) {
|
|
793
|
+
super(client);
|
|
794
|
+
this.client = client;
|
|
795
|
+
this.base = 'says';
|
|
796
|
+
this.name = 'say';
|
|
797
|
+
}
|
|
798
|
+
get proxy() {
|
|
799
|
+
return this.client.proxy(this.base);
|
|
800
|
+
}
|
|
523
801
|
/**
|
|
524
|
-
*
|
|
802
|
+
* 获取随机一条
|
|
525
803
|
*/
|
|
526
|
-
|
|
527
|
-
return this.proxy.
|
|
528
|
-
data,
|
|
529
|
-
});
|
|
804
|
+
getRandom() {
|
|
805
|
+
return this.proxy.random.get();
|
|
530
806
|
}
|
|
531
807
|
}
|
|
532
808
|
|
|
533
|
-
class
|
|
809
|
+
class SearchController {
|
|
534
810
|
constructor(client) {
|
|
535
811
|
this.client = client;
|
|
536
|
-
this.base = '
|
|
537
|
-
this.name = '
|
|
812
|
+
this.base = 'search';
|
|
813
|
+
this.name = 'search';
|
|
538
814
|
}
|
|
539
815
|
get proxy() {
|
|
540
816
|
return this.client.proxy(this.base);
|
|
541
817
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
getList(page = 1, perPage = 10) {
|
|
546
|
-
return this.proxy.get({
|
|
547
|
-
params: { page, size: perPage },
|
|
818
|
+
search(type, keyword, options = {}) {
|
|
819
|
+
return this.proxy(type).get({
|
|
820
|
+
params: Object.assign({ keyword }, options),
|
|
548
821
|
});
|
|
549
822
|
}
|
|
550
823
|
/**
|
|
551
|
-
*
|
|
824
|
+
* 从 algolya 搜索
|
|
825
|
+
* https://www.algolia.com/doc/api-reference/api-methods/search/
|
|
826
|
+
* @param keyword
|
|
827
|
+
* @param options
|
|
828
|
+
* @returns
|
|
552
829
|
*/
|
|
830
|
+
searchByAlgolia(keyword, options) {
|
|
831
|
+
return this.proxy('algolia').get({ params: Object.assign({ keyword }, options) });
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
class SnippetController {
|
|
836
|
+
constructor(client) {
|
|
837
|
+
this.client = client;
|
|
838
|
+
this.base = 'snippets';
|
|
839
|
+
this.name = 'snippet';
|
|
840
|
+
}
|
|
841
|
+
get proxy() {
|
|
842
|
+
return this.client.proxy(this.base);
|
|
843
|
+
}
|
|
553
844
|
getById(id) {
|
|
554
845
|
return this.proxy(id).get();
|
|
555
846
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
847
|
+
getByReferenceAndName(reference, name) {
|
|
848
|
+
return this.proxy(reference)(name).get();
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
class UserController {
|
|
853
|
+
constructor(client) {
|
|
854
|
+
this.client = client;
|
|
855
|
+
this.base = 'master';
|
|
856
|
+
this.name = 'user';
|
|
857
|
+
}
|
|
858
|
+
get proxy() {
|
|
859
|
+
return this.client.proxy(this.base);
|
|
860
|
+
}
|
|
861
|
+
getMasterInfo() {
|
|
862
|
+
return this.proxy.get();
|
|
863
|
+
}
|
|
864
|
+
login(username, password) {
|
|
865
|
+
return this.proxy.login.post({
|
|
866
|
+
data: {
|
|
867
|
+
username,
|
|
868
|
+
password,
|
|
869
|
+
},
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
checkTokenValid(token) {
|
|
873
|
+
return this.proxy.check_logged.get({
|
|
874
|
+
params: {
|
|
875
|
+
token,
|
|
876
|
+
},
|
|
877
|
+
});
|
|
563
878
|
}
|
|
564
879
|
}
|
|
565
880
|
|
|
566
881
|
const allControllers = [
|
|
882
|
+
AggregateController,
|
|
883
|
+
CategoryController,
|
|
884
|
+
CommentController,
|
|
885
|
+
LinkController,
|
|
567
886
|
NoteController,
|
|
568
|
-
PostController,
|
|
569
887
|
PageController,
|
|
570
|
-
|
|
888
|
+
PostController,
|
|
889
|
+
ProjectController,
|
|
890
|
+
RecentlyController,
|
|
891
|
+
SayController,
|
|
892
|
+
SearchController,
|
|
893
|
+
SnippetController,
|
|
894
|
+
UserController,
|
|
895
|
+
];
|
|
896
|
+
const allContollerNames = [
|
|
897
|
+
'aggregate',
|
|
898
|
+
'category',
|
|
899
|
+
'comment',
|
|
900
|
+
'link',
|
|
901
|
+
'note',
|
|
902
|
+
'page',
|
|
903
|
+
'post',
|
|
904
|
+
'project',
|
|
905
|
+
'recently',
|
|
906
|
+
'say',
|
|
907
|
+
'search',
|
|
908
|
+
'snippet',
|
|
909
|
+
'user',
|
|
571
910
|
];
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
911
|
+
|
|
912
|
+
class HTTPControllerDefine {
|
|
913
|
+
get master() {
|
|
914
|
+
return this.user;
|
|
915
|
+
}
|
|
916
|
+
get friend() {
|
|
917
|
+
return this.link;
|
|
918
|
+
}
|
|
919
|
+
get shorthand() {
|
|
920
|
+
return this.recently;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
578
923
|
|
|
579
924
|
class RequestError extends Error {
|
|
580
925
|
constructor(message, status, path, raw) {
|
|
@@ -585,8 +930,10 @@ class RequestError extends Error {
|
|
|
585
930
|
}
|
|
586
931
|
}
|
|
587
932
|
|
|
588
|
-
class HTTPClient {
|
|
933
|
+
class HTTPClient extends HTTPControllerDefine {
|
|
934
|
+
// define all clients
|
|
589
935
|
constructor(_endpoint, _instance) {
|
|
936
|
+
super();
|
|
590
937
|
this._endpoint = _endpoint;
|
|
591
938
|
this._instance = _instance;
|
|
592
939
|
this._endpoint = _endpoint
|
|
@@ -688,13 +1035,24 @@ class HTTPClient {
|
|
|
688
1035
|
const transform = Array.isArray(data) || isPlainObject(data)
|
|
689
1036
|
? camelcaseKeys(data, { deep: true })
|
|
690
1037
|
: data;
|
|
691
|
-
Object.defineProperty(transform, 'raw', {
|
|
1038
|
+
Object.defineProperty(transform, '$raw', {
|
|
692
1039
|
get() {
|
|
693
1040
|
return res;
|
|
694
1041
|
},
|
|
695
1042
|
enumerable: false,
|
|
696
1043
|
configurable: false,
|
|
697
1044
|
});
|
|
1045
|
+
// attach request config onto response
|
|
1046
|
+
Object.defineProperty(transform, '$request', {
|
|
1047
|
+
get() {
|
|
1048
|
+
return {
|
|
1049
|
+
url,
|
|
1050
|
+
method: name,
|
|
1051
|
+
options,
|
|
1052
|
+
};
|
|
1053
|
+
},
|
|
1054
|
+
enumerable: false,
|
|
1055
|
+
});
|
|
698
1056
|
return transform;
|
|
699
1057
|
};
|
|
700
1058
|
}
|