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