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